From 4eb8eadd9eed4c3a497696ea6e1211fa79279619 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 25 Mar 2019 16:54:27 -0600 Subject: [PATCH] Add profile info to JSON output --- src/spectator/formatting/json_formatter.cr | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/spectator/formatting/json_formatter.cr b/src/spectator/formatting/json_formatter.cr index a2bb26a..f4ab59d 100644 --- a/src/spectator/formatting/json_formatter.cr +++ b/src/spectator/formatting/json_formatter.cr @@ -67,7 +67,29 @@ module Spectator::Formatting # Adds the profile information to the document. private def profile(profile) - raise NotImplementedError.new("profile") + @json.field("profile") do + @json.object do + @json.field("count", profile.size) + @json.field("time", profile.total_time.to_s) + @json.field("percentage", profile.percentage) + @json.field("results") do + @json.array do + profile.each do |result| + profile_entry(result) + end + end + end + end + end + end + + # Adds a profile entry to the document. + private def profile_entry(result) + @json.object do + @json.field("example", result.example) + @json.field("time", result.elapsed.to_s) + @json.field("source", result.example.source) + end end end end