diff --git a/src/spectator/runnable_example.cr b/src/spectator/runnable_example.cr index d981689..9bbbbed 100644 --- a/src/spectator/runnable_example.cr +++ b/src/spectator/runnable_example.cr @@ -20,6 +20,7 @@ module Spectator context.run_before_hooks(self) run_example(result) context.run_after_hooks(self) + run_deferred(result) end end @@ -40,6 +41,17 @@ module Spectator end end + # Runs the deferred blocks of code and captures the result. + private def run_deferred(result) + result.elapsed += Time.measure do + begin + Harness.current.run_deferred + rescue ex # Catch all errors and handle them later. + result.error = ex + end + end + end + # Creates a result instance from captured result information. private def translate_result(result, expectations) case (error = result.error)