mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove direct references to Example in ExampleGroup
This commit is contained in:
parent
ef7fca3f95
commit
d292c01e74
2 changed files with 9 additions and 4 deletions
|
@ -180,6 +180,11 @@ module Spectator
|
||||||
json.string(to_s)
|
json.string(to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Creates a procsy from this example and the provided block.
|
||||||
|
def procsy(&block : ->)
|
||||||
|
Procsy.new(self, &block)
|
||||||
|
end
|
||||||
|
|
||||||
# Wraps an example to behave like a `Proc`.
|
# Wraps an example to behave like a `Proc`.
|
||||||
# This is typically used for an *around_each* hook.
|
# This is typically used for an *around_each* hook.
|
||||||
# Invoking `#call` or `#run` will run the example.
|
# Invoking `#call` or `#run` will run the example.
|
||||||
|
|
|
@ -163,26 +163,26 @@ module Spectator
|
||||||
# Defines a hook for the *around_each* event.
|
# Defines a hook for the *around_each* event.
|
||||||
# The block of code given to this method is invoked when the event occurs.
|
# The block of code given to this method is invoked when the event occurs.
|
||||||
# The current example is provided as a block argument.
|
# The current example is provided as a block argument.
|
||||||
def around_each(&block : Example::Procsy ->) : Nil
|
def around_each(&block) : Nil
|
||||||
hook = ExampleProcsyHook.new(label: "around_each", &block)
|
hook = ExampleProcsyHook.new(label: "around_each", &block)
|
||||||
add_around_each_hook(hook)
|
add_around_each_hook(hook)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Signals that the *around_each* event has occurred.
|
# Signals that the *around_each* event has occurred.
|
||||||
# All hooks associated with the event will be called.
|
# All hooks associated with the event will be called.
|
||||||
def call_around_each(example : Example, &block : -> _) : Nil
|
def call_around_each(example, &block : -> _) : Nil
|
||||||
# Avoid overhead if there's no hooks.
|
# Avoid overhead if there's no hooks.
|
||||||
return yield if @around_hooks.empty?
|
return yield if @around_hooks.empty?
|
||||||
|
|
||||||
# Start with a procsy that wraps the original code.
|
# Start with a procsy that wraps the original code.
|
||||||
procsy = Example::Procsy.new(example, &block)
|
procsy = example.procsy(&block)
|
||||||
procsy = wrap_around_each(procsy)
|
procsy = wrap_around_each(procsy)
|
||||||
procsy.call
|
procsy.call
|
||||||
end
|
end
|
||||||
|
|
||||||
# Wraps a procsy with the *around_each* hooks from this example group.
|
# Wraps a procsy with the *around_each* hooks from this example group.
|
||||||
# The returned procsy will call each hook then *procsy*.
|
# The returned procsy will call each hook then *procsy*.
|
||||||
protected def wrap_around_each(procsy : Example::Procsy) : Example::Procsy
|
protected def wrap_around_each(procsy)
|
||||||
# Avoid overhead if there's no hooks.
|
# Avoid overhead if there's no hooks.
|
||||||
return procsy if @around_hooks.empty?
|
return procsy if @around_hooks.empty?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue