Created
June 5, 2011 07:22
-
-
Save denisdefreyne/1008736 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'minitest/autorun' | |
require 'nokogiri' | |
class MyEncodingTest < MiniTest::Unit::TestCase | |
def test_replace_document | |
doc = Nokogiri::HTML('<p>abc</p>') | |
doc.inner_html = '<p>…</p>' | |
assert_equal '<p>…</p>', doc.inner_html | |
end | |
def test_replace_fragment | |
original_string = '<div><p>abc</p></div>' | |
replaced_string = '<div><p>…</p></div>' | |
replacement_string = '<p>…</p>' | |
doc = Nokogiri::HTML.fragment(original_string, 'UTF-8') | |
assert_equal Encoding.find('UTF-8'), doc.inner_html.encoding # works | |
doc.css('div').first.inner_html = replacement_string | |
assert_equal Encoding.find('UTF-8'), doc.inner_html.encoding # works | |
assert_equal replaced_string, doc.inner_html # FAILS | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment