Skip to content

Commit

Permalink
Exit with different status codes when scenarios failed (1) and when a…
Browse files Browse the repository at this point in the history
…pplication exited with error (2).
  • Loading branch information
ciembor committed Apr 30, 2015
1 parent c862c73 commit 92ebc53
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion features/docs/getting_started.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Getting started
puts 'this will not be shown'
"""
When I run `cucumber`
Then the exit status should be 1
Then the exit status should be 2
And the output should not contain:
"""
this will not be shown
Expand Down
2 changes: 1 addition & 1 deletion features/docs/raketask.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ Feature: Raketask

Scenario: Failing feature
When I run `bundle exec rake fail`
Then the exit status should not be 0
Then the exit status should be 1
But the output should not contain "rake aborted!"
19 changes: 11 additions & 8 deletions lib/cucumber/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,30 @@ def execute!(existing_runtime = nil)
end

runtime.run!
failure = runtime.failure? || Cucumber.wants_to_quit
@kernel.exit(failure ? 1 : 0)
if Cucumber.wants_to_quit
@kernel.exit(2)
else
@kernel.exit(runtime.failure? ? 1 : 0)
end
rescue FileNotFoundException => e
@err.puts(e.message)
@err.puts("Couldn't open #{e.path}")
@kernel.exit(1)
@kernel.exit(2)
rescue FeatureFolderNotFoundException => e
@err.puts(e.message + ". You can use `cucumber --init` to get started.")
@kernel.exit(1)
@kernel.exit(2)
rescue ProfilesNotDefinedError, YmlLoadError, ProfileNotFound => e
@err.puts(e.message)
@kernel.exit(1)
@kernel.exit(2)
rescue SystemExit => e
@kernel.exit(e.status)
rescue Errno::EACCES, Errno::ENOENT => e
@err.puts("#{e.message} (#{e.class})")
@kernel.exit(1)
@kernel.exit(2)
rescue Exception => e
@err.puts("#{e.message} (#{e.class})")
@err.puts(e.backtrace.join("\n"))
@kernel.exit(1)
@kernel.exit(2)
end

def configuration
Expand All @@ -70,7 +73,7 @@ def configuration

def trap_interrupt
trap('INT') do
exit!(1) if Cucumber.wants_to_quit
exit!(2) if Cucumber.wants_to_quit
Cucumber.wants_to_quit = true
STDERR.puts "\nExiting... Interrupt again to exit immediately."
end
Expand Down
6 changes: 3 additions & 3 deletions spec/cucumber/cli/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def do_execute
Cucumber.wants_to_quit = false
end

it "registers as a failure" do
it "exits with error code" do
results = double('results', :failure? => false)

allow_any_instance_of(Runtime).to receive(:run!)
allow_any_instance_of(Runtime).to receive(:results) { results }

Cucumber.wants_to_quit = true

expect(kernel).to receive(:exit).with(1)
expect(kernel).to receive(:exit).with(2)

subject.execute!
end
Expand Down Expand Up @@ -93,7 +93,7 @@ def do_execute

allow(Configuration).to receive(:new) { configuration }
allow(configuration).to receive(:parse!).and_raise(exception_klass.new("error message"))
allow(kernel).to receive(:exit).with(1)
allow(kernel).to receive(:exit).with(2)

subject.execute!

Expand Down

0 comments on commit 92ebc53

Please sign in to comment.