diff --git a/src/spectator/example_group.cr b/src/spectator/example_group.cr index 2482618..ab27112 100644 --- a/src/spectator/example_group.cr +++ b/src/spectator/example_group.cr @@ -15,13 +15,19 @@ module Spectator parent.call_once_before_all end - hooks.each(&.call) + hooks.each do |hook| + Log.trace { "Invoking hook #{hook}" } + hook.call + end end group_event after_all do |hooks| Log.trace { "Processing after_all hooks" } - hooks.each(&.call) + hooks.each do |hook| + Log.trace { "Invoking hook #{hook}" } + hook.call + end if (parent = group?) parent.call_once_after_all @@ -35,13 +41,19 @@ module Spectator parent.call_before_each(example) end - hooks.each(&.call(example)) + hooks.each do |hook| + Log.trace { "Invoking hook #{hook}" } + hook.call(example) + end end example_event after_each do |hooks, example| Log.trace { "Processing after_each hooks" } - hooks.each(&.call(example)) + hooks.each do |hook| + Log.trace { "Invoking hook #{hook}" } + hook.call(example) + end if (parent = group?) parent.call_after_each(example) diff --git a/src/spectator/example_group_hook.cr b/src/spectator/example_group_hook.cr index 4748b2a..11b0117 100644 --- a/src/spectator/example_group_hook.cr +++ b/src/spectator/example_group_hook.cr @@ -28,5 +28,21 @@ module Spectator def call : Nil @delegate.call end + + # Produces the string representation of the hook. + # Includes the source and label if they're not nil. + def to_s(io) + io << "example group hook" + + if (label = @label) + io << ' ' + io << label + end + + if (source = @source) + io << " @ " + io << source + end + end end end diff --git a/src/spectator/example_hook.cr b/src/spectator/example_hook.cr index b169b9d..4597981 100644 --- a/src/spectator/example_hook.cr +++ b/src/spectator/example_hook.cr @@ -30,5 +30,21 @@ module Spectator def call(example : Example) : Nil @delegate.call(example) end + + # Produces the string representation of the hook. + # Includes the source and label if they're not nil. + def to_s(io) + io << "example hook" + + if (label = @label) + io << ' ' + io << label + end + + if (source = @source) + io << " @ " + io << source + end + end end end