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|