core: config raises NoMethodError on bad calls once finalized
This commit is contained in:
parent
3348baab56
commit
f72db0c611
|
@ -48,6 +48,7 @@ module Vagrant
|
|||
|
||||
@keys.each do |_key, instance|
|
||||
instance.finalize!
|
||||
instance._finalize!
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -70,6 +70,8 @@ module Vagrant
|
|||
# Capture all bad configuration calls and save them for an error
|
||||
# message later during validation.
|
||||
def method_missing(name, *args, &block)
|
||||
return super if @__finalized
|
||||
|
||||
name = name.to_s
|
||||
name = name[0...-1] if name.end_with?("=")
|
||||
|
||||
|
@ -130,6 +132,11 @@ module Vagrant
|
|||
return [I18n.t("vagrant.config.common.bad_field",
|
||||
:fields => @__invalid_methods.to_a.sort.join(", "))]
|
||||
end
|
||||
|
||||
# An internal finalize call that no subclass should override.
|
||||
def _finalize!
|
||||
@__finalized = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,8 +41,8 @@ describe Vagrant::Config::V2::Root do
|
|||
}
|
||||
end
|
||||
|
||||
describe "finalization" do
|
||||
it "should finalize un-used keys" do
|
||||
describe "#finalize!" do
|
||||
it "should call #finalize!" do
|
||||
foo_class = Class.new do
|
||||
attr_accessor :foo
|
||||
|
||||
|
@ -57,6 +57,17 @@ describe Vagrant::Config::V2::Root do
|
|||
|
||||
instance.foo.foo.should == "SET"
|
||||
end
|
||||
|
||||
it "should call #_finalize!" do
|
||||
klass = Class.new
|
||||
|
||||
klass.any_instance.should_receive(:finalize!)
|
||||
klass.any_instance.should_receive(:_finalize!)
|
||||
|
||||
map = { foo: klass }
|
||||
instance = described_class.new(map)
|
||||
instance.finalize!
|
||||
end
|
||||
end
|
||||
|
||||
describe "validation" do
|
||||
|
|
|
@ -12,7 +12,9 @@ describe Vagrant::Plugin::V2::Config do
|
|||
|
||||
let(:unset_value) { described_class.const_get("UNSET_VALUE") }
|
||||
|
||||
describe "merging" do
|
||||
subject { foo_class.new }
|
||||
|
||||
describe "#merge" do
|
||||
it "should merge by default by simply copying each instance variable" do
|
||||
one = foo_class.new
|
||||
one.one = 2
|
||||
|
@ -57,4 +59,18 @@ describe Vagrant::Plugin::V2::Config do
|
|||
result.instance_variable_get(:@__bar).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "#method_missing" do
|
||||
it "returns a DummyConfig object" do
|
||||
expect(subject.i_should_not_exist).
|
||||
to be_kind_of(Vagrant::Config::V2::DummyConfig)
|
||||
end
|
||||
|
||||
it "raises an error if finalized (internally)" do
|
||||
subject._finalize!
|
||||
|
||||
expect { subject.i_should_not_exist }.
|
||||
to raise_error(NoMethodError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue