32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/barthes/reporter/junit_xml.rb', line 32
def walk_json(json, parents=[])
case json.first
when 'feature'
if json.last.class == Array
@xml.testsuite(name: json[1], tests: json.last.size) do
parents.push json[1]
json.last.each do |child|
walk_json(child, parents)
end
parents.pop
end
end
when 'scenario'
if json.last.class == Array
parents.push json[1]
json.last.each do |child|
walk_json(child, parents)
end
parents.pop
end
when 'action'
name = "##{sprintf('%03d', json.last['number'])} #{parents.join(' > ')} #{json[1]}"
@xml.testcase(name: name) do
case json.last['status']
when 'skipped'
@xml.skipped
when 'failure'
failure = "failed expectations: \n"
expectations = json.last['expectations'] || []
expectations.each do |expectation|
if expectation['result'] == false
failure += JSON.pretty_generate(expectation) + "\n"
end
end
@xml.failure failure
when 'error'
error = "error:\n"
error += "class: #{json.last['error']['class']}\n"
error += "message: #{json.last['error']['message']}\n"
error += "backtrace: #{json.last['error']['backtrace'].join("\n")}\n"
@xml.error error
end
if json.last['status'] != 'skipped' && json.last['request'] && json.last['response']
stdout = "request:\n"
stdout += "#{JSON.pretty_generate(json.last['request'])}\n"
stdout += "response:\n"
stdout += "#{JSON.pretty_generate(json.last['response'])}\n"
@xml.tag!(:'system-out', stdout)
end
end
else
puts json
end
end
|