From aff26b832d6febac1ec03892d6eb1c420af63551 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Mon, 2 Dec 2013 22:26:44 -0200 Subject: [PATCH 1/3] core: Retrofit some test for Method support on Action::Runner --- test/unit/vagrant/action/runner_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) From ae472dece9e9989baa512d40d98a524d941fc37e Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Mon, 2 Dec 2013 22:43:25 -0200 Subject: [PATCH 2/3] core: Fix hooking when using a `Method` object as a callable on action runner --- lib/vagrant/action/runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant/action/runner.rb b/lib/vagrant/action/runner.rb index ea1aad862..fea573732 100644 --- a/lib/vagrant/action/runner.rb +++ b/lib/vagrant/action/runner.rb @@ -19,7 +19,7 @@ module Vagrant def run(callable_id, options=nil) callable = callable_id - callable = Builder.build(callable_id) if callable_id.kind_of?(Class) + callable = Builder.build(callable_id) if callable_id.kind_of?(Class) || callable_id.is_a?(Method) raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call) # Create the initial environment with the options given From 1550946b0c82a5061dfa62f9b631c8afcb337ae0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 3 Dec 2013 11:43:23 -0800 Subject: [PATCH 3/3] core: build action builder if responds to call --- lib/vagrant/action/runner.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/action/runner.rb b/lib/vagrant/action/runner.rb index fea573732..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) || callable_id.is_a?(Method) - 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 = {}