Capture elapsed test time

This commit is contained in:
Michael Miller 2018-08-30 22:45:49 -06:00
parent e38fddb12a
commit f4de0ffee9
4 changed files with 22 additions and 11 deletions

View file

@ -7,8 +7,5 @@ module Spectator
def errored? : Bool
true
end
def initialize(@example, @error)
end
end
end

View file

@ -1,10 +1,11 @@
module Spectator
abstract class ExampleResult
getter example : Example
getter elapsed : Time::Span
abstract def passed? : Bool
protected def initialize(@example)
protected def initialize(@example, @elapsed)
end
end
end

View file

@ -8,7 +8,8 @@ module Spectator
false
end
def initialize(@example, @error)
def initialize(example, elapsed, @error)
super(example, elapsed)
end
end
end

View file

@ -23,12 +23,24 @@ module Spectator
end
private def run_example(example)
example.run
SuccessfulExampleResult.new(example)
rescue failure : ExpectationFailedError
FailedExampleResult.new(example, failure)
rescue ex
ErroredExampleResult.new(example, ex)
error = nil
elapsed = Time.measure do
begin
example.run
rescue failure : ExpectationFailedError
error = failure
rescue ex
error = ex
end
end
case error
when Nil
SuccessfulExampleResult.new(example, elapsed)
when ExpectationFailedError
FailedExampleResult.new(example, elapsed, error)
else
ErroredExampleResult.new(example, elapsed, error)
end
end
end
end