teamcapybara--capybara/lib/capybara/queries/ancestor_query.rb

30 lines
729 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-01-08 20:23:54 +00:00
module Capybara
module Queries
class AncestorQuery < Capybara::Queries::SelectorQuery
# @api private
def resolve_for(node, exact = nil)
@child_node = node
node.synchronize do
match_results = super(node.session.current_scope, exact)
2018-01-13 21:06:03 +00:00
node.all(:xpath, XPath.ancestor) { |el| match_results.include?(el) }
end
end
def description
2018-01-13 21:06:03 +00:00
child_query = @child_node && @child_node.instance_variable_get(:@query)
desc = super
2018-01-13 21:06:03 +00:00
desc += " that is an ancestor of #{child_query.description}" if child_query
desc
end
private
def valid_keys
super - COUNT_KEYS
end
end
end
end