Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negated matchers no longer compoundable #2010

Closed
deivid-rodriguez opened this issue Apr 12, 2018 · 7 comments
Closed

Negated matchers no longer compoundable #2010

deivid-rodriguez opened this issue Apr 12, 2018 · 7 comments

Comments

@deivid-rodriguez
Copy link
Contributor

deivid-rodriguez commented Apr 12, 2018

Meta

Capybara Version: 3.0.1

Expected Behavior

Here's a diff with some specs that used to pass on 2.18.

diff --git a/spec/rspec/shared_spec_matchers.rb b/spec/rspec/shared_spec_matchers.rb
index ac6f240f..b23123c6 100644
--- a/spec/rspec/shared_spec_matchers.rb
+++ b/spec/rspec/shared_spec_matchers.rb
@@ -80,6 +80,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
       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')
       end
     end
 
@@ -147,6 +148,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
       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')
       end
     end
 
@@ -253,6 +255,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
     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
 
@@ -342,6 +345,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
     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
 
@@ -476,6 +480,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
     it "supports compounding" do
       expect("<h1>Text</h1><h2>And</h2>").to have_text('Text').and have_text('And')
       expect("<h1>Text</h1><h2>Or</h2>").to have_text('Not here').or have_text('Or')
+      expect("<h1>Text</h1><h2>Or</h2>").to have_no_text('Not here').and have_text('Or')
     end
   end
 
@@ -499,6 +504,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

Actual Behavior

No longer works. Fail with

Capybara starting Puma...
* Version 3.11.3 , codename: Love Song
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:34699
Run options:                                                                                                                                                            
  include {:full_description=>/supports\ compounding/}
  exclude {:requires=>#<Proc:0x000055fd28e0a968>}
                                                                                                                                                                        
  1) Capybara::Session with chrome have_css matcher on a string supports compounding
     Failure/Error: expect("<h1>Text</h1><h2>Text</h2>").to have_no_css('h4').and have_css('h2')
     
     NoMethodError:
       undefined method `and' for #<Capybara::RSpecMatchers::NegatedMatcher:0x000055fd2ad50958>
     Shared Example Group: Capybara::RSpecMatchers called from ./spec/selenium_spec_chrome.rb:38
     # ./spec/rspec/shared_spec_matchers.rb:83:in `block (4 levels) in <top (required)>'

                                                                                                                                                                        
  2) Capybara::Session with chrome have_xpath matcher on a string supports compounding
     Failure/Error: expect("<h1>Text</h1><h2>Text</h2>").to have_no_xpath('//h4').and have_xpath('//h1')
     
     NoMethodError:
       undefined method `and' for #<Capybara::RSpecMatchers::NegatedMatcher:0x000055fd2b526ec0>
     Shared Example Group: Capybara::RSpecMatchers called from ./spec/selenium_spec_chrome.rb:38
     # ./spec/rspec/shared_spec_matchers.rb:151:in `block (4 levels) in <top (required)>'

                                                                                                                                                                        
  3) Capybara::Session with chrome have_selector matcher supports compounding
     Failure/Error: expect("<h1>Text</h1><h2>Text</h2>").to have_no_selector('//h3').and have_selector('//h1')
     
     NoMethodError:
       undefined method `and' for #<Capybara::RSpecMatchers::NegatedMatcher:0x000055fd2b6138b0>
     Shared Example Group: Capybara::RSpecMatchers called from ./spec/selenium_spec_chrome.rb:38
     # ./spec/rspec/shared_spec_matchers.rb:258:in `block (3 levels) in <top (required)>'

                                                                                                                                                                        
  4) Capybara::Session with chrome have_content matcher supports compounding
     Failure/Error: expect("<h1>Text</h1><h2>Or</h2>").to have_no_content('XYZ').and have_content('Or')
     
     NoMethodError:
       undefined method `and' for #<Capybara::RSpecMatchers::NegatedMatcher:0x000055fd2b67b9d8>
     Shared Example Group: Capybara::RSpecMatchers called from ./spec/selenium_spec_chrome.rb:38
     # ./spec/rspec/shared_spec_matchers.rb:348:in `block (3 levels) in <top (required)>'

                                                                                                                                                                        
  5) Capybara::Session with chrome have_text matcher supports compounding
     Failure/Error: expect("<h1>Text</h1><h2>Or</h2>").to have_no_text('Not here').and have_text('Or')
     
     NoMethodError:
       undefined method `and' for #<Capybara::RSpecMatchers::NegatedMatcher:0x000055fd2b6bfd68>
     Shared Example Group: Capybara::RSpecMatchers called from ./spec/selenium_spec_chrome.rb:38
     # ./spec/rspec/shared_spec_matchers.rb:483:in `block (3 levels) in <top (required)>'

                                                                                                                                                                        
  6) Capybara::Session with chrome have_link matcher supports compounding
     Failure/Error: expect(html).to have_no_link('Not a link').and have_link('Another link')
     
     NoMethodError:
       undefined method `and' for #<Capybara::RSpecMatchers::NegatedMatcher:0x000055fd2b778a70>
     Shared Example Group: Capybara::RSpecMatchers called from ./spec/selenium_spec_chrome.rb:38
     # ./spec/rspec/shared_spec_matchers.rb:507:in `block (3 levels) in <top (required)>'

 14/14 |==================================================================== 100 =====================================================================>| Time: 00:00:00 

Finished in 0.19394 seconds (files took 0.81648 seconds to load)
14 examples, 6 failures

Failed examples:

rspec ./spec/selenium_spec_chrome.rb[1:2:2:3] # Capybara::Session with chrome have_css matcher on a string supports compounding
rspec ./spec/selenium_spec_chrome.rb[1:3:2:3] # Capybara::Session with chrome have_xpath matcher on a string supports compounding
rspec ./spec/selenium_spec_chrome.rb[1:4:4] # Capybara::Session with chrome have_selector matcher supports compounding
rspec ./spec/selenium_spec_chrome.rb[1:5:4] # Capybara::Session with chrome have_content matcher supports compounding
rspec ./spec/selenium_spec_chrome.rb[1:6:4] # Capybara::Session with chrome have_text matcher supports compounding
rspec ./spec/selenium_spec_chrome.rb[1:7:4] # Capybara::Session with chrome have_link matcher supports compounding

Steps to reproduce

@twalpole
Copy link
Member

Good catch -- fixing

@twalpole
Copy link
Member

Fixed via 059fd43 - I will release 3.0.2 including the fix later today or tomorrow

@deivid-rodriguez
Copy link
Contributor Author

Thanks!!

@twalpole
Copy link
Member

Released 3.0.2

@maxim
Copy link

maxim commented Dec 7, 2018

For some reason I'm still getting this for have_text on Capybara 3.12.0. (rspec 3.7.1, rspec-rails 3.7.2)

undefined method `and' for #<Capybara::RSpecMatchers::Matchers::HaveText:0x00007fccddc71670>

When I use it like

expect(page)
  .to have_text('foo')
  .and have_text('bar')
  .and have_text('baz')

@twalpole
Copy link
Member

twalpole commented Dec 7, 2018

@maxim None of those matchers are negated (have_no_text) so it’s not the same issue - please create a new issue with details of what you're doing - most likely you're not requiring rspec before capybara

@maxim
Copy link

maxim commented Dec 7, 2018

@twalpole Thank you for the pointer, turns out capybara/rspec wasn't required at all. All good now. 👍

@lock lock bot locked and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants