Class: Minitest::Queue::JUnitReporter
- Inherits:
-
Reporters::BaseReporter
- Object
- Reporters::BaseReporter
- Minitest::Queue::JUnitReporter
- Includes:
- CI::Queue::OutputHelpers
- Defined in:
- lib/minitest/queue/junit_reporter.rb
Instance Method Summary collapse
- #format_document(doc, io) ⇒ Object
- #generate_document ⇒ Object
-
#initialize(report_path = ENV.fetch("CI_QUEUE_MINITEST_JUNITXML", 'log/junit.xml'), options = {}) ⇒ JUnitReporter
constructor
A new instance of JUnitReporter.
- #report ⇒ Object
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'), = {}) super({}) @report_path = File.absolute_path(report_path) @base_path = [: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_document ⇒ Object
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 |
#report ⇒ Object
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 |