Action.run can be called with a class

This commit is contained in:
Mitchell Hashimoto 2010-07-07 21:03:28 -07:00
parent 086ca5a97e
commit e9bcd3fc16
2 changed files with 14 additions and 0 deletions

View File

@ -43,6 +43,7 @@ module Vagrant
# #
# @param [Object] callable An object which responds to `call`. # @param [Object] callable An object which responds to `call`.
def run(callable, options=nil) def run(callable, options=nil)
callable = Builder.new.use(callable) if callable.kind_of?(Class)
callable = self.class.actions[callable] if callable.kind_of?(Symbol) callable = self.class.actions[callable] if callable.kind_of?(Symbol)
action_environment = Action::Environment.new(env) action_environment = Action::Environment.new(env)

View File

@ -71,6 +71,19 @@ class ActionTest < Test::Unit::TestCase
@instance.run(:call) @instance.run(:call)
end end
should "run the given class if a class is given" do
callable = Class.new do
def initialize(app, env); end
end
callable.any_instance.expects(:call).with() do |env|
assert_equal :foo, env[:bar]
true
end
@instance.run(callable, :bar => :foo)
end
should "error and exit if erroneous environment results" do should "error and exit if erroneous environment results" do
callable = lambda do |env| callable = lambda do |env|
env.error!(:key, :foo => :bar) env.error!(:key, :foo => :bar)