mbklein / equivalent-xml

Easy equivalency tests for Nokogiri and Oga XML
MIT License
94 stars 29 forks source link

NoMethodError: undefined method `equivalent_to?' #25

Closed awead closed 8 years ago

awead commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 9 years ago

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

require 'equivalent-xml/rspec_matchers'
dchandekstark commented 9 years ago

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

atz commented 9 years ago

That require change worked for me also.

ruby-2.1.2
rspec-rails (3.1.0) 
rspec-core  (3.1.0)
amitpatelx commented 9 years ago

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 https://github.com/mbklein/equivalent-xml/issues/25#issuecomment-59627128 worked for me as well.

mbklein commented 8 years ago

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.

joallard commented 8 years ago

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

jpmcgrath commented 7 years ago

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

tierra commented 6 years ago

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