Add profile info to JSON output

This commit is contained in:
Michael Miller 2019-03-25 16:54:27 -06:00
parent df6431f2d7
commit 4eb8eadd9e

View file

@ -67,7 +67,29 @@ module Spectator::Formatting
# Adds the profile information to the document. # Adds the profile information to the document.
private def profile(profile) 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 end
end end