Class: Capybara::Selector
- Inherits:
-
Object
- Object
- Capybara::Selector
- Defined in:
- lib/capybara/selector.rb
Defined Under Namespace
Classes: Filter
Instance Attribute Summary collapse
-
#custom_filters ⇒ Object
readonly
Returns the value of attribute custom_filters.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #call(locator) ⇒ Object
-
#css(&block) ⇒ Object
Same as xpath, but wrap in XPath.css().
- #describe(&block) ⇒ Object
- #description(options = {}) ⇒ Object
- #filter(name, options = {}, &block) ⇒ Object
-
#initialize(name, &block) ⇒ Selector
constructor
A new instance of Selector.
- #label(label = nil) ⇒ Object
- #match(&block) ⇒ Object
- #match?(locator) ⇒ Boolean
- #xpath(&block) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Selector
Returns a new instance of Selector.
61 62 63 64 65 66 67 68 69 |
# File 'lib/capybara/selector.rb', line 61 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_filters ⇒ Object (readonly)
Returns the value of attribute custom_filters.
41 42 43 |
# File 'lib/capybara/selector.rb', line 41 def custom_filters @custom_filters end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
41 42 43 |
# File 'lib/capybara/selector.rb', line 41 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
41 42 43 |
# File 'lib/capybara/selector.rb', line 41 def name @name end |
Class Method Details
.add(name, &block) ⇒ Object
48 49 50 |
# File 'lib/capybara/selector.rb', line 48 def add(name, &block) all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block) end |
.all ⇒ Object
44 45 46 |
# File 'lib/capybara/selector.rb', line 44 def all @selectors ||= {} end |
.remove(name) ⇒ Object
56 57 58 |
# File 'lib/capybara/selector.rb', line 56 def remove(name) all.delete(name.to_sym) end |
.update(name, &block) ⇒ Object
52 53 54 |
# File 'lib/capybara/selector.rb', line 52 def update(name, &block) all[name.to_sym].instance_eval(&block) end |
Instance Method Details
#call(locator) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/capybara/selector.rb', line 102 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().
80 81 82 83 84 85 86 |
# File 'lib/capybara/selector.rb', line 80 def css(&block) if block @format = :css @css, @xpath = block, nil end @css end |
#describe(&block) ⇒ Object
118 119 120 |
# File 'lib/capybara/selector.rb', line 118 def describe &block @description = block end |
#description(options = {}) ⇒ Object
98 99 100 |
# File 'lib/capybara/selector.rb', line 98 def description(={}) (@description && @description.call()).to_s end |
#filter(name, options = {}, &block) ⇒ Object
114 115 116 |
# File 'lib/capybara/selector.rb', line 114 def filter(name, ={}, &block) @custom_filters[name] = Filter.new(name, block, ) end |
#label(label = nil) ⇒ Object
93 94 95 96 |
# File 'lib/capybara/selector.rb', line 93 def label(label=nil) @label = label if label @label end |
#match(&block) ⇒ Object
88 89 90 91 |
# File 'lib/capybara/selector.rb', line 88 def match(&block) @match = block if block @match end |
#match?(locator) ⇒ Boolean
110 111 112 |
# File 'lib/capybara/selector.rb', line 110 def match?(locator) @match and @match.call(locator) end |
#xpath(&block) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/capybara/selector.rb', line 71 def xpath(&block) if block @format = :xpath @xpath, @css = block, nil end @xpath end |