class Capybara::Queries::CurrentPathQuery

Public Class Methods

new(expected_path, **options) click to toggle source
Calls superclass method Capybara::Queries::BaseQuery.new
# File lib/capybara/queries/current_path_query.rb, line 8
def initialize(expected_path, **options)
  super(options)
  @expected_path = expected_path
  @options = {
    url: !@expected_path.is_a?(Regexp) && !::Addressable::URI.parse(@expected_path || '').hostname.nil?,
    ignore_query: false
  }.merge(options)
  assert_valid_keys
end

Public Instance Methods

failure_message() click to toggle source
# File lib/capybara/queries/current_path_query.rb, line 30
def failure_message
  failure_message_helper
end
negative_failure_message() click to toggle source
# File lib/capybara/queries/current_path_query.rb, line 34
def negative_failure_message
  failure_message_helper(' not')
end
resolves_for?(session) click to toggle source
# File lib/capybara/queries/current_path_query.rb, line 18
def resolves_for?(session)
  uri = ::Addressable::URI.parse(session.current_url)
  uri.query = nil if uri && options[:ignore_query]
  @actual_path = options[:url] ? uri.to_s : uri&.request_uri

  if @expected_path.is_a? Regexp
    @actual_path.to_s.match(@expected_path)
  else
    ::Addressable::URI.parse(@expected_path) == ::Addressable::URI.parse(@actual_path)
  end
end

Private Instance Methods

failure_message_helper(negated = '') click to toggle source
# File lib/capybara/queries/current_path_query.rb, line 40
def failure_message_helper(negated = '')
  verb = @expected_path.is_a?(Regexp) ? 'match' : 'equal'
  "expected #{@actual_path.inspect}#{negated} to #{verb} #{@expected_path.inspect}"
end
valid_keys() click to toggle source
# File lib/capybara/queries/current_path_query.rb, line 45
def valid_keys
  %i[wait url ignore_query]
end