Fix after_all hooks running too soon

This commit is contained in:
Michael Miller 2018-09-12 21:31:44 -06:00
parent 77753ab974
commit 9f778c5cb9
3 changed files with 7 additions and 3 deletions

View File

@ -50,10 +50,12 @@ module Spectator
def run_after_all_hooks
unless @after_all_hooks_run
@after_all_hooks.each do |hook|
hook.call
if all_examples.all?(&.finished?)
@after_all_hooks.each do |hook|
hook.call
end
@after_all_hooks_run = true
end
@after_all_hooks_run = true
end
if (parent = @parent)
parent.run_after_all_hooks

View File

@ -161,6 +161,7 @@ module Spectator
begin
Example%example.new.%run({% for v, i in var_names %}%var{i}{% if i < var_names.size - 1 %}, {% end %}{% end %})
ensure
@finished = true
context.run_after_each_hooks
context.run_after_all_hooks
end

View File

@ -3,6 +3,7 @@ require "./source"
module Spectator
abstract class Example
getter context : Context
getter? finished = false
def initialize(@context)
end