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



62
63
64
65
66
67
68
69
70
# File 'lib/capybara/selector.rb', line 62

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



42
43
44
# File 'lib/capybara/selector.rb', line 42

def custom_filters
  @custom_filters
end

#formatObject (readonly)

Returns the value of attribute format



42
43
44
# File 'lib/capybara/selector.rb', line 42

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name



42
43
44
# File 'lib/capybara/selector.rb', line 42

def name
  @name
end

Class Method Details

.add(name, &block) ⇒ Object



49
50
51
# File 'lib/capybara/selector.rb', line 49

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

.allObject



45
46
47
# File 'lib/capybara/selector.rb', line 45

def all
  @selectors ||= {}
end

.remove(name) ⇒ Object



57
58
59
# File 'lib/capybara/selector.rb', line 57

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

.update(name, &block) ⇒ Object



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

def update(name, &block)
  all[name.to_sym].instance_eval(&block)
end

Instance Method Details

#call(locator) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/capybara/selector.rb', line 103

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().



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

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

#describe(&block) ⇒ Object



119
120
121
# File 'lib/capybara/selector.rb', line 119

def describe &block
  @description = block
end

#description(options = {}) ⇒ Object



99
100
101
# File 'lib/capybara/selector.rb', line 99

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

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



115
116
117
# File 'lib/capybara/selector.rb', line 115

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

#label(label = nil) ⇒ Object



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

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

#match(&block) ⇒ Object



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

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

#match?(locator) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/capybara/selector.rb', line 111

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

#xpath(&block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/capybara/selector.rb', line 72

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