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

- (Selector) initialize(name, &block)



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

- (Object) custom_filters (readonly)

Returns the value of attribute custom_filters



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

def custom_filters
  @custom_filters
end

- (Object) format (readonly)

Returns the value of attribute format



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

def format
  @format
end

- (Object) name (readonly)

Returns the value of attribute name



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

def name
  @name
end

Class Method Details

+ (Object) add(name, &block)



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

+ (Object) all



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

def all
  @selectors ||= {}
end

+ (Object) remove(name)



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

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

Instance Method Details

- (Object) call(locator)



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

- (Object) css(&block)

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

- (Object) describe(&block)



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

def describe &block
  @description = block
end

- (Object) description(options = {})



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

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

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



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

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

- (Object) label(label = nil)



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

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

- (Object) match(&block)



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

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

- (Boolean) match?(locator)



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

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

- (Object) xpath(&block)



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

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