Skip to content

Fix flaky system tests: wait for Turbo redirect before asserting content#80

Merged
HamptonMakes merged 1 commit intomainfrom
fix-flaky-comment-ux
Apr 3, 2026
Merged

Fix flaky system tests: wait for Turbo redirect before asserting content#80
HamptonMakes merged 1 commit intomainfrom
fix-flaky-comment-ux

Conversation

@HamptonMakes
Copy link
Copy Markdown
Collaborator

Problem

System tests intermittently fail with Node with given id does not belong to the document during sign_in (e.g., comment_ux_spec.rb:596). This is a Selenium race condition: after click_button 'Sign In', Turbo Drive replaces the page body via a redirect to the plans index. If have_content('Sign out') is evaluated before the navigation completes, Selenium references a stale DOM node from the sign-in page.

Fix

Add expect(page).to have_current_path(root_path) after click_button to wait for the Turbo redirect to complete before asserting on the new page's content. This is standard Capybara best practice for form submissions that trigger page navigations.

Applied to all three system spec files sharing this sign-in pattern:

  • spec/system/comment_ux_spec.rb
  • spec/system/comment_anchoring_spec.rb
  • spec/system/tokens_spec.rb

Verification

All 40 system specs pass locally.

After clicking 'Sign In', Turbo Drive replaces the page body via a
redirect to the plans index. If Selenium asserts have_content('Sign out')
before the navigation completes, it references a stale DOM node from the
sign-in page, causing 'Node with given id does not belong to the document'.

Fix: add have_current_path(root_path) after click_button to wait for the
redirect to complete before asserting on the new page's content. Applied
to all three system spec files that share this sign-in pattern.

Amp-Thread-ID: https://ampcode.com/threads/T-019d5520-a72e-723a-9dc4-7ee62fb4fb5d
Co-authored-by: Amp <amp@ampcode.com>
@HamptonMakes HamptonMakes merged commit f5d0a48 into main Apr 3, 2026
4 checks passed
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.

1 participant