From af2690635e50db471d098ea10eb29f9d1c7a1de5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 28 Feb 2013 00:16:30 -0800 Subject: [PATCH] Unknown keys return a DummyConfig rather than OpenStruct --- lib/vagrant/config/v1.rb | 1 + lib/vagrant/config/v1/dummy_config.rb | 13 ++++++++++ lib/vagrant/config/v1/root.rb | 3 +-- .../vagrant/config/v1/dummy_config_test.rb | 24 +++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lib/vagrant/config/v1/dummy_config.rb create mode 100644 test/unit/vagrant/config/v1/dummy_config_test.rb diff --git a/lib/vagrant/config/v1.rb b/lib/vagrant/config/v1.rb index bf8936a9d..706e41ec8 100644 --- a/lib/vagrant/config/v1.rb +++ b/lib/vagrant/config/v1.rb @@ -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 diff --git a/lib/vagrant/config/v1/dummy_config.rb b/lib/vagrant/config/v1/dummy_config.rb new file mode 100644 index 000000000..dc678a33d --- /dev/null +++ b/lib/vagrant/config/v1/dummy_config.rb @@ -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 diff --git a/lib/vagrant/config/v1/root.rb b/lib/vagrant/config/v1/root.rb index ba3288095..1f7db9763 100644 --- a/lib/vagrant/config/v1/root.rb +++ b/lib/vagrant/config/v1/root.rb @@ -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 diff --git a/test/unit/vagrant/config/v1/dummy_config_test.rb b/test/unit/vagrant/config/v1/dummy_config_test.rb new file mode 100644 index 000000000..22a99a97b --- /dev/null +++ b/test/unit/vagrant/config/v1/dummy_config_test.rb @@ -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