Class: Capybara::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/selector.rb

Defined Under Namespace

Classes: Filter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Selector

Returns a new instance of Selector.



43
44
45
46
47
48
49
50
51
# File 'lib/capybara/selector.rb', line 43

def initialize(name, &block)
  @name = name
  @custom_filters = {}
  @match = nil
  @label = nil
  @failure_message = nil
  @description = nil
  instance_eval(&block)
end

Instance Attribute Details

#custom_filtersObject (readonly)

Returns the value of attribute custom_filters.



27
28
29
# File 'lib/capybara/selector.rb', line 27

def custom_filters
  @custom_filters
end

#formatObject (readonly)

Returns the value of attribute format.



27
28
29
# File 'lib/capybara/selector.rb', line 27

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/capybara/selector.rb', line 27

def name
  @name
end

Class Method Details

.add(name, &block) ⇒ Object



34
35
36
# File 'lib/capybara/selector.rb', line 34

def add(name, &block)
  all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block)
end

.allObject



30
31
32
# File 'lib/capybara/selector.rb', line 30

def all
  @selectors ||= {}
end

.remove(name) ⇒ Object



38
39
40
# File 'lib/capybara/selector.rb', line 38

def remove(name)
  all.delete(name.to_sym)
end

Instance Method Details

#call(locator) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/capybara/selector.rb', line 80

def call(locator)
  if @format==:css
    @css.call(locator)
  else
    @xpath.call(locator)
  end
end

#css(&block) ⇒ Object

Same as xpath, but wrap in XPath.css().



60
61
62
63
64
# File 'lib/capybara/selector.rb', line 60

def css(&block)
  @format = :css
  @css = block if block
  @css
end

#describe(&block) ⇒ Object



96
97
98
# File 'lib/capybara/selector.rb', line 96

def describe &block
  @description = block
end

#description(options = {}) ⇒ Object



76
77
78
# File 'lib/capybara/selector.rb', line 76

def description(options={})
  (@description && @description.call(options)).to_s
end

#filter(name, options = {}, &block) ⇒ Object



92
93
94
# File 'lib/capybara/selector.rb', line 92

def filter(name, options={}, &block)
  @custom_filters[name] = Filter.new(name, block, options)
end

#label(label = nil) ⇒ Object



71
72
73
74
# File 'lib/capybara/selector.rb', line 71

def label(label=nil)
  @label = label if label
  @label
end

#match(&block) ⇒ Object



66
67
68
69
# File 'lib/capybara/selector.rb', line 66

def match(&block)
  @match = block if block
  @match
end

#match?(locator) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/capybara/selector.rb', line 88

def match?(locator)
  @match and @match.call(locator)
end

#xpath(&block) ⇒ Object



53
54
55
56
57
# File 'lib/capybara/selector.rb', line 53

def xpath(&block)
  @format = :xpath
  @xpath = block if block
  @xpath
end