VM#invoke_callback now returns an array of the results of the actions which implemented the callback.
This commit is contained in:
parent
af1fcd0ae0
commit
4ea450ba2a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue