From 4567162459be16959a8e796a543464213158952c Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 26 Sep 2020 19:23:57 -0600 Subject: [PATCH] Prevent defining an example or group in a test --- src/spectator/dsl/examples.cr | 2 ++ src/spectator/dsl/groups.cr | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/spectator/dsl/examples.cr b/src/spectator/dsl/examples.cr index 76edc15..0082fc5 100644 --- a/src/spectator/dsl/examples.cr +++ b/src/spectator/dsl/examples.cr @@ -5,6 +5,8 @@ module Spectator::DSL module Examples macro define_example(name) macro {{name.id}}(what = nil, &block) + \{% raise "Cannot use '{{name.id}}' inside of a test block" if @def %} + def %test \{{block.body}} end diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index 8dcbe81..2d82ecf 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -11,6 +11,8 @@ module Spectator::DSL # # TODO: Handle string interpolation in example and group names. macro {{name.id}}(what, &block) + \{% raise "Cannot use '{{name.id}}' inside of a test block" if @def %} + class Group%group < \{{@type.id}} _spectator_group_subject(\{{what}})