Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

--seed option in RSpec

Is anyone able to explain what this actually means? The documentation seems to say that it is similar to setting an order (--seed 123 # same as --order rand:123), but from what I can tell doesn't seem to go into it any further. I'm assuming it's not related to database seed data, but I could well be wrong.

like image 268
johansenja Avatar asked Apr 06 '19 12:04

johansenja


1 Answers

In the default configuration, RSpec runs its tests in random order.

This is considered a good practice because tests should be independent of each other. Running them in a random order helps to find tests that only pass when they are run in a specific order and fail in another order.

But the problem is: When RSpec runs the test in random order and then fails, how can you re-run the test in the exact same order again to debug the issue?

That can be done by telling RSpec to use the same seed for its randomness as it was used before.

RSpec tells you this seed when it is starting:

$ rspec spec

Randomized with seed 48111
.....*.........

To re-run the specs in the exact same order run:

$ rspec spec --seed 48111

Reading about Random#seed might be interesting in this context.

like image 84
spickermann Avatar answered Nov 13 '22 15:11

spickermann