diff --git a/src/spectator/example_group.cr b/src/spectator/example_group.cr index 42a23f3..6e25a93 100644 --- a/src/spectator/example_group.cr +++ b/src/spectator/example_group.cr @@ -157,9 +157,10 @@ module Spectator # The hooks will be run only once, # and only after all examples in the group have finished. # Subsequent calls after the hooks have been run will do nothing. - protected def run_after_all_hooks : Nil + protected def run_after_all_hooks(ignore_unfinished = false) : Nil return if @after_all_hooks_run - return unless finished? + return unless ignore_unfinished || finished? + @hooks.run_after_all @after_all_hooks_run = true end diff --git a/src/spectator/nested_example_group.cr b/src/spectator/nested_example_group.cr index 44df61f..0a90b86 100644 --- a/src/spectator/nested_example_group.cr +++ b/src/spectator/nested_example_group.cr @@ -51,9 +51,9 @@ module Spectator # and only after all examples in the group have finished. # Subsequent calls after the hooks have been run will do nothing. # Parent "after-all" hooks will be run last. - protected def run_after_all_hooks : Nil + protected def run_after_all_hooks(ignore_unfinished = false) : Nil super - parent.run_after_all_hooks + parent.run_after_all_hooks(ignore_unfinished) end # Runs all of the "after-each" hooks. diff --git a/src/spectator/runner.cr b/src/spectator/runner.cr index f61c2f7..306f837 100644 --- a/src/spectator/runner.cr +++ b/src/spectator/runner.cr @@ -34,7 +34,10 @@ module Spectator example_order.each do |example| result = run_example(example).as(Result) results << result - break if @config.fail_fast? && result.is_a?(FailedResult) + if @config.fail_fast? && result.is_a?(FailedResult) + example.group.run_after_all_hooks(ignore_unfinished: true) + break + end end end