Fix flaky spec "Edit poll allows removing answers"

The test was hanging sometimes on my machine, probably because we
weren't making sure the request submitting the form had finished before
visiting a new page.

In theory the spec should have been fine from a technical point of view:
since submitting the form generates a regular HTTP request (and not an
AJAX one), Capybara/Selenium/Chromedrive should wait until the request
is finished. But that doesn't seem to be the case 100% of the time;
maybe conditions change depending on previous tests.

On the other hand, from a design point of view, the spec wasn't that
fine. The main purpose of system specs is to test the way users interact
with our application, and users don't click a button and immediately
visit a different page. Instead, most users wait until they receive
feedback of their actions, and then they visit a different page.

Of course some users might visit another page without waiting. What
happens then cannot be predicted (it will depend on which request is
handled first), and so there's no point in writing a test for this case
unless there's a specific concurrency issue we'd like to check.
This commit is contained in:
Javi Martín
2021-04-03 14:42:29 +02:00
parent 08e19153d4
commit 171a40d25d

View File

@@ -165,7 +165,7 @@ describe "Polls" do
expect(page).to have_css ".nested-fields", count: 1
end
scenario "Edit poll should allow to remove answers" do
scenario "Edit poll allows users to remove answers" do
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
create(:poll_question, :yes_no, poll: poll)
visit proposal_dashboard_polls_path(proposal)
@@ -182,6 +182,9 @@ describe "Polls" do
end
click_button "Update poll"
expect(page).to have_content "Poll updated successfully"
visit edit_proposal_dashboard_poll_path(proposal, poll)
within ".js-questions .js-answers" do