Options can now be passed into running actions

This commit is contained in:
Mitchell Hashimoto 2010-07-05 02:46:11 +02:00
parent d97c972a7f
commit d4de0d7357
2 changed files with 23 additions and 1 deletions

View File

@ -37,10 +37,11 @@ module Vagrant
# up in the registered actions list which are registered with {register}.
#
# @param [Object] callable An object which responds to `call`.
def run(callable)
def run(callable, options=nil)
callable = self.class.actions[callable] if callable.kind_of?(Symbol)
action_environment = Action::Environment.new(env)
action_environment.merge!(options || {})
callable.call(action_environment)
if action_environment.error?

View File

@ -25,6 +25,27 @@ class ActionTest < Test::Unit::TestCase
@instance.run(callable)
end
should "run the callable with the passed in options if given" do
options = {
:key => :value,
:another => %W[1 2 3]
}
callable = mock("callable")
callable.expects(:call).with() do |env|
assert env.kind_of?(Vagrant::Action::Environment)
assert_equal @instance.env, env.env
options.each do |k,v|
assert_equal v, env[k]
end
true
end
@instance.run(callable, options)
end
should "run the registered callable if a symbol is given" do
callable = mock("callable")
callable.expects(:call).once