diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 46ee28c40..c21d287fe 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -4,13 +4,14 @@ module Vagrant end class Config + extend StackedProcRunner + @@config = nil - @@config_runners = [] class << self def reset! @@config = nil - config_runners.clear + proc_stack.clear end def configures(key, klass) @@ -21,19 +22,12 @@ module Vagrant @@config ||= Config::Top.new end - def config_runners - @@config_runners ||= [] - end - def run(&block) - config_runners << block + push_proc(&block) end def execute! - config_runners.each do |block| - block.call(config) - end - + run_procs!(config) config.loaded! end end diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index a301b0875..ce36a3711 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -35,10 +35,10 @@ class ConfigTest < Test::Unit::TestCase assert !config.equal?(Vagrant::Config.config) end - should "empty the runners" do - assert !Vagrant::Config.config_runners.empty? + should "empty the proc stack" do + assert !Vagrant::Config.proc_stack.empty? Vagrant::Config.reset! - assert Vagrant::Config.config_runners.empty? + assert Vagrant::Config.proc_stack.empty? end end @@ -54,29 +54,18 @@ class ConfigTest < Test::Unit::TestCase end context "initializing" do - teardown do + setup do Vagrant::Config.reset! end - should "not run the blocks right away" do - obj = mock("obj") - obj.expects(:foo).never - Vagrant::Config.run { |config| obj.foo } - Vagrant::Config.run { |config| obj.foo } - Vagrant::Config.run { |config| obj.foo } + should "add the given block to the proc stack" do + proc = Proc.new {} + Vagrant::Config.run(&proc) + assert_equal [proc], Vagrant::Config.proc_stack end - should "run the blocks when execute! is ran" do - obj = mock("obj") - obj.expects(:foo).times(2) - Vagrant::Config.run { |config| obj.foo } - Vagrant::Config.run { |config| obj.foo } - Vagrant::Config.execute! - end - - should "run the blocks with the same config object" do - Vagrant::Config.run { |config| assert config } - Vagrant::Config.run { |config| assert config } + should "run the proc stack with the config when execute is called" do + Vagrant::Config.expects(:run_procs!).with(Vagrant::Config.config).once Vagrant::Config.execute! end