Skip to content

fix: wrap fabricator time attributes in blocks to prevent flaky tests#2631

Merged
olleolleolle merged 1 commit into
masterfrom
fix/flaky-fabricator-time-attributes
Jun 6, 2026
Merged

fix: wrap fabricator time attributes in blocks to prevent flaky tests#2631
olleolleolle merged 1 commit into
masterfrom
fix/flaky-fabricator-time-attributes

Conversation

@mroderick
Copy link
Copy Markdown
Collaborator

Problem

The Fabrication gem evaluates attributes without blocks once and caches the value. When Fabricate(:event) was first called inside a travel_to block (e.g. in event_spec.rb), the date_and_time default was cached as a past date. All subsequent events fabricated in the same process reused that cached value, making them appear as past events.

This caused view_event_spec feature tests to fail because the event page showed 'This event has already occurred' instead of the 'Log in' link.

Changes

  • Wrap date_and_time, rsvp_opens_at, and past_workshop.date_and_time in Fabrication blocks so they evaluate dynamically at fabrication time
  • Reset Capybara sessions after each feature spec as a defensive measure against session leaks between tests

Verification

Reproduced the failure locally with the exact CI command and seed (41835, group 2). After the fix, the same command passes with 0 failures. Ran multiple additional seeds and the full test suite — all green.

The Fabrication gem evaluates attributes without blocks once and caches
the value. When  was first called inside a
travel_to block (e.g. in event_spec.rb), the date_and_time default
was cached as a past date. All subsequent events fabricated in the
same process reused that cached value, making them appear as past
events. This caused the view_event_spec feature tests to fail because
the event page showed 'This event has already occurred' instead of
the 'Log in' link.

Also reset Capybara sessions after each feature spec as a defensive
measure against session leaks between tests.
@mroderick mroderick marked this pull request as ready for review May 29, 2026 20:45
@mroderick mroderick requested a review from olleolleolle June 5, 2026 15:47
Copy link
Copy Markdown
Collaborator

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, did you experience flakes when not having the reset_sessions!? Anyway, good fix!

@olleolleolle olleolleolle merged commit 478be12 into master Jun 6, 2026
16 checks passed
@olleolleolle olleolleolle deleted the fix/flaky-fabricator-time-attributes branch June 6, 2026 11:02
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

Successfully merging this pull request may close these issues.

2 participants