Fix flipped append/prepend of "after" hooks

This commit is contained in:
Michael Miller 2021-08-08 10:27:34 -06:00
parent b9f0a31a4a
commit 841efc236d
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 7 additions and 7 deletions

View file

@ -26,7 +26,7 @@ module Spectator
before_all_hooks.each &.call_once before_all_hooks.each &.call_once
end end
define_hook after_all : ExampleGroupHook do define_hook after_all : ExampleGroupHook, :prepend do
Log.trace { "Processing after_all hooks for #{self}" } Log.trace { "Processing after_all hooks for #{self}" }
after_all_hooks.each &.call_once if finished? after_all_hooks.each &.call_once if finished?
@ -42,7 +42,7 @@ module Spectator
before_each_hooks.each &.call(example) before_each_hooks.each &.call(example)
end end
define_hook after_each : ExampleHook do |example| define_hook after_each : ExampleHook, :prepend do |example|
Log.trace { "Processing after_each hooks for #{self}" } Log.trace { "Processing after_each hooks for #{self}" }
after_each_hooks.each &.call(example) after_each_hooks.each &.call(example)

View file

@ -50,8 +50,8 @@ module Spectator
private def apply_hooks(group) private def apply_hooks(group)
before_all_hooks.each { |hook| group.before_all(hook) } before_all_hooks.each { |hook| group.before_all(hook) }
before_each_hooks.each { |hook| group.before_each(hook) } before_each_hooks.each { |hook| group.before_each(hook) }
after_all_hooks.each { |hook| group.after_all(hook) } after_all_hooks.reverse_each { |hook| group.after_all(hook) }
after_each_hooks.each { |hook| group.after_each(hook) } after_each_hooks.reverse_each { |hook| group.after_each(hook) }
around_each_hooks.each { |hook| group.around_each(hook) } around_each_hooks.each { |hook| group.around_each(hook) }
end end
end end

View file

@ -236,9 +236,9 @@ module Spectator
# Copy all hooks from config to top-level group. # Copy all hooks from config to top-level group.
private def apply_config_hooks(group) private def apply_config_hooks(group)
config.before_suite_hooks.reverse_each { |hook| group.prepend_before_all(hook) } config.before_suite_hooks.reverse_each { |hook| group.prepend_before_all(hook) }
config.after_suite_hooks.each { |hook| group.after_all(hook) } config.after_suite_hooks.each { |hook| group.append_after_all(hook) }
config.before_each_hooks.reverse_each { |hook| group.prepend_before_each(hook) } config.before_each_hooks.reverse_each { |hook| group.prepend_before_each(hook) }
config.after_each_hooks.each { |hook| group.after_each(hook) } config.after_each_hooks.each { |hook| group.append_after_each(hook) }
config.around_each_hooks.reverse_each { |hook| group.prepend_around_each(hook) } config.around_each_hooks.reverse_each { |hook| group.prepend_around_each(hook) }
# `before_all` and `after_all` hooks from config are slightly different. # `before_all` and `after_all` hooks from config are slightly different.
@ -247,7 +247,7 @@ module Spectator
next unless node.is_a?(Hooks) next unless node.is_a?(Hooks)
config.before_all_hooks.reverse_each { |hook| node.prepend_before_all(hook.dup) } config.before_all_hooks.reverse_each { |hook| node.prepend_before_all(hook.dup) }
config.after_all_hooks.each { |hook| node.after_all(hook.dup) } config.after_all_hooks.each { |hook| node.append_after_all(hook.dup) }
end end
end end
end end