This project is archived and is in readonly mode.
Add Nokogiri as XmlMini backend
-
Pratik
- Assigned user set to Jeremy Kemper
-
Pratik
- Title changed from [PATCH] Add Nokogiri as XmlMini backend to Add Nokogiri as XmlMini backend
-
Repository
- State changed from open to committed
(from [694998ee4fb8d257ba78424cab630846327a0889]) Nokogiri backend for XmlMini
[#2190 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
Bart ten Brinke
I'm getting failures if I actually enable nokogiri:
1) Error: test_array_with_multiple_entries_from_xml(HashToXmlTest): TypeError: can't convert String into Integer
./test/../lib/active_support/xml_mini/nokogiri.rb:38:in `[]' ./test/../lib/active_support/xml_mini/nokogiri.rb:38:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `call' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `to_hash' /Users/bart/.gem/ruby/1.8/gems/nokogiri-1.2.1/lib/nokogiri/xml/node_set.rb:139:in `each' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `call' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `to_hash' /Users/bart/.gem/ruby/1.8/gems/nokogiri-1.2.1/lib/nokogiri/xml/node_set.rb:139:in `each' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:55:in `call' ./test/../lib/active_support/xml_mini/nokogiri.rb:55:in `to_hash' /Users/bart/.gem/ruby/1.8/gems/nokogiri-1.2.1/lib/nokogiri/xml/node_set.rb:139:in `each' ./test/../lib/active_support/xml_mini/nokogiri.rb:55:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:20:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:13:in `parse' (__DELEGATION__):2:in `__send__' (__DELEGATION__):2:in `parse' ./test/../lib/active_support/core_ext/hash/conversions.rb:153:in `from_xml' ./test/core_ext/hash_ext_test.rb:674:in `test_array_with_multiple_entries_from_xml' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `__send__' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `run'2) Error: test_file_from_xml(HashToXmlTest): NoMethodError: undefined method
original_filename' for {"content_type"=>"image/png", "name"=>"logo.png", "type"=>"file"}:Hash./test/core_ext/hash_ext_test.rb:689:in `test_file_from_xml' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `__send__' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `run'3) Error: test_file_from_xml_with_defaults(HashToXmlTest): NoMethodError: You have a nil object when you didn't expect it! The error occurred while evaluating nil.original_filename
./test/core_ext/hash_ext_test.rb:701:in `test_file_from_xml_with_defaults' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `__send__' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `run'4) Error: test_multiple_records_from_xml(HashToXmlTest): TypeError: can't convert String into Integer
./test/../lib/active_support/xml_mini/nokogiri.rb:44:in `[]' ./test/../lib/active_support/xml_mini/nokogiri.rb:44:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `call' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `to_hash' /Users/bart/.gem/ruby/1.8/gems/nokogiri-1.2.1/lib/nokogiri/xml/node_set.rb:139:in `each' ./test/../lib/active_support/xml_mini/nokogiri.rb:52:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:55:in `call' ./test/../lib/active_support/xml_mini/nokogiri.rb:55:in `to_hash' /Users/bart/.gem/ruby/1.8/gems/nokogiri-1.2.1/lib/nokogiri/xml/node_set.rb:139:in `each' ./test/../lib/active_support/xml_mini/nokogiri.rb:55:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:20:in `to_hash' ./test/../lib/active_support/xml_mini/nokogiri.rb:13:in `parse' (__DELEGATION__):2:in `__send__' (__DELEGATION__):2:in `parse' ./test/../lib/active_support/core_ext/hash/conversions.rb:153:in `from_xml' ./test/core_ext/hash_ext_test.rb:605:in `test_multiple_records_from_xml' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `__send__' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `run'5) Failure: test_expansion_count_is_limited(QueryTest)
[./test/core_ext/hash_ext_test.rb:888:in `test_expansion_count_is_limited' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `__send__' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `run']:exception expected but none was thrown.
6) Failure: test_default_is_rexml(REXMLEngineTest)
[./test/xml_mini/rexml_engine_test.rb:8:in `test_default_is_rexml' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `__send__' /Library/Ruby/Gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `run']:<ActiveSupport::XmlMini_REXML> expected but was <ActiveSupport::XmlMini_Nokogiri>.
1666 tests, 7289 assertions, 2 failures, 4 errors
-
Bart ten Brinke
If you run the entire rails test suite you'll get even more errors. Looks like the behaviour is different from Rexml. The LibXML implementation does not have this issue.
-
Aaron Patterson
What version of nokogiri? How are you executing the tests? They all pass for me.
Also, do you have tests for the LibXML version? I'm glad to match behavior if it is spec'd.
-
Bart ten Brinke
Well, if you enable the nokogiri gem as default:
XmlMini.backend = 'Nokogiri'and then run the rails test, you'll see a lot of issues where your nokogiri implementation has a different behaviour as the default REXML and LibXML implementation. This means that enabeling nokogiri will result in a rails which will behave wrong or dangerously ( 5 Failure: test_expansion_count_is_limited(QueryTest )
-
Bart ten Brinke
If you use XmlMini.backend = 'LibXML' you will only get 1 failure: test_default_is_rexml, which is obvious.
-
Aaron Patterson
I can fix these. But I must make it clear that it does not behave dangerously. Expansion count is limited, but nokogiri corrects the document and doesn't raise an exception. :-)
-
Bart ten Brinke
Ok, but the behavior is still different :). I didn't look into the Nokogiri implementation. I do agree with you that this test needs to be automated somehow, for future xml implementations.
BTW: Nice work on the Nokogiri implementation :)
-
Jeremy Kemper
- State changed from committed to open
Ok, I won't revert, but reopened pending expanded test coverage. Thanks guys!
-
Bart ten Brinke
Anyone got a nice idea how to implement this in the active support rake file?
if gem 'libxml-ruby', '=0.9.7' XmlMini.backend = 'LibXML' run_entire_testsuite end if gem 'nokogiri' XmlMini.backend = 'Nokogiri' run_entire_testsuite endThis is why my initial implementation automatically chose from the available back-ends :)
Oh yeah, could you put
require 'nokogiri'at the top of you mixin? That would make it function the same as the LibXML and REXML.
-
Aaron Patterson
Hallo! I've attached a patch that fixes the nokogiri back end so that all rails tests pass.
-
Repository
- State changed from open to resolved
(from [b9e021df974217b9c6ee273bd6c98b40ebde0cd3]) adding more nokogiri tests and making the main rails tests pass
[#2190 state:resolved]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
Stephen Bannasch
Aaron,
You might want to check out this benchmark I just put together comparing all three XmlMini backends.
http://github.com/stepheneb/rail...
The benchmark runs Hash.from_xml on a 1.7MB XML file.
Summary: libxml-ruby was 25x faster than REXML while nokogiri was only 1.6 times faster.
Also: JRuby ran the REXML backend 3 times faster than MRI 1.8.6.
-
Aaron Patterson
@Stephen
You're right. But LibXML seems to produce different results than REXML, where Nokogiri matches the REXML output.
I would say that because of that, this speed test is not exactly valid.
-
Jérôme
Hello
In which file do you set XmlMini.backend = 'Nokogiri' ?
-
Aaron Patterson
I suppose I would do this in my environment.rb file.
-
Jérôme
Nope :(
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant XmlMini (NameError) from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:92:in `const_missing' from /Users/jerome/Sites/foo/config/environment.rb:45 -
Pratik
Jérôme,
You should really be asking this question the mailing list. LH is not for general support. Also, use ActiveSupport::XmlMini.
Thanks.
-
Aaron Patterson
Did you try ActiveSupport::XmlMini?
-
Jérôme
As apache says: it works !
Thanks.
-
Jérôme
Thank you Pratik. However it wasn't documented, not even on the announcement on the official rails blog.
Anyway it works, end of story. Thank you very much.
