Trace hook invocation

This commit is contained in:
Michael Miller 2021-01-09 11:14:27 -07:00
parent e5cbc8d631
commit def66acc15
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 48 additions and 4 deletions

View file

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

View file

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

View file

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