Fix assert_invalid in configuration spec

assert_invalid was previously only raising an error if there was a
validation error logged, rather than if there wasn't an error. Tests
that expected validation failures were passing without any validation
errors being logged.
This commit is contained in:
Dominic Cleal 2017-05-16 14:14:30 +01:00
parent 772c38a2b3
commit 7b968c7a72
No known key found for this signature in database
GPG Key ID: 7C7D326F2C2B72CC

View File

@ -8,7 +8,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
def assert_invalid
errors = subject.validate(machine)
raise "No errors: #{errors.inspect}" if errors.values.any? { |v| !v.empty? }
raise "No errors: #{errors.inspect}" if errors.values.all?(&:empty?)
end
def assert_valid
@ -21,6 +21,9 @@ describe VagrantPlugins::ProviderLibvirt::Config do
assert_valid
end
context 'with disks defined' do
before { expect(machine).to receive(:provider_config).and_return(subject).at_least(:once) }
it 'is valid if relative path used for disk' do
subject.storage :file, path: '../path/to/file.qcow2'
assert_valid
@ -30,22 +33,19 @@ describe VagrantPlugins::ProviderLibvirt::Config do
subject.storage :file, path: '/absolute/path/to/file.qcow2'
assert_invalid
end
end
context 'with mac defined' do
let (:vm) { double('vm') }
let (:networks) { double('networks') }
before do
allow(vm).to receive(:networks).and_return(networks)
allow(machine.config).to receive(:vm).and_return(vm)
end
before { expect(machine.config).to receive(:vm).and_return(vm) }
it 'is valid with valid mac' do
allow(networks).to receive(:each).and_return([:public, { mac: 'aa:bb:cc:dd:ee:ff' }])
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aa:bb:cc:dd:ee:ff' }]])
assert_valid
end
it 'should be invalid if MAC not formatted correctly' do
allow(networks).to receive(:each).and_return([:public, { mac: 'aabbccddeeff' }])
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aabbccddeeff' }]])
assert_invalid
end
end