mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial implementation of invoking #around_each hooks
My brain hurts. 😖
This commit is contained in:
parent
9f778c5cb9
commit
e4d46ca603
2 changed files with 21 additions and 3 deletions
|
@ -12,7 +12,7 @@ module Spectator
|
|||
getter before_each_hooks = [] of ->
|
||||
getter after_all_hooks = [] of ->
|
||||
getter after_each_hooks = [] of ->
|
||||
getter around_each_hooks = [] of Example ->
|
||||
getter around_each_hooks = [] of Proc(Nil) ->
|
||||
|
||||
@before_all_hooks_run = false
|
||||
@after_all_hooks_run = false
|
||||
|
@ -71,6 +71,21 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
def wrap_around_each_hooks(&block : ->)
|
||||
wrapper = block
|
||||
@around_each_hooks.reverse_each do |hook|
|
||||
wrapper = wrap_proc(hook, wrapper)
|
||||
end
|
||||
if (parent = @parent)
|
||||
wrapper = parent.wrap_around_each_hooks(&wrapper)
|
||||
end
|
||||
wrapper
|
||||
end
|
||||
|
||||
private def wrap_proc(inner : Proc(Nil) ->, wrapper : ->)
|
||||
-> { inner.call(wrapper) }
|
||||
end
|
||||
|
||||
protected def add_examples(array = [] of Example)
|
||||
array.concat(@examples)
|
||||
contexts.each do |context|
|
||||
|
|
|
@ -114,7 +114,7 @@ module Spectator
|
|||
end
|
||||
|
||||
macro around_each(&block)
|
||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].around_each_hooks << -> {{block}}
|
||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].around_each_hooks << Proc(Proc(Nil), Nil).new {{block}}
|
||||
end
|
||||
|
||||
def include_examples
|
||||
|
@ -159,7 +159,10 @@ module Spectator
|
|||
context.run_before_all_hooks
|
||||
context.run_before_each_hooks
|
||||
begin
|
||||
Example%example.new.%run({% for v, i in var_names %}%var{i}{% if i < var_names.size - 1 %}, {% end %}{% end %})
|
||||
wrapper = context.wrap_around_each_hooks do
|
||||
Example%example.new.%run({% for v, i in var_names %}%var{i}{% if i < var_names.size - 1 %}, {% end %}{% end %})
|
||||
end
|
||||
wrapper.call
|
||||
ensure
|
||||
@finished = true
|
||||
context.run_after_each_hooks
|
||||
|
|
Loading…
Reference in a new issue