2016-03-08 00:52:19 +00:00
|
|
|
# frozen_string_literal: true
|
2018-01-08 20:23:54 +00:00
|
|
|
|
2016-01-27 22:20:47 +00:00
|
|
|
require 'addressable/uri'
|
2016-01-27 18:53:59 +00:00
|
|
|
|
2015-08-24 05:14:48 +00:00
|
|
|
module Capybara
|
|
|
|
# @api private
|
|
|
|
module Queries
|
|
|
|
class CurrentPathQuery < BaseQuery
|
2016-08-17 23:14:39 +00:00
|
|
|
def initialize(expected_path, **options)
|
2017-05-28 15:54:55 +00:00
|
|
|
super(options)
|
2015-08-24 05:14:48 +00:00
|
|
|
@expected_path = expected_path
|
|
|
|
@options = {
|
2017-06-20 22:14:32 +00:00
|
|
|
url: !@expected_path.is_a?(Regexp) && !::Addressable::URI.parse(@expected_path || "").hostname.nil?,
|
2017-10-08 21:56:17 +00:00
|
|
|
ignore_query: false
|
|
|
|
}.merge(options)
|
2015-08-24 05:14:48 +00:00
|
|
|
assert_valid_keys
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolves_for?(session)
|
2017-06-20 22:14:32 +00:00
|
|
|
uri = ::Addressable::URI.parse(session.current_url)
|
|
|
|
uri.query = nil if uri && options[:ignore_query]
|
2018-05-10 20:20:23 +00:00
|
|
|
@actual_path = options[:url] ? uri.to_s : uri&.request_uri
|
2015-08-24 05:14:48 +00:00
|
|
|
|
|
|
|
if @expected_path.is_a? Regexp
|
2017-11-28 06:35:04 +00:00
|
|
|
@actual_path.to_s.match(@expected_path)
|
2015-08-24 05:14:48 +00:00
|
|
|
else
|
2017-01-27 00:10:51 +00:00
|
|
|
::Addressable::URI.parse(@expected_path) == ::Addressable::URI.parse(@actual_path)
|
2015-08-24 05:14:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure_message
|
|
|
|
failure_message_helper
|
|
|
|
end
|
|
|
|
|
|
|
|
def negative_failure_message
|
|
|
|
failure_message_helper(' not')
|
|
|
|
end
|
|
|
|
|
2018-01-09 22:05:50 +00:00
|
|
|
private
|
2015-08-24 05:14:48 +00:00
|
|
|
|
|
|
|
def failure_message_helper(negated = '')
|
2018-01-08 20:23:54 +00:00
|
|
|
verb = @expected_path.is_a?(Regexp) ? 'match' : 'equal'
|
2015-08-24 05:14:48 +00:00
|
|
|
"expected #{@actual_path.inspect}#{negated} to #{verb} #{@expected_path.inspect}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_keys
|
2018-01-08 20:23:54 +00:00
|
|
|
%i[wait url ignore_query]
|
2015-08-24 05:14:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|