class Capybara::Selector

Attributes

custom_filters[R]
format[R]
name[R]

Public Class Methods

add(name, &block) click to toggle source
# File lib/capybara/selector.rb, line 14
def add(name, &block)
  all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block)
end
all() click to toggle source
# File lib/capybara/selector.rb, line 10
def all
  @selectors ||= {}
end
new(name, &block) click to toggle source
# File lib/capybara/selector.rb, line 27
def initialize(name, &block)
  @name = name
  @custom_filters = {}
  @match = nil
  @label = nil
  @failure_message = nil
  @description = nil
  @format = nil
  @expression = nil
  instance_eval(&block)
end
remove(name) click to toggle source
# File lib/capybara/selector.rb, line 22
def remove(name)
  all.delete(name.to_sym)
end
update(name, &block) click to toggle source
# File lib/capybara/selector.rb, line 18
def update(name, &block)
  all[name.to_sym].instance_eval(&block)
end

Public Instance Methods

call(locator) click to toggle source
# File lib/capybara/selector.rb, line 63
def call(locator)
  if format
    @expression.call(locator)
  else
    warn "Selector has no format"
  end
end
css(&block) click to toggle source
# File lib/capybara/selector.rb, line 44
def css(&block)
  @format, @expression = :css, block if block
  format == :css ? @expression : nil
end
describe(&block) click to toggle source
# File lib/capybara/selector.rb, line 79
def describe &block
  @description = block
end
description(options={}) click to toggle source
# File lib/capybara/selector.rb, line 59
def description(options={})
  (@description && @description.call(options)).to_s
end
filter(name, options={}, &block) click to toggle source
# File lib/capybara/selector.rb, line 75
def filter(name, options={}, &block)
  @custom_filters[name] = Filter.new(name, block, options)
end
label(label=nil) click to toggle source
# File lib/capybara/selector.rb, line 54
def label(label=nil)
  @label = label if label
  @label
end
match(&block) click to toggle source
# File lib/capybara/selector.rb, line 49
def match(&block)
  @match = block if block
  @match
end
match?(locator) click to toggle source
# File lib/capybara/selector.rb, line 71
def match?(locator)
  @match and @match.call(locator)
end
xpath(&block) click to toggle source
# File lib/capybara/selector.rb, line 39
def xpath(&block)
  @format, @expression = :xpath, block if block
  format == :xpath ? @expression : nil
end

Private Instance Methods

locate_field(xpath, locator) click to toggle source
# File lib/capybara/selector.rb, line 85
def locate_field(xpath, locator)
  locate_field = xpath[XPath.attr(:id).equals(locator) |
                       XPath.attr(:name).equals(locator) |
                       XPath.attr(:placeholder).equals(locator) |
                       XPath.attr(:id).equals(XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for))]
  locate_field += XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(xpath)
  locate_field
end