Class: SemanticLogger::Reporters::Minitest

Inherits:
Minitest::AbstractReporter
  • Object
show all
Includes:
Loggable
Defined in:
lib/semantic_logger/reporters/minitest.rb

Overview

When using Minitest to run tests, log start and end messages for every test to the log file. On completion the time it took to run the test is also logged.

For example, add the following lines to ‘test_helper.rb`:

require 'minitest/reporters'

reporters = [
  Minitest::Reporters::ProgressReporter.new,
  SemanticLogger::Reporters::Minitest.new
]
Minitest::Reporters.use!(reporters)

And add ‘gem minitest-reporters` to the Gemfile.

Log entries similar to the following should show up in the log file:

2019-02-06 18:58:17.522467 I [84730:70256441962000] Minitest – START RocketJob::DirmonEntry::with valid entry::#archive_file test_0001_moves file to archive dir 2019-02-06 18:58:17.527492 I [84730:70256441962000] (4.980ms) Minitest – PASS RocketJob::DirmonEntry::with valid entry::#archive_file test_0001_moves file to archive dir 2019-02-06 18:58:17.527835 I [84730:70256441962000] Minitest – START RocketJob::DirmonEntry::#job_class::with a valid job_class_name test_0001_return job class 2019-02-06 18:58:17.529761 I [84730:70256441962000] (1.882ms) Minitest – PASS RocketJob::DirmonEntry::#job_class::with a valid job_class_name test_0001_return job class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

included

Instance Attribute Details

#ioObject

Returns the value of attribute io.



28
29
30
# File 'lib/semantic_logger/reporters/minitest.rb', line 28

def io
  @io
end

Instance Method Details

#after_test(test) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/semantic_logger/reporters/minitest.rb', line 34

def after_test(test)
  if test.error?
    logger.benchmark_error("FAIL #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: "minitest/fail")
  elsif test.skipped?
    logger.benchmark_warn("SKIP #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: "minitest/skip")
  else
    logger.benchmark_info("PASS #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: "minitest/pass")
  end
end

#before_test(test) ⇒ Object



30
31
32
# File 'lib/semantic_logger/reporters/minitest.rb', line 30

def before_test(test)
  logger.info("START #{test.class_name} #{test.name}")
end