diff --git a/lib/vagrant/actions/base.rb b/lib/vagrant/actions/base.rb index dc317bed7..411c13505 100644 --- a/lib/vagrant/actions/base.rb +++ b/lib/vagrant/actions/base.rb @@ -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 diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 8d0f04f57..23873f7fc 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -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! diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 0e696ac5c..7f6d78e7b 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -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