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

Ability to checkpoint and restore sequence state #1631

Open
harto opened this issue Mar 28, 2024 · 0 comments
Open

Ability to checkpoint and restore sequence state #1631

harto opened this issue Mar 28, 2024 · 0 comments
Labels

Comments

@harto
Copy link

harto commented Mar 28, 2024

Problem this feature will solve

Several of our tests rely on sequences being reset between examples. So we call FactoryBot.reload in a before(:each). But this interferes with us being able to use create in a before(:all). For example:

RSpec.describe '…' do
  before(:all) { @user = create(:user) }

  before(:each) { FactoryBot.reload }

  it '…' { another_user = create(:user) }
end

The second call to create will attempt to reuse the same ID from the first call.

Desired solution

It might be good if we could somehow checkpoint the state of the sequences, then restore to that state before each example:

RSpec.describe '…' do
  before(:all) {
    FactoryBot.reload
    @user = create(:user)
    FactoryBot.snapshot
  }

  before(:each) { FactoryBot.rollback }

  # …
end

Alternatives considered

Additional context

We rely on IDs being reset between examples because we use approval tests, and in some cases, object IDs appear in the approval output, and it's not straightforward for us to elide them. So we depend on IDs being generated predictably for each example.

@harto harto added the feature label Mar 28, 2024
@harto harto changed the title Ability to checkpoint and restore FactoryBot state Ability to checkpoint and restore sequence state Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant