Merge pull request #2569 from mitchellh/fix-hook-with-methods
core: fix hook with methods
This commit is contained in:
commit
900a8a4ec1
|
@ -19,8 +19,16 @@ module Vagrant
|
|||
|
||||
def run(callable_id, options=nil)
|
||||
callable = callable_id
|
||||
callable = Builder.build(callable_id) if callable_id.kind_of?(Class)
|
||||
raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call)
|
||||
if !callable.kind_of?(Builder)
|
||||
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
|
||||
environment = {}
|
||||
|
|
|
@ -12,6 +12,16 @@ describe Vagrant::Action::Runner do
|
|||
expect { instance.run(callable) }.to raise_error(Exception, "BOOM")
|
||||
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
|
||||
callable = Class.new do
|
||||
def initialize(app, env)
|
||||
|
|
Loading…
Reference in New Issue