Sloppily handle deferred operations

This commit is contained in:
Michael Miller 2021-01-30 20:53:09 -07:00
parent 078058ad05
commit 82e13f5434
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD

View file

@ -58,9 +58,9 @@ module Spectator
# Runs test code and produces a result based on the outcome. # Runs test code and produces a result based on the outcome.
# The test code should be called from within the block given to this method. # The test code should be called from within the block given to this method.
def run : Result def run : Result
outcome = capture { yield } elapsed, error = capture { yield }
run_deferred # TODO: Handle errors in deferred blocks. elapsed2, error2 = run_deferred
translate(*outcome) translate(elapsed + elapsed2, error || error2)
end end
def report(expectation : Expectation) : Nil def report(expectation : Expectation) : Nil
@ -105,9 +105,15 @@ module Spectator
end end
# Runs all deferred blocks. # Runs all deferred blocks.
private def run_deferred : Nil private def run_deferred
@deferred.each(&.call) error = nil.as(Exception?)
elapsed = Time.measure do
@deferred.each(&.call)
rescue ex
error = ex
end
@deferred.clear @deferred.clear
{elapsed, error}
end end
end end
end end