diff --git a/lib/vagrant/action/vm/discard_state.rb b/lib/vagrant/action/vm/discard_state.rb index dee46a41d..ad56b6a02 100644 --- a/lib/vagrant/action/vm/discard_state.rb +++ b/lib/vagrant/action/vm/discard_state.rb @@ -9,7 +9,7 @@ module Vagrant end def call(env) - if env["vm"].vm.saved? + if env["vm"].created? && env["vm"].vm.saved? env.ui.info "vagrant.actions.vm.discard_state.discarding" env["vm"].vm.discard_state end diff --git a/test/vagrant/action/vm/discard_state_test.rb b/test/vagrant/action/vm/discard_state_test.rb index cc1807553..b0732360e 100644 --- a/test/vagrant/action/vm/discard_state_test.rb +++ b/test/vagrant/action/vm/discard_state_test.rb @@ -16,11 +16,20 @@ class DiscardStateVMActionTest < Test::Unit::TestCase context "calling" do setup do + @vm.stubs(:created?).returns(true) @internal_vm.stubs(:saved?).returns(false) end + should "do nothing if the VM is not created" do + @vm.stubs(:created?).returns(false) + @internal_vm.expects(:discard_state).never + @app.expects(:call).with(@env).once + @instance.call(@env) + end + should "do nothing if not saved and continue chain" do @internal_vm.expects(:saved?).returns(false) + @internal_vm.expects(:discard_state).never @app.expects(:call).with(@env).once @instance.call(@env) end