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
|
class Base
|
||||||
attr_reader :vm
|
attr_reader :vm
|
||||||
|
|
||||||
|
# Included so subclasses don't need to include it themselves.
|
||||||
include Vagrant::Util
|
include Vagrant::Util
|
||||||
|
|
||||||
# Initialization of the actions are done all at once. The guarantee
|
# Initialization of the actions are done all at once. The guarantee
|
||||||
|
|
|
@ -45,9 +45,12 @@ module Vagrant
|
||||||
def invoke_callback(name, *args)
|
def invoke_callback(name, *args)
|
||||||
# Attempt to call the method for the callback on each of the
|
# Attempt to call the method for the callback on each of the
|
||||||
# actions
|
# actions
|
||||||
|
results = []
|
||||||
@actions.each do |action|
|
@actions.each do |action|
|
||||||
action.send(name, *args) if action.respond_to?(name)
|
results << action.send(name, *args) if action.respond_to?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -34,6 +34,19 @@ class VMTest < Test::Unit::TestCase
|
||||||
@vm.actions << action
|
@vm.actions << action
|
||||||
@vm.invoke_callback(:foo)
|
@vm.invoke_callback(:foo)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "actions" do
|
context "actions" do
|
||||||
|
|
Loading…
Reference in New Issue