Class: Capybara::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/selector.rb,
lib/capybara/selector/filter.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.



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_filtersObject (readonly)

Returns the value of attribute custom_filters.



7
8
9
# File 'lib/capybara/selector.rb', line 7

def custom_filters
  @custom_filters
end

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/capybara/selector.rb', line 7

def format
  @format
end

#nameObject (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

.allObject



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(options={})
  (@description && @description.call(options)).to_s
end

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



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

def filter(name, options={}, &block)
  @custom_filters[name] = Filter.new(name, block, options)
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

Returns:

  • (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