Configuration now uses the new StackedProcRunner module
This commit is contained in:
parent
130d584322
commit
0062207ab3
|
@ -4,13 +4,14 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
|
extend StackedProcRunner
|
||||||
|
|
||||||
@@config = nil
|
@@config = nil
|
||||||
@@config_runners = []
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def reset!
|
def reset!
|
||||||
@@config = nil
|
@@config = nil
|
||||||
config_runners.clear
|
proc_stack.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def configures(key, klass)
|
def configures(key, klass)
|
||||||
|
@ -21,19 +22,12 @@ module Vagrant
|
||||||
@@config ||= Config::Top.new
|
@@config ||= Config::Top.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def config_runners
|
|
||||||
@@config_runners ||= []
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(&block)
|
def run(&block)
|
||||||
config_runners << block
|
push_proc(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
config_runners.each do |block|
|
run_procs!(config)
|
||||||
block.call(config)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.loaded!
|
config.loaded!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,10 +35,10 @@ class ConfigTest < Test::Unit::TestCase
|
||||||
assert !config.equal?(Vagrant::Config.config)
|
assert !config.equal?(Vagrant::Config.config)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "empty the runners" do
|
should "empty the proc stack" do
|
||||||
assert !Vagrant::Config.config_runners.empty?
|
assert !Vagrant::Config.proc_stack.empty?
|
||||||
Vagrant::Config.reset!
|
Vagrant::Config.reset!
|
||||||
assert Vagrant::Config.config_runners.empty?
|
assert Vagrant::Config.proc_stack.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,29 +54,18 @@ class ConfigTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
context "initializing" do
|
context "initializing" do
|
||||||
teardown do
|
setup do
|
||||||
Vagrant::Config.reset!
|
Vagrant::Config.reset!
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not run the blocks right away" do
|
should "add the given block to the proc stack" do
|
||||||
obj = mock("obj")
|
proc = Proc.new {}
|
||||||
obj.expects(:foo).never
|
Vagrant::Config.run(&proc)
|
||||||
Vagrant::Config.run { |config| obj.foo }
|
assert_equal [proc], Vagrant::Config.proc_stack
|
||||||
Vagrant::Config.run { |config| obj.foo }
|
|
||||||
Vagrant::Config.run { |config| obj.foo }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "run the blocks when execute! is ran" do
|
should "run the proc stack with the config when execute is called" do
|
||||||
obj = mock("obj")
|
Vagrant::Config.expects(:run_procs!).with(Vagrant::Config.config).once
|
||||||
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 }
|
|
||||||
Vagrant::Config.execute!
|
Vagrant::Config.execute!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue