Skip to content

Commit b5ef1ef

Browse files
committed
test: improve failure message for tree construction
where before we saw: TestHtml5TreeConstructionWebkit02#test_31 [/home/flavorjones/code/oss/nokogiri/test/html5/test_tree_construction.rb:35] Minitest::Assertion: Element <select><option><hr></option></select> has wrong number of children ["option"] in <table><tr><td><select><option><hr>. Expected: 2 Actual: 1 now we'll see: TestHtml5TreeConstructionWebkit02#test_31 [/home/flavorjones/code/oss/nokogiri/test/html5/test_tree_construction.rb:35] Minitest::Assertion: Element <select> has wrong number of children ["option"] Input: <table><tr><td><select><option><hr> Expected: | <html> | <head> | <body> | <table> | <tbody> | <tr> | <td> | <select> | <option> | <hr> Parsed: <select><option><hr></option></select>. Expected: 2 Actual: 1
1 parent 47401f4 commit b5ef1ef

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/html5/test_tree_construction.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ def compare_nodes(node, ng_node)
3535
assert_equal(
3636
node[:children].length,
3737
ng_node.children.length,
38-
"Element <#{node[:tag]}> has wrong number of children #{ng_node.children.map(&:name)} in #{@test[:data]}",
38+
[
39+
"Element <#{node[:tag]}> has wrong number of children #{ng_node.children.map(&:name)}",
40+
" Input: #{@test[:data]}",
41+
"Expected: #{@test[:raw].join("\n ")}",
42+
" Parsed: #{ng_node.to_html}",
43+
].join("\n"),
3944
)
4045
when Nokogiri::XML::Node::TEXT_NODE, Nokogiri::XML::Node::CDATA_SECTION_NODE
4146
# We preserve the CDATA in the tree, but the tests represent it as text.
@@ -205,8 +210,10 @@ def self.parse_test(test_data)
205210
children: [],
206211
}
207212
open_nodes = [document]
213+
test[:raw] = []
208214
while index < lines.length
209215
raise(BadHtml5libFormat, "Expected '| ' but got #{lines[index]}") unless /^\| ( *)([^ ].*$)/ =~ lines[index]
216+
test[:raw] << lines[index]
210217

211218
depth = $LAST_MATCH_INFO[1].length
212219
if depth.odd?

0 commit comments

Comments
 (0)