exoego / exoego/rspec-openapi

Preserving a predictable output

Open
#76 1 comment 6 reactions 0 assignees View on GitHub
documentation good first issue
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.