Add report stats, timing, and result

This commit is contained in:
Michael Miller 2019-03-22 21:48:00 -06:00
parent dca2925461
commit 29dc833ea3

View file

@ -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