V2 missing key returns a DummyConfig as well
This commit is contained in:
parent
af2690635e
commit
7547a0d34a
|
@ -1,6 +1,7 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Config
|
module Config
|
||||||
module V2
|
module V2
|
||||||
|
autoload :DummyConfig, "vagrant/config/v2/dummy_config"
|
||||||
autoload :Loader, "vagrant/config/v2/loader"
|
autoload :Loader, "vagrant/config/v2/loader"
|
||||||
autoload :Root, "vagrant/config/v2/root"
|
autoload :Root, "vagrant/config/v2/root"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
module Vagrant
|
||||||
|
module Config
|
||||||
|
module V2
|
||||||
|
# This is a configuration object that can have anything done
|
||||||
|
# to it. Anything, and it just appears to keep working.
|
||||||
|
class DummyConfig
|
||||||
|
def method_missing(name, *args, &block)
|
||||||
|
DummyConfig.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,3 @@
|
||||||
require "ostruct"
|
|
||||||
require "set"
|
require "set"
|
||||||
|
|
||||||
require "vagrant/config/v2/util"
|
require "vagrant/config/v2/util"
|
||||||
|
@ -33,7 +32,7 @@ module Vagrant
|
||||||
else
|
else
|
||||||
# Record access to a missing key as an error
|
# Record access to a missing key as an error
|
||||||
@missing_key_calls.add(name.to_s)
|
@missing_key_calls.add(name.to_s)
|
||||||
return OpenStruct.new
|
return DummyConfig.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
require File.expand_path("../../../../base", __FILE__)
|
||||||
|
|
||||||
|
describe Vagrant::Config::V2::DummyConfig do
|
||||||
|
it "should allow attribute setting" do
|
||||||
|
expect { subject.foo = :bar }.
|
||||||
|
to_not raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should allow method calls that return more DummyConfigs" do
|
||||||
|
subject.foo.should be_kind_of(described_class)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should allow hash access" do
|
||||||
|
expect { subject[:foo] }.
|
||||||
|
to_not raise_error
|
||||||
|
|
||||||
|
subject[:foo].should be_kind_of(described_class)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should allow setting hash values" do
|
||||||
|
expect { subject[:foo] = :bar }.
|
||||||
|
to_not raise_error
|
||||||
|
end
|
||||||
|
end
|
|
@ -21,7 +21,7 @@ describe Vagrant::Config::V2::Root do
|
||||||
instance.__internal_state["missing_key_calls"].include?("foo").should be
|
instance.__internal_state["missing_key_calls"].include?("foo").should be
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an OpenStruct for a missing key" do
|
it "returns a dummy config for a missing key" do
|
||||||
instance = described_class.new({})
|
instance = described_class.new({})
|
||||||
expect { instance.foo.foo = "bar" }.to_not raise_error
|
expect { instance.foo.foo = "bar" }.to_not raise_error
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue