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

NoMethodError: undefined method `equivalent_to?' #25

Closed
awead opened this issue Aug 21, 2014 · 10 comments
Closed

NoMethodError: undefined method `equivalent_to?' #25

awead opened this issue Aug 21, 2014 · 10 comments

Comments

@awead
Copy link

awead commented Aug 21, 2014

Ran into:

NoMethodError: undefined method `equivalent_to?'

When using with rspec. I was able to fix this by adding require 'equivalent-xml/rspec_matchers' to my spec_helper.rb file. I didn't have require either matchers or equivalent-xml as per the README.

This was using rspec 2.99 and rails 4.1.5.

@karlhe
Copy link

karlhe commented Sep 3, 2014

Noticed this as well using rspec 2.14, rails 3.1.12, nokogiri 1.5.7, equivalent-xml 0.5.1

Likely not related to rspec/rails version.

@mbklein
Copy link
Owner

mbklein commented Sep 4, 2014

This seems to be another battle in the war to provide seamless compatibility with both RSpec 2 and 3. I thought I had it fixed, but I'll keep looking into it.

@joallard
Copy link

The workaround that seemed to work for me, change the require line to:

require 'equivalent-xml/rspec_matchers'

@dchandekstark
Copy link

Me too. rspec-rails 3.0.2, rspec-core 3.0.4.

@atz
Copy link

atz commented Dec 3, 2014

That require change worked for me also.

ruby-2.1.2
rspec-rails (3.1.0) 
rspec-core  (3.1.0)

@amitpatelx
Copy link

Facing same issue with equivalent-xml 0.5.1. We have been using RSpec 3.1.0 in one of our gem. The workaround in #25 (comment) worked for me as well.

@mbklein
Copy link
Owner

mbklein commented Aug 18, 2016

This issue has been stagnant for a while, so I'm going to close it. I think the answer is to explicitly require equivalent-xml/rspec_matchers in spec_helper.rb.

@mbklein mbklein closed this as completed Aug 18, 2016
@joallard
Copy link

@mbklein If that's the case I'd suggest trying to catch that with a more helpful error message. Error messages are important!

@jpmcgrath
Copy link

@mbklein it would be good to update the readme to reflect this.

@tierra
Copy link

tierra commented Jun 26, 2018

Worth noting that this happens because matchers are only loaded if this gem detects that RSpec is defined:

if defined?(::RSpec::Matchers) or defined?(::Spec::Matchers)
  require 'equivalent-xml/rspec_matchers'
end

But the issue here is that, anyone using the standard Ruby Coding Guidelines and Rubocop usually maintains a Gemfile that makes Bundler load equivalent-xml before it loads rspec (since it's in alphabetical order). Of course this means that, Rspec won't be loaded when EquivalentXml is loaded, so it thinks you don't need the matchers.

One way EquivalentXml could handle this situation (without requiring everyone to explicitly require the matchers) is by doing something like this:

begin
  require 'rspec'
  require 'equivalent-xml/rspec_matchers'
rescue LoadError
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants