Created
February 14, 2012 22:01
-
-
Save mboeh/1830890 to your computer and use it in GitHub Desktop.
Nokogiri::XML::Reader#outer_xml issue with JRuby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget https://gist.github.com/raw/1830890/64e63d7e21929937624629e88a3b337928f42d39/nokogiri-jruby-outer-xml-test.rb -O /tmp/nokogiri-jruby-outer-xml-test.rb | |
rvm ree-1.8.7-2011.03 do ruby /tmp/nokogiri-jruby-outer-xml-test.rb | |
rvm jruby-1.6.6 do ruby /tmp/nokogiri-jruby-outer-xml-test.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
gem 'nokogiri', '>= 1.5.0' | |
require 'nokogiri' | |
require 'stringio' | |
require 'test/unit' | |
class JrubyXmlReaderOuterXmlRegressionTest < Test::Unit::TestCase | |
DOCUMENT = <<-EOF | |
<root-element> | |
<children> | |
<child n="1"> | |
<field>child-1</field> | |
</child> | |
<child n="1"> | |
<field>child-2</field> | |
</child> | |
</children> | |
</root-element> | |
EOF | |
def test_correct_outer_html_inclusion | |
xml = Nokogiri::XML::Reader.from_io(StringIO.new(DOCUMENT)) | |
nodelengths = [] | |
has_child2 = [] | |
xml.each do |node| | |
if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child" | |
nodelengths << node.outer_xml.length | |
has_child2 << !!(node.outer_xml =~ /child-2/) | |
end | |
end | |
assert_equal(nodelengths[0], nodelengths[1]) | |
assert(has_child2[1]) | |
assert(!has_child2[0]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[mboeh@orz:~] % rvm ree-1.8.7-2011.03 do ruby /tmp/nokogiri-jruby-outer-xml-test.rb | |
Loaded suite /tmp/nokogiri-jruby-outer-xml-test | |
Started | |
. | |
Finished in 0.000513 seconds. | |
1 tests, 3 assertions, 0 failures, 0 errors | |
[mboeh@orz:~] % rvm jruby-1.6.6 do ruby /tmp/nokogiri-jruby-outer-xml-test.rb | |
Loaded suite /tmp/nokogiri-jruby-outer-xml-test | |
Started | |
F | |
Finished in 0.29 seconds. | |
1) Failure: | |
test_correct_outer_html_inclusion(JrubyXmlReaderOuterXmlRegressionTest) | |
[/tmp/nokogiri-jruby-outer-xml-test.rb:34:in `test_correct_outer_html_inclusion' | |
org/jruby/RubyKernel.java:2074:in `send' | |
org/jruby/RubyArray.java:1614:in `each' | |
org/jruby/RubyArray.java:1614:in `each']: | |
<130> expected but was | |
<64>. | |
1 tests, 1 assertions, 1 failures, 0 errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment