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 def assert_invalid
errors = subject.validate(machine) 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 end
def assert_valid def assert_valid
@ -21,31 +21,31 @@ describe VagrantPlugins::ProviderLibvirt::Config do
assert_valid assert_valid
end end
it 'is valid if relative path used for disk' do context 'with disks defined' do
subject.storage :file, path: '../path/to/file.qcow2' before { expect(machine).to receive(:provider_config).and_return(subject).at_least(:once) }
assert_valid
end
it 'should be invalid if absolute path used for disk' do it 'is valid if relative path used for disk' do
subject.storage :file, path: '/absolute/path/to/file.qcow2' subject.storage :file, path: '../path/to/file.qcow2'
assert_invalid assert_valid
end
it 'should be invalid if absolute path used for disk' do
subject.storage :file, path: '/absolute/path/to/file.qcow2'
assert_invalid
end
end end
context 'with mac defined' do context 'with mac defined' do
let (:vm) { double('vm') } let (:vm) { double('vm') }
let (:networks) { double('networks') } before { expect(machine.config).to receive(:vm).and_return(vm) }
before do
allow(vm).to receive(:networks).and_return(networks)
allow(machine.config).to receive(:vm).and_return(vm)
end
it 'is valid with valid mac' do 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 assert_valid
end end
it 'should be invalid if MAC not formatted correctly' do 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 assert_invalid
end end
end end