Skip to content

Commit

Permalink
Add test for exception being raised from an XML::Builder block
Browse files Browse the repository at this point in the history
Co-authored-by: Joana Tavares <jtavares@salsify.com>
  • Loading branch information
ric2b and rinthedev committed Nov 19, 2021
1 parent 44efbc3 commit 210ecbc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/xml/test_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ def test_builder_multiple_nodes
end
end

def test_builder_resilient_to_exceptions
builder = Nokogiri::XML::Builder.new do |xml|
xml.root do
begin
xml.a { raise "badjoras" }
rescue StandardError
# Ignored
end

xml.b
end
end

expected_output = <<~HEREDOC
<?xml version="1.0"?>
<root>
<a/>
<b/>
</root>
HEREDOC
assert_equal(expected_output, builder.to_xml)
end

def test_builder_with_utf8_text
text = "test ﺵ "
doc = Nokogiri::XML::Builder.new(encoding: "UTF-8") { |xml| xml.test(text) }.doc
Expand Down

0 comments on commit 210ecbc

Please sign in to comment.