Class: Capybara::Selector::Filters::NodeFilter

Inherits:
Base
  • Object
show all
Defined in:
lib/capybara/selector/filters/node_filter.rb

Direct Known Subclasses

LocatorFilter

Instance Method Summary collapse

Methods inherited from Base

#boolean?, #default, #default?, #format, #handles_option?, #matcher?, #skip?

Constructor Details

#initialize(name, matcher, block, **options) ⇒ NodeFilter

Returns a new instance of NodeFilter.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/capybara/selector/filters/node_filter.rb', line 9

def initialize(name, matcher, block, **options)
  super
  @block = if boolean?
    proc do |node, value|
      error_cnt = errors.size
      block.call(node, value).tap do |res|
        add_error("Expected #{name} #{value} but it wasn't") if !res && error_cnt == errors.size
      end
    end
  else
    block
  end
end

Instance Method Details

#matches?(node, name, value, context = nil) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/capybara/selector/filters/node_filter.rb', line 23

def matches?(node, name, value, context = nil)
  apply(node, name, value, true, context)
rescue Capybara::ElementNotFound
  false
end