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).
This commit is contained in:
David Cook
2025-02-12 15:07:34 +11:00
parent f55cdcdd34
commit c29b15d5f6

View File

@@ -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