Fix a couple of tests
Use subject instead of invalid_subject because the validation assertions test the subject double. This also adds an additional check when validating the `size` attribute because it is only required for disks of type `:disk`.
This commit is contained in:
parent
1d46cd3882
commit
de461fa47c
@ -172,7 +172,7 @@ module VagrantPlugins
|
||||
end
|
||||
end
|
||||
|
||||
if !@size
|
||||
if !@size && type == :disk
|
||||
errors << I18n.t("vagrant.config.disk.invalid_size", name: @name, machine: machine.name)
|
||||
end
|
||||
|
||||
|
||||
@ -32,8 +32,6 @@ describe VagrantPlugins::Kernel_V2::VagrantConfigDisk do
|
||||
before do
|
||||
env = double("env")
|
||||
|
||||
subject.name = "foo"
|
||||
subject.size = 100
|
||||
allow(provider).to receive(:capability?).with(:validate_disk_ext).and_return(true)
|
||||
allow(provider).to receive(:capability).with(:validate_disk_ext, "vdi").and_return(true)
|
||||
allow(provider).to receive(:capability?).with(:set_default_disk_ext).and_return(true)
|
||||
@ -41,6 +39,11 @@ describe VagrantPlugins::Kernel_V2::VagrantConfigDisk do
|
||||
end
|
||||
|
||||
describe "with defaults" do
|
||||
before do
|
||||
subject.name = "foo"
|
||||
subject.size = 100
|
||||
end
|
||||
|
||||
it "is valid with test defaults" do
|
||||
subject.finalize!
|
||||
assert_valid
|
||||
@ -58,18 +61,24 @@ describe VagrantPlugins::Kernel_V2::VagrantConfigDisk do
|
||||
end
|
||||
|
||||
describe "with an invalid config" do
|
||||
let(:invalid_subject) { described_class.new(type) }
|
||||
before do
|
||||
subject.name = "bar"
|
||||
end
|
||||
|
||||
it "raises an error if size not set" do
|
||||
invalid_subject.name = "bar"
|
||||
subject.finalize!
|
||||
assert_invalid
|
||||
end
|
||||
|
||||
context "with an invalid disk extension" do
|
||||
before do
|
||||
subject.size = 100
|
||||
subject.disk_ext = "fake"
|
||||
|
||||
allow(provider).to receive(:capability?).with(:validate_disk_ext).and_return(true)
|
||||
allow(provider).to receive(:capability).with(:validate_disk_ext, "fake").and_return(false)
|
||||
allow(provider).to receive(:capability?).with(:default_disk_exts).and_return(true)
|
||||
allow(provider).to receive(:capability).with(:default_disk_exts).and_return(["vdi", "vmdk"])
|
||||
end
|
||||
|
||||
it "raises an error" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user