diff --git a/lib/vagrant/action/runner.rb b/lib/vagrant/action/runner.rb index ea1aad862..a654e37e3 100644 --- a/lib/vagrant/action/runner.rb +++ b/lib/vagrant/action/runner.rb @@ -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 = {} diff --git a/test/unit/vagrant/action/runner_test.rb b/test/unit/vagrant/action/runner_test.rb index 2f5ab95dd..87c83aabe 100644 --- a/test/unit/vagrant/action/runner_test.rb +++ b/test/unit/vagrant/action/runner_test.rb @@ -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)