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 = 'log/junit.xml', options = {}) ⇒ JUnitReporter

Returns a new instance of JUnitReporter.



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

def initialize(report_path = '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



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

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

#generate_documentObject



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

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



40
41
42
43
44
45
46
47
# File 'lib/minitest/queue/junit_reporter.rb', line 40

def report
  super

  FileUtils.mkdir_p(File.dirname(@report_path))
  File.open(@report_path, 'w+') do |file|
    format_document(generate_document, file)
  end
end