From e11d3bd4f777d4a8edacfe3dac26e48957a6c8db Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 12 Sep 2010 16:29:35 -0600 Subject: [PATCH] Only halt if created and running --- lib/vagrant/action/vm/halt.rb | 2 +- test/vagrant/action/vm/halt_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/vm/halt.rb b/lib/vagrant/action/vm/halt.rb index 823722e87..ef578fa13 100644 --- a/lib/vagrant/action/vm/halt.rb +++ b/lib/vagrant/action/vm/halt.rb @@ -8,7 +8,7 @@ module Vagrant end def call(env) - if env["vm"].vm.running? + if env["vm"].created? && env["vm"].vm.running? env["vm"].system.halt if !env["force"] if env["vm"].vm.state(true) != :powered_off diff --git a/test/vagrant/action/vm/halt_test.rb b/test/vagrant/action/vm/halt_test.rb index 47087f2e4..4ddfba8a3 100644 --- a/test/vagrant/action/vm/halt_test.rb +++ b/test/vagrant/action/vm/halt_test.rb @@ -26,6 +26,7 @@ class HaltVMActionTest < Test::Unit::TestCase context "calling" do setup do + @vm.stubs(:created?).returns(true) @internal_vm.stubs(:running?).returns(true) @vm.system.stubs(:halt) @@ -33,6 +34,15 @@ class HaltVMActionTest < Test::Unit::TestCase @internal_vm.stubs(:state).returns(:powered_off) end + should "do nothing if VM is not created" do + @internal_vm.stubs(:created?).returns(false) + @vm.system.expects(:halt).never + @internal_vm.expects(:stop).never + @app.expects(:call).once + + @instance.call(@env) + end + should "do nothing if VM not running" do @internal_vm.stubs(:running?).returns(false) @vm.system.expects(:halt).never