lib/capybara/rspec/matchers.rb in capybara-3.21.0 vs lib/capybara/rspec/matchers.rb in capybara-3.22.0
- old
+ new
@@ -1,8 +1,10 @@
# frozen_string_literal: true
require 'capybara/rspec/matchers/have_selector'
+require 'capybara/rspec/matchers/have_ancestor'
+require 'capybara/rspec/matchers/have_sibling'
require 'capybara/rspec/matchers/match_selector'
require 'capybara/rspec/matchers/have_current_path'
require 'capybara/rspec/matchers/match_style'
require 'capybara/rspec/matchers/have_text'
require 'capybara/rspec/matchers/have_title'
@@ -136,20 +138,33 @@
warn 'DEPRECATED: have_style is deprecated, please use match_style'
match_style(styles, **options)
end
%w[selector css xpath text title current_path link button
- field checked_field unchecked_field select table].each do |matcher_type|
+ field checked_field unchecked_field select table
+ sibling ancestor].each do |matcher_type|
define_method "have_no_#{matcher_type}" do |*args, &optional_filter_block|
Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, &optional_filter_block))
end
end
alias_method :have_no_content, :have_no_text
%w[selector css xpath].each do |matcher_type|
define_method "not_match_#{matcher_type}" do |*args, &optional_filter_block|
Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, &optional_filter_block))
end
+ end
+
+ # RSpec matcher for whether sibling element(s) matching a given selector exist
+ # See {Capybara::Node::Matcher#assert_sibling}
+ def have_sibling(*args, &optional_filter_block)
+ Matchers::HaveSibling.new(*args, &optional_filter_block)
+ end
+
+ # RSpec matcher for whether ancestor element(s) matching a given selector exist
+ # See {Capybara::Node::Matcher#assert_ancestor}
+ def have_ancestor(*args, &optional_filter_block)
+ Matchers::HaveAncestor.new(*args, &optional_filter_block)
end
##
# Wait for window to become closed.
# @example