1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Fix compounding of negated matechers - Issue #2010

This commit is contained in:
Thomas Walpole 2018-04-12 10:20:06 -07:00
parent 1bfa369be4
commit 059fd430ba
2 changed files with 12 additions and 0 deletions

View file

@ -199,6 +199,11 @@ module Capybara
end end
class NegatedMatcher class NegatedMatcher
if defined?(::RSpec::Expectations::Version)
require 'capybara/rspec/compound'
include ::Capybara::RSpecMatchers::Compound
end
def initialize(matcher) def initialize(matcher)
@matcher = matcher @matcher = matcher
end end

View file

@ -80,6 +80,8 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
it "supports compounding" do it "supports compounding" do
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2') expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2')
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1') expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1')
expect("<h1>Text</h1><h2>Text</h2>").to have_no_css('h4').and have_css('h2')
expect("<h1>Text</h1><h2>Text</h2>").to have_no_css('h2').or have_css('h1')
end end
end end
@ -147,6 +149,8 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
it "supports compounding" do it "supports compounding" do
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2') expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2')
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1') expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1')
expect("<h1>Text</h1><h2>Text</h2>").to have_no_xpath('//h4').and have_xpath('//h1')
expect("<h1>Text</h1><h2>Text</h2>").to have_no_xpath('//h4').or have_xpath('//h4')
end end
end end
@ -253,6 +257,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
it "supports compounding" do it "supports compounding" do
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2') expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2')
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1') expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1')
expect("<h1>Text</h1><h2>Text</h2>").to have_no_selector('//h3').and have_selector('//h1')
end end
end end
@ -342,6 +347,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
it "supports compounding" do it "supports compounding" do
expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And') expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And')
expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or') expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or')
expect("<h1>Text</h1><h2>Or</h2>").to have_no_content('XYZ').and have_content('Or')
end end
end end
@ -499,6 +505,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
it "supports compounding" do it "supports compounding" do
expect(html).to have_link('Just a link').and have_link('Another link') expect(html).to have_link('Just a link').and have_link('Another link')
expect(html).to have_link('Not a link').or have_link('Another link') expect(html).to have_link('Not a link').or have_link('Another link')
expect(html).to have_no_link('Not a link').and have_link('Another link')
end end
end end