2018-11-14 19:32:32 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'capybara/selector/filters/base'
|
|
|
|
|
|
|
|
module Capybara
|
|
|
|
class Selector
|
|
|
|
module Filters
|
|
|
|
class LocatorFilter < NodeFilter
|
|
|
|
def initialize(block, **options)
|
2019-11-28 22:41:13 +00:00
|
|
|
super(nil, nil, block, **options)
|
2018-11-14 19:32:32 +00:00
|
|
|
end
|
|
|
|
|
2019-04-23 00:43:02 +00:00
|
|
|
def matches?(node, value, context = nil, exact:)
|
2019-04-23 01:04:15 +00:00
|
|
|
apply(node, value, true, context, exact: exact, format: context&.default_format)
|
2019-04-23 00:43:02 +00:00
|
|
|
rescue Capybara::ElementNotFound
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def apply(subject, value, skip_value, ctx, **options)
|
|
|
|
return skip_value if skip?(value)
|
|
|
|
|
|
|
|
filter_context(ctx).instance_exec(subject, value, **options, &@block)
|
2018-11-14 19:32:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|