Add report for suite results

This commit is contained in:
Michael Miller 2018-08-30 23:38:20 -06:00
parent 9d39bc80b1
commit b8dcf35165
4 changed files with 40 additions and 8 deletions

27
src/spectator/report.cr Normal file
View file

@ -0,0 +1,27 @@
module Spectator
class Report
getter runtime : Time::Span
@results : Array(ExampleResult)
def initialize(results : Enumerable(ExampleResult), @runtime)
@results = results.to_a
end
def successful_examples
@results.select { |result| result.successful? }
end
def failed_examples
@results.select { |result| result.failed? }
end
def example_runtime
@results.map { |result| result.elapsed }.sum
end
def overhead_time
@runtime - example_runtime
end
end
end

View file

@ -2,7 +2,7 @@ module Spectator
module Reporters module Reporters
abstract class Reporter abstract class Reporter
abstract def start_suite abstract def start_suite
abstract def end_suite abstract def end_suite(report : Report)
abstract def start_example(example : Example) abstract def start_example(example : Example)
abstract def end_example(result : ExampleResult) abstract def end_example(result : ExampleResult)
end end

View file

@ -7,7 +7,7 @@ module Spectator
def start_suite def start_suite
end end
def end_suite def end_suite(report : Report)
puts puts
end end

View file

@ -9,13 +9,18 @@ module Spectator
end end
def run : Nil def run : Nil
@reporter.start_suite results = [] of ExampleResult
sorted_examples.each do |example| elapsed = Time.measure do
@reporter.start_example(example) @reporter.start_suite
result = run_example(example) results = sorted_examples.map do |example|
@reporter.end_example(result) @reporter.start_example(example)
run_example(example).tap do |result|
@reporter.end_example(result)
end
end
end end
@reporter.end_suite report = Report.new(results, elapsed)
@reporter.end_suite(report)
end end
private def sorted_examples private def sorted_examples