From c0a507ba4a3c67238020f5d00148e5590093295c Mon Sep 17 00:00:00 2001 From: Bess Sadler Date: Thu, 28 Mar 2024 18:51:26 -0400 Subject: [PATCH] Ensure flaky test passes consistently (#621) --- spec/rails_helper.rb | 6 ++++++ spec/system/project_roles_spec.rb | 11 ++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2d4ba7a6..c5873101 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -8,6 +8,7 @@ require "rspec/rails" # Add additional requires below this line. Rails is not loaded until this point! require "axe-rspec" +require "capybara/rspec" require "devise" require "webmock/rspec" WebMock.disable_net_connect!(allow_localhost: true, @@ -37,6 +38,11 @@ rescue ActiveRecord::PendingMigrationError => e abort e.to_s.strip end + +# Disable animations in system tests. +# This should make them faster and more reliable. +Capybara.disable_animation = true + RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/spec/system/project_roles_spec.rb b/spec/system/project_roles_spec.rb index 795ac037..f5980337 100644 --- a/spec/system/project_roles_spec.rb +++ b/spec/system/project_roles_spec.rb @@ -63,17 +63,14 @@ click_on "btn-add-rw-user" expect(page.find("#rw-user-uid-to-add").native.attribute("validationMessage")).to eq "" + page.find("#departments").find(:xpath, "option[3]").select_option + fill_in "directory", with: "test_project" fill_in "title", with: "My test project" expect(page).to have_content("Project Directory: /td-test-001/") + expect(page.find_all("input:invalid").count).to eq(0) expect do - expect(page.find_all("input:invalid").count).to eq(0) - click_on "Submit" - # For some reason the above click on submit sometimes does not submit the form - # even though the inputs are all valid, so try it again... - if page.find_all("#btn-add-rw-user").count > 0 - click_on "Submit" - end + click_button("Submit") end.to have_enqueued_job(ActionMailer::MailDeliveryJob).exactly(1).times expect(page).to have_content "New Project Request Received" click_on "Return to Dashboard"