Skip to content

Commit

Permalink
execute kitchen destroy on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvw committed Apr 22, 2014
1 parent f39a381 commit ce04081
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
27 changes: 12 additions & 15 deletions lib/guard/kitchen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/kitchen/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

module Guard
class Kitchen < Guard
VERSION = "0.0.2"
VERSION = "0.0.3"
end
end
24 changes: 21 additions & 3 deletions spec/unit/guard/kitchen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce04081

Please # to comment.