mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Some DSL methods for hooks
This commit is contained in:
parent
7002564ebd
commit
52ef5e5ced
3 changed files with 62 additions and 2 deletions
35
src/spectator/dsl/hooks.cr
Normal file
35
src/spectator/dsl/hooks.cr
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Spectator
|
||||
module DSL
|
||||
macro before_each(&block)
|
||||
def %hook : Nil
|
||||
{{block.body}}
|
||||
end
|
||||
|
||||
::Spectator::SpecBuilder.add_before_each_hook { |test| test.as({{@type.id}}).%hook }
|
||||
end
|
||||
|
||||
macro after_each(&block)
|
||||
def %hook : Nil
|
||||
{{block.body}}
|
||||
end
|
||||
|
||||
::Spectator::SpecBuilder.add_after_each_hook { |test| test.as({{@type.id}}).%hook }
|
||||
end
|
||||
|
||||
macro before_all(&block)
|
||||
::Spectator::SpecBuilder.add_before_all_hook {{block}}
|
||||
end
|
||||
|
||||
macro after_all(&block)
|
||||
::Spectator::SpecBuilder.add_after_all_hook {{block}}
|
||||
end
|
||||
|
||||
macro around_each(&block)
|
||||
def %hook({{block.args.splat}}) : Nil
|
||||
{{block.body}}
|
||||
end
|
||||
|
||||
# TODO: Handle wrapping proc and test together.
|
||||
end
|
||||
end
|
||||
end
|
|
@ -56,7 +56,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Adds a block of code to run before each example in the current group.
|
||||
def add_before_each_hook(&block : ->) : Nil
|
||||
def add_before_each_hook(&block : TestMethod) : Nil
|
||||
@@stack.current.add_before_each_hook(block)
|
||||
end
|
||||
|
||||
|
@ -66,7 +66,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Adds a block of code to run after each example in the current group.
|
||||
def add_after_each_hook(&block : ->) : Nil
|
||||
def add_after_each_hook(&block : TestMethod) : Nil
|
||||
@@stack.current.add_after_each_hook(block)
|
||||
end
|
||||
|
||||
|
|
|
@ -6,8 +6,33 @@ module Spectator::SpecBuilder
|
|||
|
||||
private getter children = [] of Child
|
||||
|
||||
@before_each_hooks = Deque(TestMethod).new
|
||||
@after_each_hooks = Deque(TestMethod).new
|
||||
@before_all_hooks = Deque(->).new
|
||||
@after_all_hooks = Deque(->).new
|
||||
|
||||
def add_child(child : Child)
|
||||
@children << child
|
||||
end
|
||||
|
||||
def add_before_each_hook(hook : TestMethod)
|
||||
@before_each_hooks << hook
|
||||
end
|
||||
|
||||
def add_after_each_hook(hook : TestMethod)
|
||||
@after_each_hooks << hook
|
||||
end
|
||||
|
||||
def add_before_all_hook(hook : ->)
|
||||
@before_all_hooks << hook
|
||||
end
|
||||
|
||||
def add_after_all_hook(hook : ->)
|
||||
@after_all_hooks << hook
|
||||
end
|
||||
|
||||
private def build_hooks
|
||||
ExampleHooks.empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue