Additional options can be passed into actions as additional arguments to the constructor
This commit is contained in:
parent
f3cd0591d0
commit
874eb70911
|
@ -17,7 +17,7 @@ module Vagrant
|
|||
# would be instance_evaling the vm instance to include a module so
|
||||
# additionally functionality could be defined on the vm which other
|
||||
# action `prepare` methods may rely on.
|
||||
def initialize(vm)
|
||||
def initialize(vm, *args)
|
||||
@vm = vm
|
||||
end
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ module Vagrant
|
|||
|
||||
class << self
|
||||
# Executes a specific action
|
||||
def execute!(action_klass)
|
||||
def execute!(action_klass, *args)
|
||||
vm = new
|
||||
vm.add_action(action_klass)
|
||||
vm.add_action(action_klass, *args)
|
||||
vm.execute!
|
||||
end
|
||||
|
||||
|
@ -84,8 +84,8 @@ error
|
|||
@actions = []
|
||||
end
|
||||
|
||||
def add_action(action_klass)
|
||||
@actions << action_klass.new(self)
|
||||
def add_action(action_klass, *args)
|
||||
@actions << action_klass.new(self, *args)
|
||||
end
|
||||
|
||||
def execute!
|
||||
|
|
|
@ -66,6 +66,12 @@ class VMTest < Test::Unit::TestCase
|
|||
assert_equal 1, @vm.actions.length
|
||||
end
|
||||
|
||||
should "initialize the action with given arguments when added" do
|
||||
action_klass = mock("action_class")
|
||||
action_klass.expects(:new).with(@vm, "foo", "bar").once
|
||||
@vm.add_action(action_klass, "foo", "bar")
|
||||
end
|
||||
|
||||
should "run #prepare on all actions, then #execute!" do
|
||||
action_seq = sequence("action_seq")
|
||||
actions = []
|
||||
|
@ -94,6 +100,16 @@ class VMTest < Test::Unit::TestCase
|
|||
|
||||
Vagrant::VM.execute!("foo")
|
||||
end
|
||||
|
||||
should "forward arguments to add_action on class method execute!" do
|
||||
vm = mock("vm")
|
||||
execute_seq = sequence("execute_seq")
|
||||
Vagrant::VM.expects(:new).returns(vm).in_sequence(execute_seq)
|
||||
vm.expects(:add_action).with("foo", "bar", "baz").in_sequence(execute_seq)
|
||||
vm.expects(:execute!).once.in_sequence(execute_seq)
|
||||
|
||||
Vagrant::VM.execute!("foo", "bar", "baz")
|
||||
end
|
||||
end
|
||||
|
||||
context "finding a VM" do
|
||||
|
|
Loading…
Reference in New Issue