Class: Minitest::Junit::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/junit.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(io, options) ⇒ Reporter

Returns a new instance of Reporter.



12
13
14
15
16
17
18
# File 'lib/minitest/junit.rb', line 12

def initialize(io, options)
  @io = io
  @results = []
  @options = options
  @options[:timestamp] = options.fetch(:timestamp, Time.now.iso8601)
  @options[:hostname] = options.fetch(:hostname, Socket.gethostname)
end

Instance Method Details

#format(result, parent = nil) ⇒ Object



57
58
59
60
61
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
# File 'lib/minitest/junit.rb', line 57

def format(result, parent = nil)
  testcase = Ox::Element.new('testcase')
  testcase['classname'] = format_class(result)
  testcase['name'] = format_name(result)
  testcase['time'] = format_time(result.time)
  testcase['file'] = relative_to_cwd(result.source_location.first)
  testcase['line'] = result.source_location.last
  testcase['assertions'] = result.assertions

  if result.skipped?
    skipped = Ox::Element.new('skipped')
    skipped['message'] = result
    skipped << ""
    testcase << skipped
  else
    result.failures.each do |failure|
      failure_tag = Ox::Element.new(classify(failure))
      failure_tag['message'] = result
      failure_tag << format_backtrace(failure)
      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 = Ox::Element.new("system-out")
    screenshot << "[[ATTACHMENT|#{result.[:failure_screenshot_path]}]]"
    testcase << screenshot
  end

  testcase
end

#passed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/minitest/junit.rb', line 20

def passed?
  true
end

#record(result) ⇒ Object



26
27
28
# File 'lib/minitest/junit.rb', line 26

def record(result)
  @results << result
end

#reportObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/minitest/junit.rb', line 30

def report
  doc = Ox::Document.new(version: '1.0', encoding: 'UTF-8')
  instruct = Ox::Instruct.new(:xml)
  instruct[:version] = '1.0'
  instruct[:encoding] = 'UTF-8'
  doc << instruct

  testsuite = Ox::Element.new('testsuite')
  testsuite['name'] = @options[:name] || 'minitest'
  testsuite['timestamp'] = @options[:timestamp]
  testsuite['hostname'] = @options[:hostname]
  testsuite['tests'] = @results.size
  testsuite['skipped'] = @results.count(&:skipped?)
  testsuite['failures'] = @results.count { |result| !result.error? && result.failure }
  testsuite['errors'] = @results.count(&:error?)
  testsuite['time'] = format_time(@results.map(&:time).inject(0, :+))
  @results.each do |result|
    testsuite << format(result)
  end

  testsuites = Ox::Element.new('testsuites')
  testsuites << testsuite

  doc << testsuites
  @io << Ox.dump(doc)
end

#startObject



24
# File 'lib/minitest/junit.rb', line 24

def start; end