Fix flaky spec: Proposals Voting Voting proposals on behalf of someone in show view #2697
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
References
Objectives
Fix the flaky that appeared in
spec/features/management/proposals_spec.rb:164
: "Proposals Voting Voting proposals on behalf of someone in show view".Explain why the test is flaky, or under which conditions/scenario it fails randomly
It's hard to reproduce and be sure about what was going on, so here is my best guess. Given the code:
The first clicked link generates an AJAX request. Usually, Capybara would wait for the AJAX request to generate a "Support" link in the element
#proposal_XX_votes
. However, there's already a#proposal_XX_votes
element with a "Support" link on the proposals index page!So Capybara doesn't have to wait for the AJAX request to finish before clicking the "Support" link. From then on, anything can happen.
As stated on issue #2558, on my machine the best chance to reproduce the failure was running
bundle exec rspec spec/features/management/proposals_spec.rb --seed 8625
(fails about 20% of the time).Explain why your PR fixes it
By checking the proposal code is present, which is present on the proposals show page but not on the proposals index page, we ensure we've left the proposals index page when we click the "Support" link.
Notes