class Minitest::FailureReporter::Reporter

Public Class Methods

new(io, options) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 7
def initialize(io, options)
  @io = io
  @results = []
  @options = options
end

Public Instance Methods

format(test) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 30
def format(test)
  test_file, test_line = test.source_location
  {
    test_file_path: normalize_file_path(test_file),
    test_line: test_line,
    test_id: "#{test.klass}##{test.name}",
    test_name: test.name,
    test_suite: test.klass,
    error_class: test.failure.exception.class.name,
    error_message: full_error_message(test),
    output: full_error_message(test),
  }
end
passed?() click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 13
def passed?
  true
end
record(result) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 19
def record(result)
  if has_failures?(result)
    @results << result
  end
end
report() click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 25
def report
  failures = @results.map { |test| format(test) }.to_json
  @io.puts(failures)
end
start() click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 17
def start; end

Private Instance Methods

backtrace(test) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 70
def backtrace(test)
  test.failure.backtrace.join("\n")
end
full_error_message(test) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 57
def full_error_message(test)
  [message(test), *backtrace(test)].join("\n")
end
has_failures?(test) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 51
def has_failures?(test)
  return false if test.skipped?

  !test.failures.empty? || test.error?
end
message(test) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 61
def message(test)
  error = test.failure
  if error.is_a?(UnexpectedError)
    "#{error.exception.class}: #{error.exception.message}"
  else
    error.exception.message
  end
end
normalize_file_path(file_path) click to toggle source
# File lib/minitest/failure_reporter_reporter.rb, line 46
def normalize_file_path(file_path)
  project_root  = Pathname.new(Dir.pwd)
  Pathname.new(file_path).relative_path_from(project_root).to_s
end