Skip to content

Commit

Permalink
cleaning up serialize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Feb 20, 2009
1 parent c534486 commit 1d06b4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/nokogiri/xml/node.rb
Expand Up @@ -392,6 +392,7 @@ def to_xml encoding = nil
def to_xhtml encoding = nil
serialize(encoding, SaveOptions::FORMAT |
SaveOptions::NO_DECLARATION |
SaveOptions::NO_EMPTY_TAGS |
SaveOptions::AS_XHTML)
end

Expand All @@ -409,6 +410,7 @@ def write_to io, encoding = nil, save_options = SaveOptions::FORMAT
def write_html_to io, encoding = nil
write_to io, encoding, SaveOptions::FORMAT |
SaveOptions::NO_DECLARATION |
SaveOptions::NO_EMPTY_TAGS |
SaveOptions::AS_HTML
end

Expand All @@ -417,6 +419,7 @@ def write_html_to io, encoding = nil
def write_xhtml_to io, encoding = nil
write_to io, encoding, SaveOptions::FORMAT |
SaveOptions::NO_DECLARATION |
SaveOptions::NO_EMPTY_TAGS |
SaveOptions::AS_XHTML
end

Expand Down
10 changes: 7 additions & 3 deletions test/xml/test_node.rb
Expand Up @@ -19,32 +19,36 @@ def test_write_to
def test_write_to_with_block
called = false
io = StringIO.new
conf = nil
@xml.write_to io do |config|
called = true
conf = config
config.format.as_html.no_empty_tags
end
io.rewind
assert called
assert_equal @xml.serialize(nil, 1 | 64 | 4), io.read
assert_equal @xml.serialize(nil, conf.options), io.read
end

%w{ xml html xhtml }.each do |type|
define_method(:"test_write_#{type}_to") do
io = StringIO.new
assert @xml.send(:"write_#{type}_to", io)
io.rewind
assert_equal @xml.send(:"to_#{type}"), io.read
assert_match @xml.send(:"to_#{type}"), io.read
end
end

def test_serialize_with_block
called = false
conf = nil
string = @xml.serialize do |config|
called = true
conf = config
config.format.as_html.no_empty_tags
end
assert called
assert_equal @xml.serialize(nil, 1 | 64 | 4), string
assert_equal @xml.serialize(nil, conf.options), string
end

def test_values
Expand Down

0 comments on commit 1d06b4f

Please sign in to comment.