Debugging randomly failing specs

With RSpec configured to run specs in a random order

# spec/spec_helper.rb

RSpec.configure do |config|
  # ...
  config.order = :random
  # ...
end

it might happen that some of them will start randomly falling, surfacing order dependencies. In most cases the specs will pass with no errors, but from time to time some of them might fail giving false negatives.

It might look like that debugging in such cases will be quite hard as we have no idea when the specs will fail. It is not that bad. In most cases it is enough to keep running the specs until the first random failure and check the seed printed after the run.

$ rspec


Randomized with seed 60715
.....................................................................F...........
.................................................................................

Finished in 1 minute 19.52 seconds (files took 2.66 seconds to load)
430 examples, 1 failure

Randomized with seed 60715

Now you can re-run the specs providing the same seed to keep the same order.

$ rspec --seed 60715

When you are able to repeat the error, dubugging is not a problem anymore.