Skip to content

Commit

Permalink
Use Capybara waiting for URL tests
Browse files Browse the repository at this point in the history
Hopefully this fixes that nasty flaky failure for good!
  • Loading branch information
shepmaster committed Sep 6, 2023
1 parent 55af984 commit 3b0f461
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/spec/support/matchers/be_at_url.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand Down

0 comments on commit 3b0f461

Please sign in to comment.