From a0af1e7cd19859438e3966bd6d6ce6864639ac70 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 17 Sep 2020 09:35:49 -0600 Subject: [PATCH] Allow string interpolation in some macros Enables interpolation in example and group descriptions, as well as anonymous doubles. Addresses https://github.com/icy-arctic-fox/spectator/issues/10 --- src/spectator/dsl/examples.cr | 4 ++-- src/spectator/dsl/groups.cr | 2 +- src/spectator/dsl/mocks.cr | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/spectator/dsl/examples.cr b/src/spectator/dsl/examples.cr index b356ea5..bcb1425 100644 --- a/src/spectator/dsl/examples.cr +++ b/src/spectator/dsl/examples.cr @@ -20,7 +20,7 @@ module Spectator %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}}) ::Spectator::SpecBuilder.add_example( - {{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}}, + {{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}}, %source, {{@type.name}} ) { |test| test.as({{@type.name}}).%run } @@ -47,7 +47,7 @@ module Spectator %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}}) ::Spectator::SpecBuilder.add_pending_example( - {{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}}, + {{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}}, %source, {{@type.name}} ) { |test| test.as({{@type.name}}).%run } diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index 0ad5f72..5a37715 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -5,7 +5,7 @@ module Spectator macro context(what, _source_file = __FILE__, _source_line = __LINE__, &block) class Context%context < {{@type.id}} {% - description = if what.is_a?(StringLiteral) + description = if what.is_a?(StringLiteral) || what.is_a?(StringInterpolation) if what.starts_with?("#") || what.starts_with?(".") what.id.symbolize else diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index 07d3c00..7ffcfc8 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -2,7 +2,7 @@ require "../mocks" module Spectator::DSL macro double(name = "Anonymous", **stubs, &block) - {% if name.is_a?(StringLiteral) %} + {% if name.is_a?(StringLiteral) || name.is_a?(StringInterpolation) %} anonymous_double({{name}}, {{stubs.double_splat}}) {% else %} {% @@ -56,7 +56,7 @@ module Spectator::DSL end macro null_double(name, **stubs, &block) - {% if name.is_a?(StringLiteral) %} + {% if name.is_a?(StringLiteral) || name.is_a?(StringInterpolation) %} anonymous_null_double({{name}}, {{stubs.double_splat}}) {% else %} {%