Sha256: 14ab733957271560ea2715ba95ede332016c9af3281a88db891798111960f546

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true
require 'addressable/uri'

module Capybara
  # @api private
  module Queries
    class CurrentPathQuery < BaseQuery
      def initialize(expected_path, options = {})
        @expected_path = expected_path
        @options = {
          url: false,
          only_path: false }.merge(options)
        assert_valid_keys
      end

      def resolves_for?(session)
        @actual_path = if options[:url]
          session.current_url
        else
          if options[:only_path]
            ::Addressable::URI.parse(session.current_url).path
          else
            ::Addressable::URI.parse(session.current_url).request_uri
          end
        end

        if @expected_path.is_a? Regexp
          @actual_path.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
        [:wait, :url, :only_path]
      end

      def assert_valid_keys
        super
        if options[:url] && options[:only_path]
          raise ArgumentError, "the :url and :only_path options cannot both be true"
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
capybara-2.11.0 lib/capybara/queries/current_path_query.rb
capybara-2.10.2 lib/capybara/queries/current_path_query.rb
capybara-2.10.1 lib/capybara/queries/current_path_query.rb
capybara-2.10.0 lib/capybara/queries/current_path_query.rb
capybara-2.9.2 lib/capybara/queries/current_path_query.rb
tdiary-5.0.2 vendor/bundle/gems/capybara-2.8.0/lib/capybara/queries/current_path_query.rb
capybara-2.9.1 lib/capybara/queries/current_path_query.rb
capybara-2.9.0 lib/capybara/queries/current_path_query.rb
capybara-2.8.1 lib/capybara/queries/current_path_query.rb
capybara-2.8.0 lib/capybara/queries/current_path_query.rb
tdiary-5.0.1 vendor/bundle/gems/capybara-2.7.1/lib/capybara/queries/current_path_query.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/capybara-2.7.1/lib/capybara/queries/current_path_query.rb
capybara-2.7.1 lib/capybara/queries/current_path_query.rb
capybara-2.7.0 lib/capybara/queries/current_path_query.rb