Skip to content

Commit

Permalink
Fix compounding of negated matechers - Issue #2010
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Apr 12, 2018
1 parent 7e0dc29 commit 58d5b74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/capybara/rspec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ def description
end

class NegatedMatcher
if defined?(::RSpec::Expectations::Version)
require 'capybara/rspec/compound'
include ::Capybara::RSpecMatchers::Compound
end

def initialize(matcher)
@matcher = matcher
end
Expand Down
7 changes: 7 additions & 0 deletions spec/rspec/shared_spec_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
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('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

Expand Down Expand Up @@ -147,6 +149,8 @@
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('//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

Expand Down Expand Up @@ -253,6 +257,7 @@
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('//h3').or have_selector('//h1')
expect("<h1>Text</h1><h2>Text</h2>").to have_no_selector('//h3').and have_selector('//h1')
end
end

Expand Down Expand Up @@ -342,6 +347,7 @@
it "supports compounding" do
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_no_content('XYZ').and have_content('Or')
end
end

Expand Down Expand Up @@ -499,6 +505,7 @@
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

Expand Down

0 comments on commit 58d5b74

Please sign in to comment.