From 6b3885af309c2da217e77e6daaeaba033c7be50e Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 14 Nov 2019 18:41:26 -0700 Subject: [PATCH] Run deferred blocks --- src/spectator/runnable_example.cr | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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)