diff --git a/spec/report_spec.cr b/spec/report_spec.cr index 8c1b2ff..bc78a65 100644 --- a/spec/report_spec.cr +++ b/spec/report_spec.cr @@ -22,7 +22,7 @@ def new_report(successful_count = 5, failed_count = 5, error_count = 5, pending_ error_count.times { results << new_failure_result(Spectator::ErroredResult) } pending_count.times { results << new_pending_result } - example_runtime = results.select(&.is_a?(Spectator::FinishedResult)).map(&.as(Spectator::FinishedResult)).sum(&.elapsed) + example_runtime = results.compact_map(&.as?(Spectator::FinishedResult)).sum(&.elapsed) total_runtime = example_runtime + Time::Span.new(nanoseconds: overhead_time) Spectator::Report.new(results, total_runtime) end diff --git a/src/spectator/report.cr b/src/spectator/report.cr index adac39b..b8c7d63 100644 --- a/src/spectator/report.cr +++ b/src/spectator/report.cr @@ -38,25 +38,19 @@ module Spectator # Returns a set of results for all failed examples. def failures - @results.select(&.is_a?(FailedResult)).map(&.as(FailedResult)) + @results.compact_map(&.as?(FailedResult)) end # Returns a set of results for all errored examples. def errors - @results.select(&.is_a?(ErroredResult)).map(&.as(ErroredResult)) + @results.compact_map(&.as?(ErroredResult)) end # Length of time it took to run just example code. # This does not include hooks, # but it does include pre- and post-conditions. def example_runtime - @results.sum do |result| - if result.is_a?(FinishedResult) - result.elapsed - else - Time::Span.zero - end - end + @results.each.compact_map(&.as?(FinishedResult)).sum(&.elapsed) end # Length of time spent in framework processes and hooks.