Sha256: aa82f810c047f6f38b4cb5ce80eabe46fb913e73cbb6e21b1e4d1cf90066bcbc

Contents?: true

Size: 1.34 KB

Versions: 30

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'addressable/uri'

module Capybara
  # @api private
  module Queries
    class CurrentPathQuery < BaseQuery
      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

      def resolves_for?(session)
        uri = ::Addressable::URI.parse(session.current_url)
        uri&.query = nil if 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

      def failure_message
        failure_message_helper
      end

      def negative_failure_message
        failure_message_helper(' not')
      end

    private

      def failure_message_helper(negated = '')
        verb = @expected_path.is_a?(Regexp) ? 'match' : 'equal'
        "expected #{@actual_path.inspect}#{negated} to #{verb} #{@expected_path.inspect}"
      end

      def valid_keys
        %i[wait url ignore_query]
      end
    end
  end
end

Version data entries

30 entries across 27 versions & 3 rubygems

Version Path
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/capybara-3.33.0/lib/capybara/queries/current_path_query.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/capybara-3.32.2/lib/capybara/queries/current_path_query.rb
capybara-3.33.0 lib/capybara/queries/current_path_query.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/capybara-3.32.2/lib/capybara/queries/current_path_query.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/capybara-3.29.0/lib/capybara/queries/current_path_query.rb
capybara-3.32.2 lib/capybara/queries/current_path_query.rb
capybara-3.32.1 lib/capybara/queries/current_path_query.rb
capybara-3.32.0 lib/capybara/queries/current_path_query.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/capybara-3.29.0/lib/capybara/queries/current_path_query.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/capybara-3.31.0/lib/capybara/queries/current_path_query.rb
capybara-3.31.0 lib/capybara/queries/current_path_query.rb
capybara-3.30.0 lib/capybara/queries/current_path_query.rb
tdiary-5.1.0 vendor/bundle/gems/capybara-3.29.0/lib/capybara/queries/current_path_query.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/capybara-3.29.0/lib/capybara/queries/current_path_query.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/capybara-3.29.0/lib/capybara/queries/current_path_query.rb
capybara-3.29.0 lib/capybara/queries/current_path_query.rb
capybara-3.28.0 lib/capybara/queries/current_path_query.rb
capybara-3.27.0 lib/capybara/queries/current_path_query.rb
capybara-3.26.0 lib/capybara/queries/current_path_query.rb
capybara-3.25.0 lib/capybara/queries/current_path_query.rb