Class: InspecPlugins::JUnitReporter::ReporterV1

Inherits:
Reporter
  • Object
show all
Defined in:
lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/reporter.rb

Overview

This is the “Legacy” JUnit reporter. It produces XML which is not correct according to the JUnit standard. It is retained for backwards compatibility.

Instance Method Summary collapse

Methods inherited from Reporter

#count_profile_errored_tests, #count_profile_failed_tests, #count_profile_skipped_tests, #count_profile_tests, #render, run_data_schema_constraints

Instance Method Details

#build_profile_xml(profile, _idx) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/reporter.rb', line 60

def build_profile_xml(profile, _idx)
  profile_xml = REXML::Element.new("testsuite")
  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))
    end
  end

  profile_xml
end

#build_result_xml(profile_name, control, result) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/reporter.rb', line 76

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)

  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"
    result_xml.add_element("skipped")
  end

  result_xml
end