Skip to content

Commit 804c97e

Browse files
committed
Explain random order test suite runs
1 parent b7e4fdb commit 804c97e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Hopefully this will be of help to those of you learning RSpec and Rails. If ther
2121
<!-- MarkdownTOC depth=0 autolink=true bracket=round -->
2222

2323
- [Support Configuration](#support-configuration)
24+
- [Run Specs in a Random Order](#run-specs-in-a-random-order)
2425
- [Testing Rake Tasks with RSpec](#testing-rake-tasks-with-rspec)
2526
- [Pry-rescue debugging](#pry-rescue-debugging)
2627
- [Time Travel Examples](#time-travel-examples)
@@ -60,6 +61,18 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
6061
(The rspec-rails installer generates this line, but it will be commented out.)
6162

6263

64+
# Run Specs in a Random Order
65+
66+
In a dependable, repeatable automated test suite, data stores (such as database, job queues, and sent email on `ActionMailer::Base.deliveries`) should return to a consistent state between each spec, regardless of the order specs are run in.
67+
68+
For a maintainable, predictable test suite, one spec should not set up data (e.g. creating users) needed by a later spec to pass. Each spec should look after its own test data and clear up after itself. (NB. If there is reference data that all tests need, such as populating a `countries` table, then this can go in `db/seeds.rb` and be run once before the entire suite).
69+
70+
The specs run in a random order each time the test suite is run. This helps prevent the introduction of run order and test data dependencies between tests, which are best avoided.
71+
72+
Random test order configuration how-to:
73+
- [spec/spec_helper.rb](spec/spec_helper.rb)
74+
75+
6376
# Testing Rake Tasks with RSpec
6477

6578
RSpec testing Rake task configuration and example:

0 commit comments

Comments
 (0)