From b8ba38152e987912c71db0ef4be3a870b77ac96b Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 26 Sep 2020 19:14:08 -0600 Subject: [PATCH] Cleanup example description handling --- src/spectator/dsl/examples.cr | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/spectator/dsl/examples.cr b/src/spectator/dsl/examples.cr index f3b5f46..82a5036 100644 --- a/src/spectator/dsl/examples.cr +++ b/src/spectator/dsl/examples.cr @@ -10,13 +10,27 @@ module Spectator::DSL end ::Spectator::DSL::Builder.add_example( - \{{what.is_a?(StringLiteral) || what.is_a?(StringInterpolation) || what.is_a?(NilLiteral) ? what : what.stringify}}, + _spectator_example_name(\{{what}}), ::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}), \{{@type.name}}.new ) { |example, context| context.as(\{{@type.name}}).%test } end end + # Inserts the correct representation of a example's name. + # If *what* is a string, then it is dropped in as-is. + # For anything else, it is stringified. + # This is intended to be used to convert a description from the spec DSL to `ExampleNode#name`. + private macro _spectator_example_name(what) + {% if what.is_a?(StringLiteral) || + what.is_a?(StringInterpolation) || + what.is_a?(NilLiteral) %} + {{what}} + {% else %} + {{what.stringify}} + {% end %} + end + define_example :example define_example :it