diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index 8c936a67f..f4b009303 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -22,8 +22,10 @@ module Vagrant end def recover(env) - # Interrupted, destroy the VM - env["actions"].run(:destroy) + if env["vm"].created? + # Interrupted, destroy the VM + env["actions"].run(:destroy) + end end end end diff --git a/test/vagrant/action/vm/import_test.rb b/test/vagrant/action/vm/import_test.rb index a7ef57726..8c2caa785 100644 --- a/test/vagrant/action/vm/import_test.rb +++ b/test/vagrant/action/vm/import_test.rb @@ -40,11 +40,15 @@ class ImportVMActionTest < Test::Unit::TestCase } end + should "not run the destroy action on recover if VM is not created" do + @env.env.vm.stubs(:created?).returns(false) + @env.env.actions.expects(:run).never + @instance.recover(@env) + end + should "run the destroy action on recover" do - env = mock("env") - destroy = mock("destory") - env.expects(:[]).with("actions").returns(destroy) - destroy.expects(:run).with(:destroy) - @instance.recover(env) + @env.env.vm.stubs(:created?).returns(true) + @env.env.actions.expects(:run).with(:destroy).once + @instance.recover(@env) end end