HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/rubygems-integration/all/gems/capybara-3.36.0/lib/capybara/queries/sibling_query.rb
# 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