mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
Use methods to access RunData
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
98ae89e6cc
commit
3651f85a7c
1 changed files with 16 additions and 16 deletions
|
@ -12,7 +12,7 @@ module InspecPlugins::JUnitReporter
|
|||
testsuites = REXML::Element.new("testsuites")
|
||||
xml_output.add(testsuites)
|
||||
|
||||
run_data[:profiles].each do |profile|
|
||||
run_data.profiles.each do |profile|
|
||||
testsuites.add(build_profile_xml(profile))
|
||||
end
|
||||
|
||||
|
@ -24,14 +24,14 @@ module InspecPlugins::JUnitReporter
|
|||
|
||||
def build_profile_xml(profile)
|
||||
profile_xml = REXML::Element.new("testsuite")
|
||||
profile_xml.add_attribute("name", profile[:name])
|
||||
profile_xml.add_attribute("name", profile.name)
|
||||
profile_xml.add_attribute("tests", count_profile_tests(profile))
|
||||
profile_xml.add_attribute("failed", count_profile_failed_tests(profile))
|
||||
profile_xml.add_attribute("failures", count_profile_failed_tests(profile))
|
||||
|
||||
profile[:controls].each do |control|
|
||||
control[:results].each do |result|
|
||||
profile_xml.add(build_result_xml(profile[:name], control, result))
|
||||
profile.controls.each do |control|
|
||||
control.results.each do |result|
|
||||
profile_xml.add(build_result_xml(profile.name, control, result))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,16 +40,16 @@ module InspecPlugins::JUnitReporter
|
|||
|
||||
def build_result_xml(profile_name, control, result)
|
||||
result_xml = REXML::Element.new("testcase")
|
||||
result_xml.add_attribute("name", result[:code_desc])
|
||||
result_xml.add_attribute("classname", control[:title].nil? ? "#{profile_name}.Anonymous" : "#{profile_name}.#{control[:id]}")
|
||||
result_xml.add_attribute("target", run_data[:platform][:target].nil? ? "" : run_data[:platform][:target].to_s)
|
||||
result_xml.add_attribute("time", result[:run_time])
|
||||
result_xml.add_attribute("name", result.code_desc)
|
||||
result_xml.add_attribute("classname", control.title.nil? ? "#{profile_name}.Anonymous" : "#{profile_name}.#{control.id}")
|
||||
result_xml.add_attribute("target", run_data.platform.target.nil? ? "" : run_data.platform.target.to_s)
|
||||
result_xml.add_attribute("time", result.run_time)
|
||||
|
||||
if result[:status] == "failed"
|
||||
if result.status == "failed"
|
||||
failure_element = REXML::Element.new("failure")
|
||||
failure_element.add_attribute("message", result[:message])
|
||||
result_xml.add(failure_element)
|
||||
elsif result[:status] == "skipped"
|
||||
elsif result.status == "skipped"
|
||||
result_xml.add_element("skipped")
|
||||
end
|
||||
|
||||
|
@ -57,15 +57,15 @@ module InspecPlugins::JUnitReporter
|
|||
end
|
||||
|
||||
def count_profile_tests(profile)
|
||||
profile[:controls].reduce(0) do |acc, elem|
|
||||
acc + elem[:results].count
|
||||
profile.controls.reduce(0) do |acc, elem|
|
||||
acc + elem.results.count
|
||||
end
|
||||
end
|
||||
|
||||
def count_profile_failed_tests(profile)
|
||||
profile[:controls].reduce(0) do |acc, elem|
|
||||
acc + elem[:results].reduce(0) do |fail_test_total, test_case|
|
||||
test_case[:status] == "failed" ? fail_test_total + 1 : fail_test_total
|
||||
profile.controls.reduce(0) do |acc, elem|
|
||||
acc + elem.results.reduce(0) do |fail_test_total, test_case|
|
||||
test_case.status == "failed" ? fail_test_total + 1 : fail_test_total
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue