Class: Minitest::JunitFormatter::Reporter
- Inherits:
-
Object
- Object
- Minitest::JunitFormatter::Reporter
- Defined in:
- lib/minitest/junit_formatter.rb
Overview
:nodoc:
Instance Method Summary collapse
- #format(result, parent = nil) ⇒ Object
-
#initialize(io, options) ⇒ Reporter
constructor
A new instance of Reporter.
- #passed? ⇒ Boolean
- #record(result) ⇒ Object
- #report ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(io, options) ⇒ Reporter
Returns a new instance of Reporter.
20 21 22 23 24 25 26 27 28 |
# File 'lib/minitest/junit_formatter.rb', line 20 def initialize(io, ) @io = io @results = [] @options = @options[:timestamp] = .fetch(:timestamp, Time.now.iso8601) @options[:hostname] = .fetch(:hostname, Socket.gethostname) @doc = document_factory.new end |
Instance Method Details
#format(result, parent = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/minitest/junit_formatter.rb', line 62 def format(result, parent = nil) testcase = @doc.element('testcase') @doc.set_attr(testcase, 'classname', format_class(result)) @doc.set_attr(testcase, 'name', format_name(result)) @doc.set_attr(testcase, 'time', format_time(result.time)) @doc.set_attr(testcase, 'file', relative_to_cwd(result.source_location.first)) @doc.set_attr(testcase, 'line', result.source_location.last) @doc.set_attr(testcase, 'assertions', result.assertions) if result.skipped? skipped = @doc.element('skipped') @doc.set_attr(skipped, 'message', result) @doc.add_text(skipped, '') @doc.add_child(testcase, skipped) else result.failures.each do |failure| failure_tag = @doc.element(classify(failure)) @doc.set_attr(failure_tag, 'message', result) @doc.add_text(failure_tag, format_backtrace(failure)) @doc.add_child(testcase, failure_tag) end end # Minitest 5.19 supports metadata # Rails 7.1 adds `failure_screenshot_path` to metadata # Output according to Gitlab format # https://docs.gitlab.com/ee/ci/testing/unit_test_reports.html#view-junit-screenshots-on-gitlab if result.respond_to?("metadata") && result.[:failure_screenshot_path] screenshot = @doc.element("system-out") @doc.add_text(screenshot, "[[ATTACHMENT|#{result.[:failure_screenshot_path]}]]") @doc.add_child(testcase, screenshot) end testcase end |
#passed? ⇒ Boolean
30 31 32 |
# File 'lib/minitest/junit_formatter.rb', line 30 def passed? true end |
#record(result) ⇒ Object
36 37 38 |
# File 'lib/minitest/junit_formatter.rb', line 36 def record(result) @results << result end |
#report ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/minitest/junit_formatter.rb', line 40 def report doc = @doc.document testsuites = @doc.element('testsuites') testsuite = @doc.element('testsuite') @doc.set_attr(testsuite, 'name', @options[:name] || 'minitest') @doc.set_attr(testsuite, 'timestamp', @options[:timestamp]) @doc.set_attr(testsuite, 'hostname', @options[:hostname]) @doc.set_attr(testsuite, 'tests', @results.size) @doc.set_attr(testsuite, 'skipped', @results.count(&:skipped?)) @doc.set_attr(testsuite, 'failures', @results.count { |result| !result.error? && result.failure }) @doc.set_attr(testsuite, 'errors', @results.count(&:error?)) @doc.set_attr(testsuite, 'time', format_time(@results.map(&:time).inject(0, :+))) @results.each do |result| @doc.add_child(testsuite, format(result)) end @doc.add_child(testsuites, testsuite) @doc.add_child(doc, testsuites) @io << @doc.dump(doc) end |
#start ⇒ Object
34 |
# File 'lib/minitest/junit_formatter.rb', line 34 def start; end |