Class: Minitest::Reporters::ShoesExportReporter
- Inherits:
-
BaseReporter
- Object
- BaseReporter
- Minitest::Reporters::ShoesExportReporter
- Defined in:
- scarpe-components/lib/scarpe/components/minitest_export_reporter.rb
Overview
To use this Scarpe component, you'll need minitest-reporters in your Gemfile, probably in the "test" group. You'll need to require and activate ShoesExportReporter to register it as Minitest's reporter:
require "scarpe/components/minitest_export_reporter"
Minitest::Reporters::ShoesExportReporter.activate!
Select a destination to export JSON test results to:
export SHOES_MINITEST_EXPORT_FILE=/tmp/shoes_test_export.json
This class overrides the MINITEST_REPORTER environment variable when you call activate. If MINITEST_REPORTER isn't set then when you run via Vim, TextMate, RubyMine, etc, the reporter will be automatically overridden and print to console instead.
Based on https://gist.github.com/davidwessman/09a13840a8a80080e3842ac3051714c7
Class Attribute Summary collapse
-
.export_file ⇒ Object
Returns the value of attribute export_file.
-
.metadata ⇒ Object
Returns the value of attribute metadata.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.export_file ⇒ Object
Returns the value of attribute export_file.
30 31 32 |
# File 'scarpe-components/lib/scarpe/components/minitest_export_reporter.rb', line 30 def export_file @export_file end |
.metadata ⇒ Object
Returns the value of attribute metadata.
29 30 31 |
# File 'scarpe-components/lib/scarpe/components/minitest_export_reporter.rb', line 29 def @metadata end |
Class Method Details
.activate! ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'scarpe-components/lib/scarpe/components/minitest_export_reporter.rb', line 33 def self.activate! unless ENV["SHOES_MINITEST_EXPORT_FILE"] raise "ShoesExportReporter is available, but no export file was specified! Set SHOES_MINITEST_EXPORT_FILE!" end ShoesExportReporter.export_file = File.(ENV["SHOES_MINITEST_EXPORT_FILE"]) ShoesExportReporter. ||= {} Minitest::Reporters.use! end |
Instance Method Details
#report ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'scarpe-components/lib/scarpe/components/minitest_export_reporter.rb', line 56 def report super results = tests.map do |result| failures = serialize_failures result.failures { name: result.name, klass: test_class(result), assertions: result.assertions, failures: failures, time: result.time, metadata: result.respond_to?(:metadata) ? result. : {}, exporter_metadata: ShoesExportReporter., source_location: begin result.source_location rescue ["unknown", -1] end, } end out_file = ShoesExportReporter.export_file #puts "Writing Minitest results to #{out_file.inspect}." File.write(out_file, JSON.dump(results)) end |
#serialize_failures(failures) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'scarpe-components/lib/scarpe/components/minitest_export_reporter.rb', line 43 def serialize_failures(failures) failures.map do |fail| case fail when Minitest::UnexpectedError ["unexpected", fail.to_json, fail.error.to_json] when Exception ["exception", fail.to_json] else raise "Not sure how to serialize failure object! #{fail.inspect}" end end end |