class Capybara::Selector

Attributes

name[R]

Public Class Methods

add(name, &block) click to toggle source
# File lib/capybara/selector.rb, line 17
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 13
def all
  @selectors ||= {}
end
new(name, &block) click to toggle source
# File lib/capybara/selector.rb, line 48
def initialize(name, &block)
  @name = name
  instance_eval(&block)
end
normalize(*args) click to toggle source
# File lib/capybara/selector.rb, line 25
def normalize(*args)
  normalized = Normalized.new
  normalized.options = if args.last.is_a?(Hash) then args.pop else {} end

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

  xpath = normalized.selector.call(normalized.locator)
  if xpath.respond_to?(:to_xpaths)
    normalized.xpaths = xpath.to_xpaths
  else
    normalized.xpaths = [xpath.to_s].flatten
  end
  normalized
end
remove(name) click to toggle source
# File lib/capybara/selector.rb, line 21
def remove(name)
  all.delete(name.to_sym)
end

Public Instance Methods

call(locator) click to toggle source
# File lib/capybara/selector.rb, line 68
def call(locator)
  @xpath.call(locator)
end
failure_message(&block) click to toggle source
# File lib/capybara/selector.rb, line 63
def failure_message(&block)
  @failure_message = block if block
  @failure_message
end
match(&block) click to toggle source
# File lib/capybara/selector.rb, line 58
def match(&block)
  @match = block if block
  @match
end
match?(locator) click to toggle source
# File lib/capybara/selector.rb, line 72
def match?(locator)
  @match and @match.call(locator)
end
xpath(&block) click to toggle source
# File lib/capybara/selector.rb, line 53
def xpath(&block)
  @xpath = block if block
  @xpath
end