diff --git a/lib/vagrant/actions/forward_ports.rb b/lib/vagrant/actions/forward_ports.rb index 29b59f45b..767dac06d 100644 --- a/lib/vagrant/actions/forward_ports.rb +++ b/lib/vagrant/actions/forward_ports.rb @@ -10,10 +10,10 @@ module Vagrant port.name = name port.hostport = options[:hostport] port.guestport = options[:guestport] - @vm.forwarded_ports << port + @vm.vm.forwarded_ports << port end - @vm.save(true) + @vm.vm.save(true) end end end diff --git a/lib/vagrant/commands.rb b/lib/vagrant/commands.rb index c89a0c851..c264cec68 100644 --- a/lib/vagrant/commands.rb +++ b/lib/vagrant/commands.rb @@ -99,7 +99,7 @@ error end # Export and package the current vm - # + # # This command requires that an instance be powered off def package(name=nil) Env.load! diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 9bbb93cdc..6b08893de 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -5,6 +5,13 @@ module Vagrant attr_reader :actions class << self + # Executes a specific action + def execute!(action_klass) + vm = new + vm.actions << action_klass + vm.execute! + end + # Bring up the virtual machine. Imports the base image and # provisions it. def up diff --git a/test/vagrant/actions/forward_ports_test.rb b/test/vagrant/actions/forward_ports_test.rb index 7cbc55d1c..8239fa6ce 100644 --- a/test/vagrant/actions/forward_ports_test.rb +++ b/test/vagrant/actions/forward_ports_test.rb @@ -18,8 +18,8 @@ class ForwardPortsActionTest < Test::Unit::TestCase end end - @mock_vm.expects(:forwarded_ports).returns(forwarded_ports) - @mock_vm.expects(:save).with(true).once + @vm.expects(:forwarded_ports).returns(forwarded_ports) + @vm.expects(:save).with(true).once @action.execute! end end diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 65108934d..f372cac81 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -87,6 +87,18 @@ class VMTest < Test::Unit::TestCase @vm.execute! end + + should "run actions on class method execute!" do + vm = mock("vm") + actions = mock("actions") + execute_seq = sequence("execute_seq") + Vagrant::VM.expects(:new).returns(vm).in_sequence(execute_seq) + vm.expects(:actions).returns(actions).in_sequence(execute_seq) + actions.expects(:<<).with("foo").once.in_sequence(execute_seq) + vm.expects(:execute!).once.in_sequence(execute_seq) + + Vagrant::VM.execute!("foo") + end end context "vagrant up" do