From dbffad837d04fdcd1f242cef50dacba0298f177d Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Feb 2019 13:54:12 -0700 Subject: [PATCH] Calculate each type of result once at initialization --- src/spectator/report.cr | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/spectator/report.cr b/src/spectator/report.cr index 2439f1b..1b13546 100644 --- a/src/spectator/report.cr +++ b/src/spectator/report.cr @@ -5,10 +5,35 @@ module Spectator # This includes examples, hooks, and framework processes. getter runtime : Time::Span + # Number of passing examples. + getter successful_count = 0 + + # Number of failing examples (includes errors). + getter failed_count = 0 + + # Number of examples that had errors. + getter error_count = 0 + + # Number of pending examples. + getter pending_count = 0 + # Creates the report. # The *results* are from running the examples in the test suite. # The *runtime* is the total time it took to execute the suite. def initialize(@results : Array(Result), @runtime) + @results.each do |result| + case result + when SuccessfulResult + @successful_count += 1 + when ErroredResult + @error_count += 1 + @failed_count += 1 + when FailedResult + @failed_count += 1 + when PendingResult + @pending_count += 1 + end + end end # Number of examples. @@ -16,26 +41,6 @@ module Spectator @results.size end - # Number of passing examples. - def successful_count - @results.count(&.is_a?(SuccessfulResult)) - end - - # Number of failing examples (includes errors). - def failed_count - @results.count(&.is_a?(FailedResult)) - end - - # Number of examples that had errors. - def error_count - @results.count(&.is_a?(ErroredResult)) - end - - # Number of pending examples. - def pending_count - @results.count(&.is_a?(PendingResult)) - end - # Returns a set of results for all failed examples. def failures @results.each.compact_map(&.as?(FailedResult))