add custom filter block for matches selector methods
This commit is contained in:
parent
b5655e9b9b
commit
6da4fb2de7
|
@ -454,8 +454,8 @@ module Capybara
|
|||
# @param (see Capybara::Node::Finders#all)
|
||||
# @raise [Capybara::ExpectationNotMet] If the selector does not match
|
||||
#
|
||||
def assert_matches_selector(*args)
|
||||
query = Capybara::Queries::MatchQuery.new(*args)
|
||||
def assert_matches_selector(*args, &optional_filter_block)
|
||||
query = Capybara::Queries::MatchQuery.new(*args, &optional_filter_block)
|
||||
synchronize(query.wait) do
|
||||
result = query.resolve_for(self.query_scope)
|
||||
unless result.include? self
|
||||
|
@ -465,7 +465,7 @@ module Capybara
|
|||
return true
|
||||
end
|
||||
|
||||
def assert_not_matches_selector(*args)
|
||||
def assert_not_matches_selector(*args, &optional_filter_block)
|
||||
query = Capybara::Queries::MatchQuery.new(*args)
|
||||
synchronize(query.wait) do
|
||||
result = query.resolve_for(self.query_scope)
|
||||
|
@ -484,8 +484,8 @@ module Capybara
|
|||
# @param (see Capybara::Node::Finders#has_selector?)
|
||||
# @return [Boolean]
|
||||
#
|
||||
def matches_selector?(*args)
|
||||
assert_matches_selector(*args)
|
||||
def matches_selector?(*args, &optional_filter_block)
|
||||
assert_matches_selector(*args, &optional_filter_block)
|
||||
rescue Capybara::ExpectationNotMet
|
||||
return false
|
||||
end
|
||||
|
@ -497,8 +497,8 @@ module Capybara
|
|||
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
||||
# @return [Boolean]
|
||||
#
|
||||
def matches_xpath?(xpath, options={})
|
||||
matches_selector?(:xpath, xpath, options)
|
||||
def matches_xpath?(xpath, options={}, &optional_filter_block)
|
||||
matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -508,7 +508,7 @@ module Capybara
|
|||
# @param [String] css The CSS selector to match against the current code
|
||||
# @return [Boolean]
|
||||
#
|
||||
def matches_css?(css, options={})
|
||||
def matches_css?(css, options={}, &optional_filter_block)
|
||||
matches_selector?(:css, css, options)
|
||||
end
|
||||
|
||||
|
@ -520,8 +520,8 @@ module Capybara
|
|||
# @param (see Capybara::Node::Finders#has_selector?)
|
||||
# @return [Boolean]
|
||||
#
|
||||
def not_matches_selector?(*args)
|
||||
assert_not_matches_selector(*args)
|
||||
def not_matches_selector?(*args, &optional_filter_block)
|
||||
assert_not_matches_selector(*args, &optional_filter_block)
|
||||
rescue Capybara::ExpectationNotMet
|
||||
return false
|
||||
end
|
||||
|
@ -533,8 +533,8 @@ module Capybara
|
|||
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
||||
# @return [Boolean]
|
||||
#
|
||||
def not_matches_xpath?(xpath, options={})
|
||||
not_matches_selector?(:xpath, xpath, options)
|
||||
def not_matches_xpath?(xpath, options={}, &optional_filter_block)
|
||||
not_matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -544,8 +544,8 @@ module Capybara
|
|||
# @param [String] css The CSS selector to match against the current code
|
||||
# @return [Boolean]
|
||||
#
|
||||
def not_matches_css?(css, options={})
|
||||
not_matches_selector?(:css, css, options)
|
||||
def not_matches_css?(css, options={}, &optional_filter_block)
|
||||
not_matches_selector?(:css, css, options, &optional_filter_block)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -48,6 +48,13 @@ Capybara::SpecHelper.spec '#match_selector?' do
|
|||
cbox = @session.find(:css, '#form_pets_dog')
|
||||
expect(cbox.matches_selector?(:checkbox, id: 'form_pets_dog', option: 'dog', name: 'form[pets][]', checked: true)).to be true
|
||||
end
|
||||
|
||||
it 'should accept a custom filter block' do
|
||||
@session.visit('/form')
|
||||
cbox = @session.find(:css, '#form_pets_dog')
|
||||
expect(cbox.matches_selector?(:checkbox){ |node| node[:id] == "form_pets_dog"}).to be true
|
||||
expect(cbox.matches_selector?(:checkbox){ |node| node[:id] != "form_pets_dog"}).to be false
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::SpecHelper.spec '#not_matches_selector?' do
|
||||
|
|
Loading…
Reference in New Issue