Class: SemanticLogger::Reporters::Minitest
- Inherits:
-
Minitest::AbstractReporter
- Object
- Minitest::AbstractReporter
- SemanticLogger::Reporters::Minitest
- 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:70256] Minitest -- START MyJob test_0001_archives file 2019-02-06 18:58:17.527492 I [84730:70256] (4.980ms) Minitest -- PASS MyJob test_0001_archives file 2019-02-06 18:58:17.527835 I [84730:70256] Minitest -- START MyJob test_0002_returns job class 2019-02-06 18:58:17.529761 I [84730:70256] (1.882ms) Minitest -- PASS MyJob test_0002_returns job class
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
Instance Method Summary collapse
Methods included from Loggable
Instance Attribute Details
#io ⇒ Object
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 43 44 45 |
# 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 |