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 def errored? : Bool
true true
end end
def initialize(@example, @error)
end
end end
end end

View file

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

View file

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

View file

@ -23,12 +23,24 @@ module Spectator
end end
private def run_example(example) private def run_example(example)
example.run error = nil
SuccessfulExampleResult.new(example) elapsed = Time.measure do
rescue failure : ExpectationFailedError begin
FailedExampleResult.new(example, failure) example.run
rescue ex rescue failure : ExpectationFailedError
ErroredExampleResult.new(example, ex) 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 end
end end