Class: Minitest::Queue::TestDataReporter

Inherits:
Reporters::BaseReporter
  • Object
show all
Defined in:
lib/minitest/queue/test_data_reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(report_path: 'log/test_data.json', base_path: nil, namespace: '') ⇒ TestDataReporter

Returns a new instance of TestDataReporter.



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

def initialize(report_path: 'log/test_data.json', base_path: nil, namespace: '')
  super({})
  @report_path = File.absolute_path(report_path)
  @base_path = base_path || Dir.pwd
  @namespace = namespace || ''
end

Instance Method Details

#reportObject



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

def report
  super

  result = tests.map.with_index do |test, index|
    Queue::TestData.new(test: test, index: index,
                        base_path: @base_path, namespace: @namespace).to_h
  end.to_json

  dirname = File.dirname(@report_path)
  FileUtils.mkdir_p(dirname)
  File.open(@report_path, 'w+') { |file| file << result }
end