Skip to content

Enable additional Rubocop rules for Capybara tests#12413

Merged
mitchellhenke merged 3 commits intomainfrom
mitchellhenke/add-capybara-rubocops
Aug 12, 2025
Merged

Enable additional Rubocop rules for Capybara tests#12413
mitchellhenke merged 3 commits intomainfrom
mitchellhenke/add-capybara-rubocops

Conversation

@mitchellhenke
Copy link
Contributor

@mitchellhenke mitchellhenke commented Aug 8, 2025

🛠 Summary of changes

We've seen some issues over time with race conditions in feature tests between the headless browser and server. Part of improving it has been moving towards assertions on arriving at a page, including past work in #11669, though it has the limitation of only working on current_path, and we have a similar issue with current_url. We also have conditional checks on current_path for taking different actions or flows based on the result, which can cause similar issues.

This borrows from the existing rule to implement a very similar one in CapybaraCurrentUrlExpectLinter to address the first issue and more distinct CapybaraCurrentPathEqualityLinter to address the second. There was some discussion on test reliability in this week's Engineering Huddle related to this issue as well. I've also enabled a handful of other Capybara-related Rubocop rules that did not have any findings, but I think are worth enforcing.

This did also uncover some incorrect assertions that succeeded due to the race conditions involved (example).

@mitchellhenke mitchellhenke requested a review from a team August 8, 2025 17:22
@mitchellhenke mitchellhenke force-pushed the mitchellhenke/add-capybara-rubocops branch 11 times, most recently from 28d473b to 57a8026 Compare August 12, 2025 14:44
Copy link
Contributor

@solipet solipet left a comment

Choose a reason for hiding this comment

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

This is awesome! A few minor suggestions - take or leave.

Comment on lines 30 to 31
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@mitchellhenke mitchellhenke force-pushed the mitchellhenke/add-capybara-rubocops branch 6 times, most recently from 3bdab20 to e996593 Compare August 12, 2025 20:01
Mitchell Henke and others added 3 commits August 12, 2025 15:06
changelog: Internal, Testing, Create Rubocop rule to enforce stricter path assertions in feature tests

Co-authored-by: Doug Price <douglas.price@gsa.gov>
@mitchellhenke mitchellhenke force-pushed the mitchellhenke/add-capybara-rubocops branch from e996593 to ac853ff Compare August 12, 2025 20:06
Comment on lines -24 to -31
before do
allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics)
allow_any_instance_of(ApplicationController).to receive(:attempts_api_tracker).and_return(
attempts_api_tracker,
)
sign_in_and_2fa_user(user)
complete_doc_auth_steps_before_ssn_step
end
Copy link
Contributor Author

@mitchellhenke mitchellhenke Aug 12, 2025

Choose a reason for hiding this comment

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

There is a before do block in the context 'phone vendor outage' below which repeated these steps. This meant the test was partially running through idv before doing it again. I've pulled this outer before block into a new context to avoid this duplication.

@mitchellhenke mitchellhenke merged commit 15b202b into main Aug 12, 2025
1 check passed
@mitchellhenke mitchellhenke deleted the mitchellhenke/add-capybara-rubocops branch August 12, 2025 21:11
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