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
|
# would be instance_evaling the vm instance to include a module so
|
||||||
# additionally functionality could be defined on the vm which other
|
# additionally functionality could be defined on the vm which other
|
||||||
# action `prepare` methods may rely on.
|
# action `prepare` methods may rely on.
|
||||||
def initialize(vm)
|
def initialize(vm, *args)
|
||||||
@vm = vm
|
@vm = vm
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ module Vagrant
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# Executes a specific action
|
# Executes a specific action
|
||||||
def execute!(action_klass)
|
def execute!(action_klass, *args)
|
||||||
vm = new
|
vm = new
|
||||||
vm.add_action(action_klass)
|
vm.add_action(action_klass, *args)
|
||||||
vm.execute!
|
vm.execute!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ error
|
||||||
@actions = []
|
@actions = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_action(action_klass)
|
def add_action(action_klass, *args)
|
||||||
@actions << action_klass.new(self)
|
@actions << action_klass.new(self, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
|
|
|
@ -66,6 +66,12 @@ class VMTest < Test::Unit::TestCase
|
||||||
assert_equal 1, @vm.actions.length
|
assert_equal 1, @vm.actions.length
|
||||||
end
|
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
|
should "run #prepare on all actions, then #execute!" do
|
||||||
action_seq = sequence("action_seq")
|
action_seq = sequence("action_seq")
|
||||||
actions = []
|
actions = []
|
||||||
|
@ -94,6 +100,16 @@ class VMTest < Test::Unit::TestCase
|
||||||
|
|
||||||
Vagrant::VM.execute!("foo")
|
Vagrant::VM.execute!("foo")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "finding a VM" do
|
context "finding a VM" do
|
||||||
|
|
Loading…
Reference in New Issue