Configuration now uses the new StackedProcRunner module
This commit is contained in:
parent
130d584322
commit
0062207ab3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue