Class: Minitest::Queue::JUnitReporter

Inherits:
Reporters::BaseReporter
  • Object
show all
Includes:
CI::Queue::OutputHelpers
Defined in:
lib/minitest/queue/junit_reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(report_path = ENV.fetch("CI_QUEUE_MINITEST_JUNITXML", 'log/junit.xml'), options = {}) ⇒ JUnitReporter

Returns a new instance of JUnitReporter.



13
14
15
16
17
# File 'lib/minitest/queue/junit_reporter.rb', line 13

def initialize(report_path = ENV.fetch("CI_QUEUE_MINITEST_JUNITXML", 'log/junit.xml'), options = {})
  super({})
  @report_path = File.absolute_path(report_path)
  @base_path = options[:base_path] || Dir.pwd
end

Instance Method Details

#format_document(doc, io) ⇒ Object



35
36
37
38
39
# File 'lib/minitest/queue/junit_reporter.rb', line 35

def format_document(doc, io)
  formatter = REXML::Formatters::Pretty.new
  formatter.write(doc, io)
  io << "\n"
end

#generate_documentObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/minitest/queue/junit_reporter.rb', line 19

def generate_document
  suites = tests.group_by { |test| test.klass }

  doc = REXML::Document.new(nil, {
    :prologue_quote => :quote,
    :attribute_quote => :quote,
  })
  doc << REXML::XMLDecl.new('1.1', 'utf-8')

  testsuites = doc.add_element('testsuites')
  suites.each do |suite, tests|
    add_tests_to(testsuites, suite, tests)
  end
  doc
end

#reportObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/minitest/queue/junit_reporter.rb', line 41

def report
  super

  dir = File.dirname(@report_path)
  FileUtils.mkdir_p(dir)
  tmp = Tempfile.new([File.basename(@report_path), '.tmp'], dir)
  begin
    format_document(generate_document, tmp)
    tmp.close
    File.rename(tmp.path, @report_path)
  rescue
    tmp.close!
    raise
  end
end