mbklein / equivalent-xml

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

Explicitly require dependencies to avoid ordering issues #37

Open nickbrowne opened 7 years ago

nickbrowne commented 7 years ago

I ran into an issue attempting to use the master version (which fixes a comparison bug we were having in 0.6.0) where the order of files being loaded in lib/equivalent-xml.rb was inconsistent. This leads to an issue when requiring the gem:

Bundler::GemRequireError: There was an error while trying to load the gem 'equivalent-xml'.
Gem Load Error is: uninitialized constant EquivalentXml::Proxy::Base

Dir[File.expand_path('../equivalent-xml/proxy/*',__FILE__)] seems to return an array of paths in an unintended order. This causes the subclasses to load before the super class, which results in EquivalentXml::Proxy::Base being undefined.

On my machine it will load in the order:

equivalent-xml/lib/equivalent-xml/proxy/oga.rb
equivalent-xml/lib/equivalent-xml/proxy/nokogiri.rb
equivalent-xml/lib/equivalent-xml/proxy/base.rb

I've changed the requires to be more explicit, each subclass now requires the base class, and lib/equivalent-xml.rb requires each of the subclasses. It's possible you're not keen on this approach, but I thought I would propose it to see what you thought.

nickbrowne commented 7 years ago

I'm not sure why those builds are failing...