From 2ff8ebb3cb18a503f26a363c03e0d28a21db4d39 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 10 Sep 2018 21:27:24 -0600 Subject: [PATCH] Implement creation of hooks --- src/spectator/context.cr | 5 +++++ src/spectator/dsl.cr | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/spectator/context.cr b/src/spectator/context.cr index 61afbd9..4a78092 100644 --- a/src/spectator/context.cr +++ b/src/spectator/context.cr @@ -4,6 +4,11 @@ module Spectator class Context getter examples = [] of Example getter contexts = [] of Context + getter before_all_hooks = [] of -> + getter before_each_hooks = [] of -> + getter after_all_hooks = [] of -> + getter after_each_hooks = [] of -> + getter around_each_hooks = [] of Example -> def all_examples add_examples diff --git a/src/spectator/dsl.cr b/src/spectator/dsl.cr index 882fbb8..9aeb834 100644 --- a/src/spectator/dsl.cr +++ b/src/spectator/dsl.cr @@ -139,24 +139,24 @@ module Spectator end end - def before_all - raise NotImplementedError.new("Spectator::DSL#before_all") + macro before_all(&block) + CURRENT_CONTEXT.before_all_hooks << -> {{block}} end - def before_each - raise NotImplementedError.new("Spectator::DSL#before_each") + macro before_each(&block) + CURRENT_CONTEXT.before_each_hooks << -> {{block}} end - def after_all - raise NotImplementedError.new("Spectator::DSL#after_all") + macro after_all(&block) + CURRENT_CONTEXT.after_all_hooks << -> {{block}} end - def after_each - raise NotImplementedError.new("Spectator::DSL#after_each") + macro after_each(&block) + CURRENT_CONTEXT.after_each_hooks << -> {{block}} end - def around_each - raise NotImplementedError.new("Spectator::DSL#around_each") + macro around_each(&block) + CURRENT_CONTEXT.around_each_hooks << -> {{block}} end def include_examples