Preserving a predictable output
- Dominant language
- Ruby
- Stars
- 509
- Forks
- 76
- Avg merge
- 12h 46m
- Merged PRs (30d)
- 16
Description
Hey :)
Using this gem we noticed that having predictable data in different run can be useful if you are going to regenerate the OpenAPI documentation (fully or partially).
To achieve this goal we are using this configuration block:
```rb
if ENV['OPENAPI'].present?
seed = ENV.fetch('OPENAPI_SEED', 0xFFFF)
srand(seed)
Faker::Config.random = Random.new(seed) if defined? Faker
RSpec.configure do |config|
config.order = :defined
config.before do
allow(Devise).to receive(:friendly_token) { ('A'..'Z').to_a.sample(20).join } if defined? Devise
ActiveRecord::Base.connection.tables.each do |t|
# to preserve IDs
ActiveRecord::Base.connection.reset_pk_sequence!(t)
end
end
config.include ActiveSupport::Testing::TimeHelpers
config.around do |example|
time = Time.zone.local(2022, 10, 15, 12, 34, 56)
travel_to(time) # to preserve dates & times
example.run
travel_back
end
end
end
```
Perhaps these kind of options shouldn't be included in the gem (they are _configuration_) but they could be useful in the README to help others.
WDYT?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.