Merge pull request #2569 from mitchellh/fix-hook-with-methods

core: fix hook with methods
This commit is contained in:
Mitchell Hashimoto 2013-12-03 11:44:16 -08:00
commit 900a8a4ec1
2 changed files with 20 additions and 2 deletions

View File

@ -19,8 +19,16 @@ module Vagrant
def run(callable_id, options=nil) def run(callable_id, options=nil)
callable = callable_id callable = callable_id
callable = Builder.build(callable_id) if callable_id.kind_of?(Class) if !callable.kind_of?(Builder)
raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call) if callable_id.kind_of?(Class) || callable_id.respond_to?(:call)
callable = Builder.build(callable_id)
end
end
if !callable || !callable.respond_to?(:call)
raise ArgumentError,
"Argument to run must be a callable object or registered action."
end
# Create the initial environment with the options given # Create the initial environment with the options given
environment = {} environment = {}

View File

@ -12,6 +12,16 @@ describe Vagrant::Action::Runner do
expect { instance.run(callable) }.to raise_error(Exception, "BOOM") expect { instance.run(callable) }.to raise_error(Exception, "BOOM")
end end
it "should be able to use a Method instance as a callable" do
klass = Class.new do
def action(env)
raise Exception, "BANG"
end
end
callable = klass.new.method(:action)
expect { instance.run(callable) }.to raise_error(Exception, "BANG")
end
it "should be able to use a Class as a callable" do it "should be able to use a Class as a callable" do
callable = Class.new do callable = Class.new do
def initialize(app, env) def initialize(app, env)