Unknown keys return a DummyConfig rather than OpenStruct
This commit is contained in:
parent
2081fe5650
commit
af2690635e
|
@ -1,6 +1,7 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Config
|
module Config
|
||||||
module V1
|
module V1
|
||||||
|
autoload :DummyConfig, "vagrant/config/v1/dummy_config"
|
||||||
autoload :Loader, "vagrant/config/v1/loader"
|
autoload :Loader, "vagrant/config/v1/loader"
|
||||||
autoload :Root, "vagrant/config/v1/root"
|
autoload :Root, "vagrant/config/v1/root"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
module Vagrant
|
||||||
|
module Config
|
||||||
|
module V1
|
||||||
|
# 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"
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
|
@ -31,7 +30,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::V1::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
|
Loading…
Reference in New Issue