Parent

Capybara::Query

Constants

VALID_KEYS

Attributes

find[RW]
locator[RW]
negative[RW]
options[RW]
selector[RW]
xpath[RW]

Public Class Methods

new(*args) click to toggle source
# File lib/capybara/query.rb, line 7
def initialize(*args)
  @options = if args.last.is_a?(Hash) then args.pop.dup else {} end

  unless options.has_key?(:visible)
    @options[:visible] = Capybara.ignore_hidden_elements
  end

  if args[0].is_a?(Symbol)
    @selector = Selector.all[args[0]]
    @locator = args[1]
  else
    @selector = Selector.all.values.find { |s| s.match?(args[0]) }
    @locator = args[0]
  end
  @selector ||= Selector.all[Capybara.default_selector]

  @xpath = @selector.call(@locator).to_s

  assert_valid_keys!
end

Public Instance Methods

description() click to toggle source
# File lib/capybara/query.rb, line 31
def description
  @description = "#{label} #{locator.inspect}"
  @description << " with text #{options[:text].inspect}" if options[:text]
  @description
end
label() click to toggle source
# File lib/capybara/query.rb, line 29
def label; selector.label or selector.name; end
matches_count?(count) click to toggle source
# File lib/capybara/query.rb, line 51
def matches_count?(count)
  case
  when options[:between]
    options[:between] === count
  when options[:count]
    options[:count].to_i == count
  when options[:maximum]
    options[:maximum].to_i >= count
  when options[:minimum]
    options[:minimum].to_i <= count
  else
    count > 0
  end
end
matches_filters?(node) click to toggle source
# File lib/capybara/query.rb, line 37
def matches_filters?(node)
  node.unsynchronized do
    if options[:text]
      regexp = options[:text].is_a?(Regexp) ? options[:text] : Regexp.escape(options[:text])
      return false if not node.text.match(regexp)
    end
    return false if options[:visible] and not node.visible?
    selector.custom_filters.each do |name, block|
      return false if options.has_key?(name) and not block.call(node, options[name])
    end
    true
  end
end
name() click to toggle source
# File lib/capybara/query.rb, line 28
def name; selector.name; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.