Skip to content

Commit

Permalink
Merge pull request #1 from ericvw/support-kitchen-destroy
Browse files Browse the repository at this point in the history
Support kitchen destroy
  • Loading branch information
adamhjk committed Aug 30, 2014
2 parents 4fec681 + ce04081 commit ccfec5c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 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
38 changes: 28 additions & 10 deletions spec/unit/guard/kitchen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
@shellout.stub(:run_command)
@shellout.stub(:error!)
Guard::UI.stub(:info).with('Guard::Kitchen is starting')
Mixlib::ShellOut.stub(:new).with("kitchen create").and_return(@shellout)
Mixlib::ShellOut.stub(:new).with("kitchen create", :timeout => 10800).and_return(@shellout)
end

it "runs kitchen create" do
Mixlib::ShellOut.should_receive(:new).with("kitchen create").and_return(@shellout)
Mixlib::ShellOut.should_receive(:new).with("kitchen create", :timeout => 10800).and_return(@shellout)
Guard::UI.should_receive(:info).with('Guard::Kitchen is starting')
Guard::Notifier.should_receive(:notify).with('Kitchen created', :title => 'test-kitchen', :image => :success)
kitchen.start
Expand All @@ -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 All @@ -56,14 +74,14 @@
@shellout.stub(:error!)
Guard::UI.stub(:info).with('Guard::Kitchen is running all tests')
Guard::Notifier.stub(:notify)
Mixlib::ShellOut.stub(:new).with("kitchen verify").and_return(@shellout)
Mixlib::ShellOut.stub(:new).with("kitchen verify", :timeout => 10800).and_return(@shellout)
end

it "runs kitchen verify" do
Guard::UI.should_receive(:info).with('Guard::Kitchen is running all tests')
Guard::UI.should_receive(:info).with('Kitchen verify succeeded')
Guard::Notifier.should_receive(:notify).with('Kitchen verify succeeded', :title => 'test-kitchen', :image => :success)
Mixlib::ShellOut.should_receive(:new).with("kitchen verify").and_return(@shellout)
Mixlib::ShellOut.should_receive(:new).with("kitchen verify", :timeout => 10800).and_return(@shellout)
kitchen.run_all
end

Expand All @@ -89,15 +107,15 @@
Guard::UI.should_receive(:info).with("Guard::Kitchen is running suites: default")
Guard::UI.should_receive(:info).with("Kitchen verify succeeded for: default")
Guard::Notifier.stub(:notify).with("Kitchen verify succeeded for: default", :title => 'test-kitchen', :image => :success)
Mixlib::ShellOut.should_receive(:new).with("kitchen verify '(default)-.+' -p").and_return(@shellout)
Mixlib::ShellOut.should_receive(:new).with("kitchen verify '(default)-.+' -p", :timeout=>10800).and_return(@shellout)
kitchen.run_on_changes(["test/integration/default/bats/foo.bats"])
end

it "runs multiple integration test suites in isolation" do
Guard::UI.should_receive(:info).with("Guard::Kitchen is running suites: default, monkey")
Guard::UI.should_receive(:info).with("Kitchen verify succeeded for: default, monkey")
Guard::Notifier.stub(:notify).with("Kitchen verify succeeded for: default, monkey", :title => 'test-kitchen', :image => :success)
Mixlib::ShellOut.should_receive(:new).with("kitchen verify '(default|monkey)-.+' -p").and_return(@shellout)
Mixlib::ShellOut.should_receive(:new).with("kitchen verify '(default|monkey)-.+' -p", :timeout=>10800).and_return(@shellout)
kitchen.run_on_changes(["test/integration/default/bats/foo.bats","test/integration/monkey/bats/foo.bats"])
end
end
Expand All @@ -115,7 +133,7 @@
Guard::UI.should_receive(:info).with("Guard::Kitchen is running converge for all suites")
Guard::UI.should_receive(:info).with("Kitchen converge succeeded")
Guard::Notifier.stub(:notify).with("Kitchen converge succeeded", :title => 'test-kitchen', :image => :success)
Mixlib::ShellOut.should_receive(:new).with('kitchen converge').and_return(@shellout)
Mixlib::ShellOut.should_receive(:new).with('kitchen converge', :timeout => 10800).and_return(@shellout)
kitchen.run_on_changes(["recipes/default.rb"])
end
end
Expand Down

0 comments on commit ccfec5c

Please sign in to comment.