Detect errors in around_each hooks

This commit is contained in:
Michael Miller 2018-12-07 23:28:30 -07:00
parent ef12e3967b
commit 56e8f8978b

View file

@ -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