Unknown keys return a DummyConfig rather than OpenStruct

This commit is contained in:
Mitchell Hashimoto 2013-02-28 00:16:30 -08:00
parent 2081fe5650
commit af2690635e
4 changed files with 39 additions and 2 deletions

View File

@ -1,6 +1,7 @@
module Vagrant
module Config
module V1
autoload :DummyConfig, "vagrant/config/v1/dummy_config"
autoload :Loader, "vagrant/config/v1/loader"
autoload :Root, "vagrant/config/v1/root"
end

View File

@ -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

View File

@ -1,4 +1,3 @@
require "ostruct"
require "set"
module Vagrant
@ -31,7 +30,7 @@ module Vagrant
else
# Record access to a missing key as an error
@missing_key_calls.add(name.to_s)
return OpenStruct.new
return DummyConfig.new
end
end

View File

@ -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