From 059fd430ba70157bb0f9cd7022952590ec13708e Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Thu, 12 Apr 2018 10:20:06 -0700 Subject: [PATCH] Fix compounding of negated matechers - Issue #2010 --- lib/capybara/rspec/matchers.rb | 5 +++++ spec/rspec/shared_spec_matchers.rb | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index f40ad530..4ff83fa7 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -199,6 +199,11 @@ module Capybara end class NegatedMatcher + if defined?(::RSpec::Expectations::Version) + require 'capybara/rspec/compound' + include ::Capybara::RSpecMatchers::Compound + end + def initialize(matcher) @matcher = matcher end diff --git a/spec/rspec/shared_spec_matchers.rb b/spec/rspec/shared_spec_matchers.rb index 8f872af2..29f2ef99 100644 --- a/spec/rspec/shared_spec_matchers.rb +++ b/spec/rspec/shared_spec_matchers.rb @@ -80,6 +80,8 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode| it "supports compounding" do expect("

Text

Text

").to have_css('h1').and have_css('h2') expect("

Text

Text

").to have_css('h3').or have_css('h1') + expect("

Text

Text

").to have_no_css('h4').and have_css('h2') + expect("

Text

Text

").to have_no_css('h2').or have_css('h1') end end @@ -147,6 +149,8 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode| it "supports compounding" do expect("

Text

Text

").to have_xpath('//h1').and have_xpath('//h2') expect("

Text

Text

").to have_xpath('//h3').or have_xpath('//h1') + expect("

Text

Text

").to have_no_xpath('//h4').and have_xpath('//h1') + expect("

Text

Text

").to have_no_xpath('//h4').or have_xpath('//h4') end end @@ -253,6 +257,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode| it "supports compounding" do expect("

Text

Text

").to have_selector('//h1').and have_selector('//h2') expect("

Text

Text

").to have_selector('//h3').or have_selector('//h1') + expect("

Text

Text

").to have_no_selector('//h3').and have_selector('//h1') end end @@ -342,6 +347,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode| it "supports compounding" do expect("

Text

And

").to have_content('Text').and have_content('And') expect("

Text

Or

").to have_content('XYZ').or have_content('Or') + expect("

Text

Or

").to have_no_content('XYZ').and have_content('Or') end end @@ -499,6 +505,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode| it "supports compounding" do 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_no_link('Not a link').and have_link('Another link') end end