Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same-seeded rspec test runs no longer generate deterministic data #2281

Closed
jasonkarns opened this issue Mar 12, 2021 · 4 comments
Closed

Same-seeded rspec test runs no longer generate deterministic data #2281

jasonkarns opened this issue Mar 12, 2021 · 4 comments

Comments

@jasonkarns
Copy link

Describe the bug

Given an identical Kernel seed value, Faker should generate the same deterministic data, but it does not.

Seems to have been caused by #2226

To Reproduce

Given a conventional rspec test suite, with randomization enabled: the conventional rspec configuration sets the Kernel seed to the rspec seed:

  # conventional spec_helper.rb
  config.order = :random
  Kernel.srand config.seed

Then rspec --seed 1234 generates non-deterministic faker data.

Expected behavior

I would expect Faker to be based on the Kernel.srand seed, as configured with rspec. This way two same-seeded rspec runs would generate identical test data.

Additional context

We're currently working around this by adding the following to our rspec configuration:

   config.order = :random
   Kernel.srand config.seed
+  Faker::Config.random = Random.new(config.seed)
@connorshea
Copy link
Member

oooh 😬 I'm not sure how to fix this in the Faker gem itself other than just telling people to use the workaround you've suggested.

@vbrazo @koic any ideas here?

@havenwood
Copy link

Should Random.new here be Random.new(Random.seed) instead? The default seed argument is currently resulting in Random.new(Random.new_seed).

@hosamaly
Copy link
Contributor

How about using RSpec's seed if it's loaded?

module Faker
  module Config
    def random
        @random || (defined?(RSpec) ? Random.new(RSpec.configuration.seed) : Random.new)
      end
  end
end

@connorshea
Copy link
Member

This should be fixed now by #2488, although it's not in the 2.21.0 release that just went out. Regardless, I'm going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants