File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
10
10
11
11
For a steady stream of TILs, [ sign up for my newsletter] ( https://crafty-builder-6996.ck.page/e169c61186 ) .
12
12
13
- _ 1437 TILs and counting..._
13
+ _ 1438 TILs and counting..._
14
14
15
15
---
16
16
@@ -1101,6 +1101,7 @@ _1437 TILs and counting..._
1101
1101
1102
1102
- [ Avoid Accidentally Disabling Pry] ( rspec/avoid-accidentally-disabling-pry.md )
1103
1103
- [ Check Specific Arguments To Received Method] ( rspec/check-specific-arguments-to-received-method.md )
1104
+ - [ Configure Tests To Run In Random Order] ( rspec/configure-tests-to-run-in-random-order.md )
1104
1105
- [ Find Minimal Set Of Tests Causing A Flicker] ( rspec/find-minimal-set-of-tests-causing-a-flicker.md )
1105
1106
- [ Format Test Results As A JSON File] ( rspec/format-test-results-as-a-json-file.md )
1106
1107
- [ Run Tests With Documentation Formatting] ( rspec/run-tests-with-documentation-formatting.md )
Original file line number Diff line number Diff line change
1
+ # Configure Tests To Run In Random Order
2
+
3
+ By default, an RSpec test suite is going to run in a predictable, sequential
4
+ order, every time.
5
+
6
+ When testing the parts of a complex Rails app that have all kinds of test data
7
+ that needs to be set up, I prefer to have my tests always run in a random
8
+ (repeatable with a seed) order. This way I'm more likely to catch sooner,
9
+ rather than later, bugs that are hidden by passing tests due to test data setup
10
+ that happens to work in a specific order.
11
+
12
+ RSpec can be configured to run tests in a random, seedable order in the
13
+ ` spec_helper.rb ` file.
14
+
15
+ ``` ruby
16
+ RSpec .configure do |config |
17
+ config.order = :random
18
+ end
19
+ ```
20
+
21
+ Whenever you run your test suite, the first thing you'll see is a message like
22
+ this:
23
+
24
+ ```
25
+ Randomized with seed 7011
26
+ ```
27
+
28
+ That seed number can be used to re-run the suite in a repeatable order when you
29
+ need to do so to track down an order-dependent failing test.
30
+
31
+ ``` bash
32
+ $ be rspec --seed 7011
33
+ ```
You can’t perform that action at this time.
0 commit comments