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
abstract class Reporter
abstract def start_suite
abstract def end_suite
abstract def end_suite(report : Report)
abstract def start_example(example : Example)
abstract def end_example(result : ExampleResult)
end

View file

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

View file

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