Run after-all hooks correctly

This commit is contained in:
Michael Miller 2019-09-26 22:53:16 -06:00
parent 95fa9b39b2
commit 0e3727b504
2 changed files with 8 additions and 4 deletions

View file

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

View file

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