Skip to content

Commit

Permalink
Fix Guard's exit-status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Maher4Ever committed Jan 3, 2012
1 parent c01bef5 commit 5cad51e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/guard.rb
Expand Up @@ -214,7 +214,6 @@ def stop

interactor.stop if interactor
listener.stop
abort
end

# Reload all Guards currently enabled.
Expand Down
1 change: 1 addition & 0 deletions lib/guard/cli.rb
Expand Up @@ -74,6 +74,7 @@ def start
::Guard.start(options)
rescue Interrupt
::Guard.stop
abort
end

desc 'list', 'Lists guards that can be used with init'
Expand Down
1 change: 1 addition & 0 deletions lib/guard/interactor.rb
Expand Up @@ -123,6 +123,7 @@ def process_input(line)
help
when :stop
::Guard.stop
exit
when :pause
::Guard.pause
when :reload
Expand Down
24 changes: 20 additions & 4 deletions spec/guard/cli_spec.rb
Expand Up @@ -5,11 +5,27 @@
let(:guard) { Guard }

describe '#start' do
it 'should rescue from an interrupt signal and close nicely' do
guard.should_receive(:start).and_raise(Interrupt)
guard.should_receive(:stop)
context 'with an interrupt signal' do
before do
guard.should_receive(:start).and_raise(Interrupt)
guard.stub(:stop)
end

subject.start
it 'exits nicely' do
guard.should_receive(:stop)
subject.stub(:abort)

subject.start
end

it 'exits with failure status code' do
begin
subject.start
raise 'Guard did not abort!'
rescue SystemExit => e
e.status.should_not eq(0)
end
end
end
end

Expand Down
10 changes: 8 additions & 2 deletions spec/guard/interactor_spec.rb
Expand Up @@ -40,10 +40,16 @@
subject.process_input 'help'
end

it 'stops Guard on stop action' do
it 'stops Guard on stop action and exit' do
subject.should_receive(:extract_scopes_and_action).with('stop').and_return [{ }, :stop]
::Guard.should_receive(:stop)
subject.process_input 'stop'

begin
subject.process_input 'stop'
raise 'Guard did not exit!'
rescue SystemExit => e
e.status.should eq(0)
end
end

it 'pauses Guard on pause action' do
Expand Down

0 comments on commit 5cad51e

Please sign in to comment.