File: failure_exit_code.feature

package info (click to toggle)
ruby-rspec 3.9.0c2e2m1s3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,612 kB
  • sloc: ruby: 67,456; sh: 1,572; makefile: 98
file content (53 lines) | stat: -rw-r--r-- 1,399 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Feature: failure exit code

  Use the `failure_exit_code` option to set a custom exit code when RSpec fails.

  ```ruby
  RSpec.configure { |c| c.failure_exit_code = 42 }
  ```

  Background:
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure { |c| c.failure_exit_code = 42 }
      """

  Scenario: A failing spec with the default exit code
    Given a file named "spec/example_spec.rb" with:
      """ruby
      RSpec.describe "something" do
        it "fails" do
          fail
        end
      end
      """
    When I run `rspec spec/example_spec.rb`
    Then the exit status should be 1

  Scenario: A failing spec with a custom exit code
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require 'spec_helper'
      RSpec.describe "something" do
        it "fails" do
          fail
        end
      end
      """
    When I run `rspec spec/example_spec.rb`
    Then the exit status should be 42

  Scenario: Exit with the default exit code when an `at_exit` hook is added upstream
    Given a file named "exit_at_spec.rb" with:
      """ruby
      require 'rspec/autorun'
      at_exit { exit(0) }

      RSpec.describe "exit 0 at_exit ignored" do
        it "does not interfere with the default exit code" do
          fail
        end
      end
      """
    When I run `ruby exit_at_spec.rb`
    Then the exit status should be 1