From 0e3727b504598490da198b4d7426670f10629fa7 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 26 Sep 2019 22:53:16 -0600 Subject: [PATCH] Run after-all hooks correctly --- src/spectator/runner.cr | 2 +- src/spectator/test_context.cr | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/spectator/runner.cr b/src/spectator/runner.cr index bf2e53c..8bde725 100644 --- a/src/spectator/runner.cr +++ b/src/spectator/runner.cr @@ -37,7 +37,7 @@ module Spectator result = run_example(example).as(Result) results << result if @config.fail_fast? && result.is_a?(FailedResult) - # TODO: example.group.run_after_all_hooks(ignore_unfinished: true) + example.group.context.run_after_all_hooks(example.group, ignore_unfinished: true) break end end diff --git a/src/spectator/test_context.cr b/src/spectator/test_context.cr index fa7a720..8d16fee 100644 --- a/src/spectator/test_context.cr +++ b/src/spectator/test_context.cr @@ -31,14 +31,18 @@ module Spectator def run_after_hooks(example : Example) run_after_each_hooks(example) - run_after_all_hooks + run_after_all_hooks(example.group) end - protected def run_after_all_hooks + protected def run_after_all_hooks(group : ExampleGroup, *, ignore_unfinished = false) return if @after_all_hooks_run + return unless ignore_unfinished || group.finished? @hooks.run_after_all - @parent.try &.run_after_all_hooks + @parent.try do |parent_context| + parent_group = group.as(NestedExampleGroup).parent + parent_context.run_after_all_hooks(parent_group, ignore_unfinished: ignore_unfinished) + end ensure @after_all_hooks_run = true end