diff --git a/lib/vagrant/config/v2.rb b/lib/vagrant/config/v2.rb index bb6c88b0c..1db256e0d 100644 --- a/lib/vagrant/config/v2.rb +++ b/lib/vagrant/config/v2.rb @@ -1,6 +1,7 @@ module Vagrant module Config module V2 + autoload :DummyConfig, "vagrant/config/v2/dummy_config" autoload :Loader, "vagrant/config/v2/loader" autoload :Root, "vagrant/config/v2/root" end diff --git a/lib/vagrant/config/v2/dummy_config.rb b/lib/vagrant/config/v2/dummy_config.rb new file mode 100644 index 000000000..149b66b7a --- /dev/null +++ b/lib/vagrant/config/v2/dummy_config.rb @@ -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 diff --git a/lib/vagrant/config/v2/root.rb b/lib/vagrant/config/v2/root.rb index 5204ea462..89009af9e 100644 --- a/lib/vagrant/config/v2/root.rb +++ b/lib/vagrant/config/v2/root.rb @@ -1,4 +1,3 @@ -require "ostruct" require "set" require "vagrant/config/v2/util" @@ -33,7 +32,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 diff --git a/test/unit/vagrant/config/v2/dummy_config_test.rb b/test/unit/vagrant/config/v2/dummy_config_test.rb new file mode 100644 index 000000000..6d55f0ab0 --- /dev/null +++ b/test/unit/vagrant/config/v2/dummy_config_test.rb @@ -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 diff --git a/test/unit/vagrant/config/v2/root_test.rb b/test/unit/vagrant/config/v2/root_test.rb index c5c72874e..d80806522 100644 --- a/test/unit/vagrant/config/v2/root_test.rb +++ b/test/unit/vagrant/config/v2/root_test.rb @@ -21,7 +21,7 @@ describe Vagrant::Config::V2::Root do instance.__internal_state["missing_key_calls"].include?("foo").should be end - it "returns an OpenStruct for a missing key" do + it "returns a dummy config for a missing key" do instance = described_class.new({}) expect { instance.foo.foo = "bar" }.to_not raise_error end