Skip to content

Commit

Permalink
Remove some excessive mocking in configuration_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jan 24, 2019
1 parent afddd94 commit b96e95b
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions spec/models/vm_or_template/operations/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@

context "when ext_management_system exists" do
let(:vm) { FactoryBot.create(:vm_or_template, :ext_management_system => ems) }
let(:ems) { FactoryBot.create(:ext_management_system) }
let(:ems) { FactoryBot.create(:ext_management_system, :with_authentication) }
let(:storage_name) { "test_storage" }
let(:storage) { FactoryBot.create(:storage, :name => storage_name) }
let(:storages) { double("storages") }
let(:host) { double("host", :writable_storages => storages) }
let(:hosts) { [host] }

before do
allow(ems).to receive(:hosts).and_return(hosts)
end
let!(:host) { FactoryBot.create(:host, :ext_management_system => ems).tap { |h| h.host_storages.create!(:storage => storage) } }

context "when storage exists" do
it "adds a disk on the storage" do
allow(storages).to receive(:find_by).with(:name => storage_name).and_return(storage)
allow(ems).to receive(:authentication_status_ok?).and_return(true)
allow(ems).to receive(:vm_add_disk)

expected_options = {
Expand All @@ -48,10 +40,8 @@

context "when storage does not exist" do
it "raises an exception when doesn't find storage by its name" do
allow(storages).to receive(:find_by).with(:name => storage_name).and_return(nil)

message = "Datastore does not exist or cannot be accessed, unable to add disk"
expect { vm.raw_add_disk(disk_name, disk_size, :datastore => storage_name) }.to raise_error(message)
expect { vm.raw_add_disk(disk_name, disk_size, :datastore => "notmystorage") }.to raise_error(message)
end
end
end
Expand Down

0 comments on commit b96e95b

Please sign in to comment.