From 3b0f4616e31a959c241be6fb602a5aaa4500edb3 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 6 Sep 2023 13:27:54 -0400 Subject: [PATCH] Use Capybara waiting for URL tests Hopefully this fixes that nasty flaky failure for good! --- tests/spec/support/matchers/be_at_url.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/spec/support/matchers/be_at_url.rb b/tests/spec/support/matchers/be_at_url.rb index 79636e668..2d08fca6a 100644 --- a/tests/spec/support/matchers/be_at_url.rb +++ b/tests/spec/support/matchers/be_at_url.rb @@ -1,11 +1,19 @@ +class NotAtUrlError < StandardError; end + RSpec::Matchers.define :be_at_url do |path, query = {}| match do |page| - uri = URI::parse(page.current_url) - expect(uri.path).to eql(path) + page.document.synchronize(nil, errors: [NotAtUrlError] ) do + uri = URI::parse(page.current_url) + raise NotAtUrlError unless uri.path == path + + query = query.map { |k, v| [k.to_s, Array(v).map(&:to_s)] }.to_h + query_hash = CGI::parse(uri.query || '') + raise NotAtUrlError unless query <= query_hash - query = query.map { |k, v| [k.to_s, Array(v).map(&:to_s)] }.to_h - query_hash = CGI::parse(uri.query || '') - expect(query_hash).to include(query) + true + end + rescue NotAtUrlError + false end failure_message do |page|