spring: Spring causes rspec to always order tests the same

When running rspec with config.order = "random" spring causes the order to always be the same.

[master●●] % spring rspec
....

Finished in 0.21176 seconds
4 examples, 0 failures

Randomized with seed 6661

[master●●] % spring rspec
....

Finished in 0.21373 seconds
4 examples, 0 failures

Randomized with seed 6661

[master●●] % spring rspec
....

Finished in 0.16834 seconds
4 examples, 0 failures

Randomized with seed 6661

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 25 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve noticed the same issue today. Since its tied to spring I didn’t want to include it directly in spec_helper so I ended up combining @jcarlson’s solution and @mwean’s solution into one in the config/spring.rb file:

Spring.after_fork do
  if Rails.env == 'test'
    RSpec.configure do |config|
      config.seed = srand % 0xFFFF unless ARGV.any? { |arg| arg =~ /seed/ }
    end
  end
end

This way it’s only done if someone is running bin/rspec but still supports overriding the seed through the command line parameter. Thanks!

For what it’s worth, this is what I’m doing now in my spec_helper.rb:

config.seed = srand % 0xFFFF unless ARGV.any? { |arg| arg =~ /seed/ }

This still gives me the ability to override the seed like I’m used to.

Thanks to everyone in this thread for the above collaboration, and especially to @javierjulio for putting it all together so elegantly.

Just ran into this on spring@2.0.2, rspec@3.7.0. Don’t understand why this is marked as closed. Thankfully the workaround above still works.

Seems like it should just work out of the box. Where would the fix go though? In spring? In spring-commands-rspec?

Thanks @mwean, your workaround works perfectly! @jonleighton This issue should probably be reopened.

This still seems to be an issue [spring@1.6.3, rspec@3.4.0] but the suggestion of @mwean works 😄

Just upgraded to 0.0.10, and I still need this block in config/spring.rb:

Spring.after_fork do
  if Rails.env == 'test'
    RSpec.configure do |config|
      srand; config.seed = srand % 0xFFFF
    end
  end
end

I’m willing to agree that RSpec might be partly at fault here, but even after doing some debugging, I’m kind of at a loss to understand why RSpec gives itself a default seed of 0 with Spring and a random seed without.

Any other thoughts?