mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial work on hooks rework
This commit is contained in:
parent
1f319a70ce
commit
688c08b087
1 changed files with 36 additions and 2 deletions
|
@ -1,5 +1,39 @@
|
||||||
module Spectator
|
module Spectator::DSL
|
||||||
module DSL
|
# DSL methods for adding custom logic to key times of the spec execution.
|
||||||
|
module Hooks
|
||||||
|
# Defines code to run before any and all examples in an example group.
|
||||||
|
macro before_all(&block)
|
||||||
|
{% raise "Cannot use 'before_all' inside of a test block" if @def %}
|
||||||
|
|
||||||
|
def self.%hook : Nil
|
||||||
|
{{block.body}}
|
||||||
|
end
|
||||||
|
|
||||||
|
::Spectator::DSL::Builder.add_hook(
|
||||||
|
:before
|
||||||
|
) { {{@type.name}.%hook }
|
||||||
|
end
|
||||||
|
|
||||||
|
macro before_each(&block)
|
||||||
|
{% raise "Cannot use 'before_each' inside of a test block" if @def %}
|
||||||
|
|
||||||
|
def %hook : Nil
|
||||||
|
{{block.body}}
|
||||||
|
end
|
||||||
|
|
||||||
|
::Spectator::DSL::Builder.add_context_hook(
|
||||||
|
:before,
|
||||||
|
{{@type.name}}
|
||||||
|
) { |context| context.as({{@type.name}).%hook }
|
||||||
|
end
|
||||||
|
|
||||||
|
macro after_all(&block)
|
||||||
|
end
|
||||||
|
|
||||||
|
macro after_each(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
macro before_each(&block)
|
macro before_each(&block)
|
||||||
def %hook({{block.args.splat}}) : Nil
|
def %hook({{block.args.splat}}) : Nil
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
|
|
Loading…
Reference in a new issue