Class: Trainer::JunitGenerator

Inherits:
Object
  • Object
show all
Defined in:
trainer/lib/trainer/junit_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ JunitGenerator

Returns a new instance of JunitGenerator.



7
8
9
# File 'trainer/lib/trainer/junit_generator.rb', line 7

def initialize(results)
  self.results = results
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



5
6
7
# File 'trainer/lib/trainer/junit_generator.rb', line 5

def results
  @results
end

Instance Method Details

#generateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'trainer/lib/trainer/junit_generator.rb', line 11

def generate
  # JUnit file documentation: http://llg.cubic.org/docs/junit/
  # And http://nelsonwells.net/2012/09/how-jenkins-ci-parses-and-displays-junit-output/
  # And http://windyroad.com.au/dl/Open%20Source/JUnit.xsd

  lib_path = Trainer::ROOT
  xml_path = File.join(lib_path, "lib/assets/junit.xml.erb")
  xml = ERB.new(File.read(xml_path), trim_mode: '<>').result(binding) # http://www.rrn.dk/rubys-erb-templating-system

  xml = xml.gsub('system_', 'system-').delete("\e") # Jenkins cannot parse 'ESC' symbol

  # We have to manually clear empty lines
  # They may contain white spaces
  clean_xml = []
  xml.each_line do |row|
    clean_xml << row.delete("\n") if row.strip.to_s.length > 0
  end
  return clean_xml.join("\n")
end