From 4335adc8f4061be97762b77a3cef5be583898183 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 12 Sep 2010 16:26:32 -0600 Subject: [PATCH] Only discard state if the VM is created --- lib/vagrant/action/vm/discard_state.rb | 2 +- test/vagrant/action/vm/discard_state_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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