From 29dc833ea3f46120023592f9a49af5a7ab9357b2 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Mar 2019 21:48:00 -0600 Subject: [PATCH] Add report stats, timing, and result --- src/spectator/formatting/json_formatter.cr | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/spectator/formatting/json_formatter.cr b/src/spectator/formatting/json_formatter.cr index 221268d..36e739f 100644 --- a/src/spectator/formatting/json_formatter.cr +++ b/src/spectator/formatting/json_formatter.cr @@ -22,6 +22,9 @@ module Spectator::Formatting # The results from the entire suite are provided. def end_suite(report : Report) @json.end_array # examples + totals(report) + timing(report) + @json.field("result", report.failed? ? "fail" : "success") @json.end_object end @@ -34,5 +37,30 @@ module Spectator::Formatting def end_example(result : Result) result.to_json(@json) end + + # Adds the totals section of the document. + private def totals(report) + @json.field("totals") do + @json.object do + @json.field("examples", report.example_count) + @json.field("success", report.successful_count) + @json.field("fail", report.failed_count) + @json.field("error", report.error_count) + @json.field("pending", report.pending_count) + @json.field("remaining", report.remaining_count) + end + end + end + + # Adds the timings section of the document. + private def timing(report) + @json.field("timing") do + @json.object do + @json.field("runtime", report.runtime.to_s) + @json.field("examples", report.example_runtime.to_s) + @json.field("overhead", report.overhead_time.to_s) + end + end + end end end