Debian Codegraph @

rspec-core/features/command_line/bisect.feature

raw
1 @with-clean-spec-opts
2 Feature: Bisect
3
4 RSpec's `--order random` and `--seed` options help surface flickering examples that only fail when one or more other examples are executed first. It can be very difficult to isolate the exact combination of examples that triggers the failure. The `--bisect` flag helps solve that problem.
5
6 Pass the `--bisect` option (in addition to `--seed` and any other options) and RSpec will repeatedly run subsets of your suite in order to isolate the minimal set of examples that reproduce the same failures.
7
8 At any point during the bisect run, you can hit ctrl-c to abort and it will provide you with the most minimal reproduction command it has discovered so far.
9
10 To get more detailed output (particularly useful if you want to report a bug with bisect), use `--bisect=verbose`.
11
12 Background:
13 Given a file named "lib/calculator.rb" with:
14 """ruby
15 class Calculator
16 def self.add(x, y)
17 x + y
18 end
19 end
20 """
21 And a file named "spec/calculator_1_spec.rb" with:
22 """ruby
23 require 'calculator'
24
25 RSpec.describe "Calculator" do
26 it 'adds numbers' do
27 expect(Calculator.add(1, 2)).to eq(3)
28 end
29 end
30 """
31 And files "spec/calculator_2_spec.rb" through "spec/calculator_9_spec.rb" with an unrelated passing spec in each file
32 And a file named "spec/calculator_10_spec.rb" with:
33 """ruby
34 require 'calculator'
35
36 RSpec.describe "Monkey patched Calculator" do
37 it 'does screwy math' do
38 # monkey patching `Calculator` affects examples that are
39 # executed after this one!
40 def Calculator.add(x, y)
41 x - y
42 end
43
44 expect(Calculator.add(5, 10)).to eq(-5)
45 end
46 end
47 """
48
49 Scenario: Use `--bisect` flag to create a minimal repro case for the ordering dependency
50 When I run `rspec --seed 1234`
51 Then the output should contain "10 examples, 1 failure"
52 When I run `rspec --seed 1234 --bisect`
53 Then bisect should succeed with output like:
54 """
55 Bisect started using options: "--seed 1234"
56 Running suite to find failures... (0.16755 seconds)
57 Starting bisect with 1 failing example and 9 non-failing examples.
58 Checking that failure(s) are order-dependent... failure appears to be order-dependent
59
60 Round 1: bisecting over non-failing examples 1-9 .. ignoring examples 6-9 (0.30166 seconds)
61 Round 2: bisecting over non-failing examples 1-5 .. ignoring examples 4-5 (0.30306 seconds)
62 Round 3: bisecting over non-failing examples 1-3 .. ignoring example 3 (0.33292 seconds)
63 Round 4: bisecting over non-failing examples 1-2 . ignoring example 1 (0.16476 seconds)
64 Bisect complete! Reduced necessary non-failing examples from 9 to 1 in 1.26 seconds.
65
66 The minimal reproduction command is:
67 rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] --seed 1234
68 """
69 When I run `rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] --seed 1234`
70 Then the output should contain "2 examples, 1 failure"
71
72 Scenario: Ctrl-C can be used to abort the bisect early and get the most minimal command it has discovered so far
73 When I run `rspec --seed 1234 --bisect` and abort in the middle with ctrl-c
74 Then bisect should fail with output like:
75 """
76 Bisect started using options: "--seed 1234"
77 Running suite to find failures... (0.17102 seconds)
78 Starting bisect with 1 failing example and 9 non-failing examples.
79 Checking that failure(s) are order-dependent... failure appears to be order-dependent
80
81 Round 1: bisecting over non-failing examples 1-9 .. ignoring examples 6-9 (0.32943 seconds)
82 Round 2: bisecting over non-failing examples 1-5 .. ignoring examples 4-5 (0.3154 seconds)
83 Round 3: bisecting over non-failing examples 1-3 .. ignoring example 3 (0.2175 seconds)
84
85 Bisect aborted!
86
87 The most minimal reproduction command discovered so far is:
88 rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_3_spec.rb[1:1] --seed 1234
89 """
90 When I run `rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_3_spec.rb[1:1] --seed 1234`
91 Then the output should contain "3 examples, 1 failure"
92
93 Scenario: Use `--bisect=verbose` to enable verbose debug mode for more detail
94 When I run `rspec --seed 1234 --bisect=verbose`
95 Then bisect should succeed with output like:
96 """
97 Bisect started using options: "--seed 1234" and bisect runner: :fork
98 Running suite to find failures... (0.16528 seconds)
99 - Failing examples (1):
100 - ./spec/calculator_1_spec.rb[1:1]
101 - Non-failing examples (9):
102 - ./spec/calculator_10_spec.rb[1:1]
103 - ./spec/calculator_2_spec.rb[1:1]
104 - ./spec/calculator_3_spec.rb[1:1]
105 - ./spec/calculator_4_spec.rb[1:1]
106 - ./spec/calculator_5_spec.rb[1:1]
107 - ./spec/calculator_6_spec.rb[1:1]
108 - ./spec/calculator_7_spec.rb[1:1]
109 - ./spec/calculator_8_spec.rb[1:1]
110 - ./spec/calculator_9_spec.rb[1:1]
111 Checking that failure(s) are order-dependent..
112 - Running: rspec ./spec/calculator_1_spec.rb[1:1] --seed 1234 (n.nnnn seconds)
113 - Failure appears to be order-dependent
114 Round 1: bisecting over non-failing examples 1-9
115 - Running: rspec ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_6_spec.rb[1:1] ./spec/calculator_7_spec.rb[1:1] ./spec/calculator_8_spec.rb[1:1] ./spec/calculator_9_spec.rb[1:1] --seed 1234 (0.15302 seconds)
116 - Running: rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_2_spec.rb[1:1] ./spec/calculator_3_spec.rb[1:1] ./spec/calculator_4_spec.rb[1:1] ./spec/calculator_5_spec.rb[1:1] --seed 1234 (0.19708 seconds)
117 - Examples we can safely ignore (4):
118 - ./spec/calculator_6_spec.rb[1:1]
119 - ./spec/calculator_7_spec.rb[1:1]
120 - ./spec/calculator_8_spec.rb[1:1]
121 - ./spec/calculator_9_spec.rb[1:1]
122 - Remaining non-failing examples (5):
123 - ./spec/calculator_10_spec.rb[1:1]
124 - ./spec/calculator_2_spec.rb[1:1]
125 - ./spec/calculator_3_spec.rb[1:1]
126 - ./spec/calculator_4_spec.rb[1:1]
127 - ./spec/calculator_5_spec.rb[1:1]
128 Round 2: bisecting over non-failing examples 1-5
129 - Running: rspec ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_4_spec.rb[1:1] ./spec/calculator_5_spec.rb[1:1] --seed 1234 (0.15836 seconds)
130 - Running: rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_2_spec.rb[1:1] ./spec/calculator_3_spec.rb[1:1] --seed 1234 (0.19065 seconds)
131 - Examples we can safely ignore (2):
132 - ./spec/calculator_4_spec.rb[1:1]
133 - ./spec/calculator_5_spec.rb[1:1]
134 - Remaining non-failing examples (3):
135 - ./spec/calculator_10_spec.rb[1:1]
136 - ./spec/calculator_2_spec.rb[1:1]
137 - ./spec/calculator_3_spec.rb[1:1]
138 Round 3: bisecting over non-failing examples 1-3
139 - Running: rspec ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_2_spec.rb[1:1] --seed 1234 (0.21028 seconds)
140 - Running: rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_3_spec.rb[1:1] --seed 1234 (0.1975 seconds)
141 - Examples we can safely ignore (1):
142 - ./spec/calculator_2_spec.rb[1:1]
143 - Remaining non-failing examples (2):
144 - ./spec/calculator_10_spec.rb[1:1]
145 - ./spec/calculator_3_spec.rb[1:1]
146 Round 4: bisecting over non-failing examples 1-2
147 - Running: rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] --seed 1234 (0.17173 seconds)
148 - Examples we can safely ignore (1):
149 - ./spec/calculator_3_spec.rb[1:1]
150 - Remaining non-failing examples (1):
151 - ./spec/calculator_10_spec.rb[1:1]
152 Bisect complete! Reduced necessary non-failing examples from 9 to 1 in 1.47 seconds.
153
154 The minimal reproduction command is:
155 rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] --seed 1234
156 """
157 When I run `rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] --seed 1234`
158 Then the output should contain "2 examples, 1 failure"
159
160 Scenario: Pick a bisect runner via a config option
161 Given a file named "spec/spec_helper.rb" with:
162 """
163 RSpec.configure do |c|
164 c.bisect_runner = :shell
165 end
166 """
167 And a file named ".rspec" with:
168 """
169 --require spec_helper
170 """
171 When I run `rspec --seed 1234 --bisect=verbose`
172 Then bisect should succeed with output like:
173 """
174 Bisect started using options: "--seed 1234" and bisect runner: :shell
175 # ...
176 The minimal reproduction command is:
177 rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] --seed 1234
178 """