From 56e8f8978bde7a1d34cedded73319523d53134df Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 7 Dec 2018 23:28:30 -0700 Subject: [PATCH] Detect errors in `around_each` hooks --- src/spectator/runnable_example.cr | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/spectator/runnable_example.cr b/src/spectator/runnable_example.cr index 4edf93b..0f27c77 100644 --- a/src/spectator/runnable_example.cr +++ b/src/spectator/runnable_example.cr @@ -41,18 +41,26 @@ module Spectator wrapper = wrap_run_example(result) run_before_hooks - wrapper.call + run_wrapper(wrapper) run_after_hooks end end + private def run_wrapper(wrapper) + wrapper.call + rescue ex + # If an error occurs calling the wrapper, + # it means it came from the `around_each` hooks. + # This is because the test code is completely wrapped with a begin/rescue block. + raise Exception.new("Error encountered while running around hooks", ex) + end + # Creates a proc that runs the test code # and captures the result. private def wrap_run_example(result) : -> # Wrap the method that runs and captures # the test code with the around-each hooks. group.wrap_around_each_hooks do - # Pass along the result capture utility. run_example(result) end end