Class: Capybara::Selector
- Inherits:
-
Object
- Object
- Capybara::Selector
- Defined in:
- lib/capybara/selector.rb,
lib/capybara/selector/filter.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
- #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.
27 28 29 30 31 32 33 34 35 36 37 |
# 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 |
Instance Attribute Details
#custom_filters ⇒ Object (readonly)
Returns the value of attribute custom_filters.
7 8 9 |
# File 'lib/capybara/selector.rb', line 7 def custom_filters @custom_filters end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/capybara/selector.rb', line 7 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/capybara/selector.rb', line 7 def name @name end |
Class Method Details
.add(name, &block) ⇒ Object
14 15 16 |
# File 'lib/capybara/selector.rb', line 14 def add(name, &block) all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block) end |
.all ⇒ Object
10 11 12 |
# File 'lib/capybara/selector.rb', line 10 def all @selectors ||= {} end |
.remove(name) ⇒ Object
22 23 24 |
# File 'lib/capybara/selector.rb', line 22 def remove(name) all.delete(name.to_sym) end |
.update(name, &block) ⇒ Object
18 19 20 |
# File 'lib/capybara/selector.rb', line 18 def update(name, &block) all[name.to_sym].instance_eval(&block) end |
Instance Method Details
#call(locator) ⇒ Object
63 64 65 66 67 68 69 |
# 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) ⇒ Object
44 45 46 47 |
# File 'lib/capybara/selector.rb', line 44 def css(&block) @format, @expression = :css, block if block format == :css ? @expression : nil end |
#describe(&block) ⇒ Object
79 80 81 |
# File 'lib/capybara/selector.rb', line 79 def describe &block @description = block end |
#description(options = {}) ⇒ Object
59 60 61 |
# File 'lib/capybara/selector.rb', line 59 def description(={}) (@description && @description.call()).to_s end |
#filter(name, options = {}, &block) ⇒ Object
75 76 77 |
# File 'lib/capybara/selector.rb', line 75 def filter(name, ={}, &block) @custom_filters[name] = Filter.new(name, block, ) end |
#label(label = nil) ⇒ Object
54 55 56 57 |
# File 'lib/capybara/selector.rb', line 54 def label(label=nil) @label = label if label @label end |
#match(&block) ⇒ Object
49 50 51 52 |
# File 'lib/capybara/selector.rb', line 49 def match(&block) @match = block if block @match end |
#match?(locator) ⇒ Boolean
71 72 73 |
# File 'lib/capybara/selector.rb', line 71 def match?(locator) @match and @match.call(locator) end |
#xpath(&block) ⇒ Object
39 40 41 42 |
# File 'lib/capybara/selector.rb', line 39 def xpath(&block) @format, @expression = :xpath, block if block format == :xpath ? @expression : nil end |