Class: InspecRspecJUnit

Inherits:
InspecRspecJson show all
Defined in:
lib/inspec/rspec_json_formatter.rb

Instance Attribute Summary

Attributes inherited from InspecRspecJson

#backend

Instance Method Summary collapse

Methods inherited from InspecRspecJson

#add_profile, #initialize, #stop

Methods inherited from InspecRspecMiniJson

#dump_summary, #stop

Constructor Details

This class inherits a constructor from InspecRspecJson

Instance Method Details

#close(_notification) ⇒ Object

This is the last method is invoked through the formatter interface. Converts the junit formatter constructed output_hash into REXML generated XML and writes it to output.



801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/inspec/rspec_json_formatter.rb', line 801

def close(_notification)
  require 'rexml/document'
  xml_output = REXML::Document.new
  xml_output.add(REXML::XMLDecl.new)

  testsuites = REXML::Element.new('testsuites')
  xml_output.add(testsuites)

  @output_hash[:profiles].each do |profile|
    testsuites.add(build_profile_xml(profile))
  end

  formatter = REXML::Formatters::Pretty.new
  formatter.compact = true
  output.puts formatter.write(xml_output.xml_decl, '')
  output.puts formatter.write(xml_output.root, '')
end