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,11 +50,13 @@ module Spectator
def run_after_all_hooks def run_after_all_hooks
unless @after_all_hooks_run unless @after_all_hooks_run
if all_examples.all?(&.finished?)
@after_all_hooks.each do |hook| @after_all_hooks.each do |hook|
hook.call hook.call
end end
@after_all_hooks_run = true @after_all_hooks_run = true
end end
end
if (parent = @parent) if (parent = @parent)
parent.run_after_all_hooks parent.run_after_all_hooks
end end

View file

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

View file

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