RSpec / RSpec Core / Docs / Configuration
This page comes from RSpec Core 3.12.3. It is not part of the 3.12.1 docs. See the latest RSpec Core docs.
Setting an error exit code
Use the error_exit_code option to set a custom exit code when RSpec fails outside an example.
ruby
RSpec.configure { |c| c.error_exit_code = 42 }Background:
- Given a file named "
spec/spec_helper.rb" with:rubyRSpec.configure { |c| c.error_exit_code = 42 }
Scenario: A erroring spec with the default exit code
- Given a file named "
spec/typo_spec.rb" with:rubyRSpec.escribe "something" do # intentional typo it "works" do true end end - When I run `rspec spec/typo_spec.rb`
- Then the exit status should be 1
Scenario: A erroring spec with a custom exit code
- Given a file named "
spec/typo_spec.rb" with:rubyrequire 'spec_helper' RSpec.escribe "something" do # intentional typo it "works" do true end end - When I run `rspec spec/typo_spec.rb`
- And the exit status should be 42
Scenario: Success running specs spec with a custom error exit code defined
- Given a file named "
spec/example_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe "something" do it "works" do true end end - When I run `rspec spec/example_spec.rb`
- Then the exit status should be 0
Source: features/configuration/error_exit_code.feature at v3.12.3, RSpec Core (MIT license).