From ce04081f9f7b55806e1917d353ec4dc646603f53 Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Tue, 22 Apr 2014 13:24:51 -0400 Subject: [PATCH] execute `kitchen destroy` on stop --- lib/guard/kitchen.rb | 27 ++++++++++++--------------- lib/guard/kitchen/version.rb | 2 +- spec/unit/guard/kitchen_spec.rb | 24 +++++++++++++++++++++--- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lib/guard/kitchen.rb b/lib/guard/kitchen.rb index fc16b30..0afe377 100644 --- a/lib/guard/kitchen.rb +++ b/lib/guard/kitchen.rb @@ -36,21 +36,18 @@ def start end def stop - ::Guard::UI.warning("Guard::Kitchen cannot stop for you, due to strange bug.") - ::Guard::UI.warning("You likely want to run 'kitchen destroy'") - #::Guard::UI.info("Guard::Kitchen is stopping") - #cmd = Mixlib::ShellOut.new("kitchen destroy") - #cmd.live_stream = STDOUT - #cmd.run_command - #begin - # cmd.error! - #rescue Mixlib::ShellOut::ShellCommandFailed => e - # ::Guard::UI.info("Kitchen failed with #{e.to_s}") - # throw :task_has_failed - #ensure - # # Sometimes, we leave the occasional shell process unreaped! - # Process.waitall - #end + ::Guard::UI.info("Guard::Kitchen is stopping") + cmd = Mixlib::ShellOut.new("kitchen destroy", :timeout => 10800) + cmd.live_stream = STDOUT + cmd.run_command + begin + cmd.error! + Notifier.notify('Kitchen destroyed', :title => 'test-kitchen', :image => :success) + rescue Mixlib::ShellOut::ShellCommandFailed => e + Notifier.notify('Kitchen destroy failed', :title => 'test-kitchen', :image => :failed) + ::Guard::UI.info("Kitchen failed with #{e.to_s}") + throw :task_has_failed + end end def reload diff --git a/lib/guard/kitchen/version.rb b/lib/guard/kitchen/version.rb index e8a5e7e..7897575 100644 --- a/lib/guard/kitchen/version.rb +++ b/lib/guard/kitchen/version.rb @@ -3,6 +3,6 @@ module Guard class Kitchen < Guard - VERSION = "0.0.2" + VERSION = "0.0.3" end end diff --git a/spec/unit/guard/kitchen_spec.rb b/spec/unit/guard/kitchen_spec.rb index 4208620..4da4a86 100644 --- a/spec/unit/guard/kitchen_spec.rb +++ b/spec/unit/guard/kitchen_spec.rb @@ -33,11 +33,29 @@ end describe "stop" do - it "yells at you to delete manually" do - Guard::UI.should_receive(:warning).with('Guard::Kitchen cannot stop for you, due to strange bug.') - Guard::UI.should_receive(:warning).with("You likely want to run 'kitchen destroy'") + before(:each) do + @shellout = double('shellout') + @shellout.stub(:live_stream=).with(STDOUT) + @shellout.stub(:run_command) + @shellout.stub(:error!) + Guard::UI.stub(:info).with('Guard::Kitchen is stopping') + Mixlib::ShellOut.stub(:new).with("kitchen destroy", :timeout => 10800).and_return(@shellout) + end + + it "runs kitchen destroy" do + Mixlib::ShellOut.should_receive(:new).with("kitchen destroy", :timeout => 10800).and_return(@shellout) + Guard::UI.should_receive(:info).with('Guard::Kitchen is stopping') + Guard::Notifier.should_receive(:notify).with('Kitchen destroyed', :title => 'test-kitchen', :image => :success) kitchen.stop end + + it "notifies on failure" do + @shellout.should_receive(:error!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + Guard::UI.should_receive(:info).with('Guard::Kitchen is stopping') + Guard::Notifier.should_receive(:notify).with('Kitchen destroy failed', :title => 'test-kitchen', :image => :failed) + Guard::UI.should_receive(:info).with('Kitchen failed with Mixlib::ShellOut::ShellCommandFailed') + expect { kitchen.stop }.to throw_symbol(:task_has_failed) + end end describe "reload" do