Sha256: 10fe862f3c2099ccee8f4ea4c6470758ecce74a685bbba796d387b93b5e83e86

Contents?: true

Size: 977 Bytes

Versions: 17

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true

module Capybara
  module Queries
    class SiblingQuery < SelectorQuery
      # @api private
      def resolve_for(node, exact = nil)
        @sibling_node = node
        node.synchronize do
          scope = node.respond_to?(:session) ? node.session.current_scope : node.find(:xpath, '/*')
          match_results = super(scope, exact)
          siblings = node.find_xpath((XPath.preceding_sibling + XPath.following_sibling).to_s)
                         .map(&method(:to_element))
                         .select { |el| match_results.include?(el) }
          Capybara::Result.new(ordered_results(siblings), self)
        end
      end

      def description(applied = false) # rubocop:disable Style/OptionalBooleanParameter
        desc = super
        sibling_query = @sibling_node&.instance_variable_get(:@query)
        desc += " that is a sibling of #{sibling_query.description}" if sibling_query
        desc
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 5 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/capybara-3.40.0/lib/capybara/queries/sibling_query.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/capybara-3.40.0/lib/capybara/queries/sibling_query.rb
capybara-3.40.0 lib/capybara/queries/sibling_query.rb
capybara-3.39.2 lib/capybara/queries/sibling_query.rb
capybara-3.39.1 lib/capybara/queries/sibling_query.rb
capybara-3.39.0 lib/capybara/queries/sibling_query.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/queries/sibling_query.rb
capybara-3.38.0 lib/capybara/queries/sibling_query.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/queries/sibling_query.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/queries/sibling_query.rb
capybara-3.37.1 lib/capybara/queries/sibling_query.rb
capybara-3.37.0 lib/capybara/queries/sibling_query.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/queries/sibling_query.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/capybara-3.36.0/lib/capybara/queries/sibling_query.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/queries/sibling_query.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/queries/sibling_query.rb
capybara-3.36.0 lib/capybara/queries/sibling_query.rb