diff --git a/lib/vagrant/actions/base.rb b/lib/vagrant/actions/base.rb index b91154496..dc317bed7 100644 --- a/lib/vagrant/actions/base.rb +++ b/lib/vagrant/actions/base.rb @@ -7,6 +7,7 @@ module Vagrant class Base attr_reader :vm + # Included so subclasses don't need to include it themselves. include Vagrant::Util # Initialization of the actions are done all at once. The guarantee diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 53993977d..9bbb93cdc 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -45,9 +45,12 @@ module Vagrant def invoke_callback(name, *args) # Attempt to call the method for the callback on each of the # actions + results = [] @actions.each do |action| - action.send(name, *args) if action.respond_to?(name) + results << action.send(name, *args) if action.respond_to?(name) end + + results end def create diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 9a3a07761..65108934d 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -34,6 +34,19 @@ class VMTest < Test::Unit::TestCase @vm.actions << action @vm.invoke_callback(:foo) end + + should "collect all the results and return them as an array" do + result = [] + 3.times do |i| + action = mock("action#{i}") + action.expects(:foo).returns("foo#{i}").once + + @vm.actions << action + result << "foo#{i}" + end + + assert_equal result, @vm.invoke_callback(:foo) + end end context "actions" do