Some Config::Top class tests

This commit is contained in:
Mitchell Hashimoto 2012-01-11 21:09:52 -08:00
parent 008132b3cb
commit d13dd482b5
2 changed files with 30 additions and 2 deletions

View File

@ -7,8 +7,9 @@ module Vagrant
# #
# If you're looking to create your own configuration class, see {Base}. # If you're looking to create your own configuration class, see {Base}.
class Top < Base class Top < Base
def initialize def initialize(registry=nil)
@keys = {} @keys = {}
@registry = registry || Vagrant.config_keys
end end
# We use method_missing as a way to get the configuration that is used # We use method_missing as a way to get the configuration that is used
@ -16,7 +17,7 @@ module Vagrant
def method_missing(name, *args) def method_missing(name, *args)
return @keys[name] if @keys.has_key?(name) return @keys[name] if @keys.has_key?(name)
config_klass = Vagrant.config_keys.get(name.to_sym) config_klass = @registry.get(name.to_sym)
if config_klass if config_klass
# Instantiate the class and return the instance # Instantiate the class and return the instance
@keys[name] = config_klass.new @keys[name] = config_klass.new

View File

@ -0,0 +1,27 @@
require File.expand_path("../../../base", __FILE__)
require "vagrant/registry"
describe Vagrant::Config::Top do
include_context "unit"
let(:registry) { Vagrant::Registry.new }
let(:instance) { described_class.new(registry) }
it "should load in the proper config class" do
registry.register(:foo, Object)
instance.foo.should be_kind_of(Object)
end
it "should load the proper config class only once" do
registry.register(:foo, Object)
obj = instance.foo
instance.foo.should eql(obj)
end
it "still raises a method missing error if invalid key" do
expect { instance.foo }.to raise_error(NoMethodError)
end
end