Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add --failure-exit-code option #472

Merged
merged 1 commit into from

3 participants

@justinko

Thanks for the pull @cgriego. We are in the middle of a release candidate, but we still might merge this. Up to @dchelimsky

@dchelimsky dchelimsky merged commit b8e25ec into rspec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 12, 2011
  1. @cgriego

    Add --failure-exit-code option

    cgriego authored
This page is out of date. Refresh to see the latest.
View
16 features/command_line/exit_status.feature
@@ -1,7 +1,8 @@
Feature: exit status
The rspec command exits with an exit status of 0 if all examples pass,
- and 1 if any examples fail.
+ and 1 if any examples fail. The failure exit code can be overridden
+ using the --failure-exit-code option.
Scenario: exit with 0 when all examples pass
Given a file named "ok_spec.rb" with:
@@ -51,6 +52,19 @@ Feature: exit status
Then the exit status should be 0
And the output should contain "0 examples"
+ Scenario: exit with 2 when one example fails and --failure-exit-code is 2
+ Given a file named "ko_spec.rb" with:
+ """
+ describe "KO" do
+ it "fails" do
+ raise "KO"
+ end
+ end
+ """
+ When I run `rspec --failure-exit-code 2 ko_spec.rb`
+ Then the exit status should be 2
+ And the output should contain "1 example, 1 failure"
+
@wip
Scenario: exit with rspec's exit code when an at_exit hook is added upstream
Given a file named "exit_at_spec.rb" with:
View
2  lib/rspec/core/command_line.rb
@@ -21,7 +21,7 @@ def run(err, out)
@configuration.reporter.report(@world.example_count) do |reporter|
begin
@configuration.run_hook(:before, :suite)
- @world.example_groups.map {|g| g.run(reporter)}.all? ? 0 : 1
+ @world.example_groups.map {|g| g.run(reporter)}.all? ? 0 : @configuration.failure_exit_code
ensure
@configuration.run_hook(:after, :suite)
end
View
1  lib/rspec/core/configuration.rb
@@ -28,6 +28,7 @@ def self.add_setting(name, opts={})
add_setting :drb_port
add_setting :profile_examples
add_setting :fail_fast
+ add_setting :failure_exit_code, :default => 1
add_setting :run_all_when_everything_filtered
add_setting :exclusion_filter
add_setting :inclusion_filter
View
4 lib/rspec/core/option_parser.rb
@@ -116,6 +116,10 @@ def parser(options)
options[:fail_fast] = true
end
+ parser.on('--failure-exit-code CODE', 'Override the exit code used when there are failing specs.') do |o|
+ options[:failure_exit_code] = o.to_i
+ end
+
parser.on('-t', '--tag TAG[:VALUE]', 'Run examples with the specified tag',
'To exclude examples, add ~ before the tag (e.g. ~slow)',
'(TAG is always converted to a symbol)') do |tag|
View
8 spec/rspec/core/command_line_spec.rb
@@ -27,11 +27,17 @@ def config_options(argv=[])
result.should be(0)
end
- it "returns 1 if spec passes" do
+ it "returns 1 if spec fails" do
err, out = StringIO.new, StringIO.new
result = command_line([failing_spec_filename]).run(err, out)
result.should be(1)
end
+
+ it "returns 2 if spec fails and --failure-exit-code is 2" do
+ err, out = StringIO.new, StringIO.new
+ result = command_line([failing_spec_filename, "--failure-exit-code", "2"]).run(err, out)
+ result.should be(2)
+ end
end
context "given an Array of options" do
View
12 spec/rspec/core/configuration_options_spec.rb
@@ -168,6 +168,18 @@ def parse_options(*args)
end
end
+ describe "--failure-exit-code" do
+ it "sets :failure_exit_code" do
+ parse_options('--failure-exit-code', '0').should include(:failure_exit_code => 0)
+ parse_options('--failure-exit-code', '1').should include(:failure_exit_code => 1)
+ parse_options('--failure-exit-code', '2').should include(:failure_exit_code => 2)
+ end
+
+ it "overrides previous :failure_exit_code" do
+ parse_options('--failure-exit-code', '2', '--failure-exit-code', '3').should include(:failure_exit_code => 3)
+ end
+ end
+
describe "--options" do
it "sets :custom_options_file" do
parse_options(*%w[-O my.opts]).should include(:custom_options_file => "my.opts")
Something went wrong with that request. Please try again.