From c29b15d5f6ab3f7f9e7363d935a8a929e32cf543 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 12 Feb 2025 15:07:34 +1100 Subject: [PATCH] Wait less for condition This code was waiting up to 20 seconds, but only checking every two seconds, which means it could be wasting up to 2s everytime it runs. Instead, we can use Capybara's waiting mechanism, which by default waits up to 20 seconds (but no doubt is optimised to be much more responsive). --- spec/system/admin/configuration/states_spec.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/spec/system/admin/configuration/states_spec.rb b/spec/system/admin/configuration/states_spec.rb index 9512415f85..f7f58c9edc 100644 --- a/spec/system/admin/configuration/states_spec.rb +++ b/spec/system/admin/configuration/states_spec.rb @@ -16,17 +16,11 @@ RSpec.describe "States" do allow(ENV).to receive(:[]).with("DEFAULT_COUNTRY_CODE").and_return("HU") end - # TODO: For whatever reason, rendering of the states page takes a non-trivial amount of time - # Therefore we navigate to it, and wait until what we see is visible + # For whatever reason, rendering of the states page takes a non-trivial amount of time. + # Therefore we navigate to it, and wait until what we see is visible. def go_to_states_page visit spree.admin_country_states_path(country) - counter = 0 - until page.has_css?("#new_state_link") - raise "Could not see new state link!" if counter >= 10 - - sleep(2) - counter += 1 - end + expect(page).to have_link "New State" end context "admin visiting states listing" do