Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does RSpec seeds run the same on different machines?

Tags:

rspec

I am trying to set up CI using Travis. But I'm running into tests failing on Travis but not locally, even providing the same seed.

I thought the seeds run the same but now I am unsure and would like to make it clear wether it does or not so I now where to look at.

like image 812
Adrien Avatar asked Apr 25 '17 15:04

Adrien


Video Answer


1 Answers

Have a look at this RSpec feature page:

In Ruby, randomness is seeded by calling srand and passing it the seed that you want to use. By doing this, subsequent calls to rand, shuffle, sample, etc. will all be randomized the same way given the same seed is passed to srand.

So in short, yes, it will run in the same order on other machines.

Ruby's srand does guarantee the same numbers across machines using the same Ruby version. See this SO question and resulting answers: Does seed generate same random sequence across different Rubys?

like image 164
jakenberg Avatar answered Oct 14 '22 07:10

jakenberg