Initial work on hooks rework

This commit is contained in:
Michael Miller 2020-11-07 22:04:37 -07:00
parent 1f319a70ce
commit 688c08b087
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436

View file

@ -1,5 +1,39 @@
module Spectator
module DSL
module Spectator::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)
def %hook({{block.args.splat}}) : Nil
{{block.body}}