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
This commit is contained in:
Michael Miller 2020-09-17 09:35:49 -06:00
parent 4a7e0c8bd7
commit a0af1e7cd1
No known key found for this signature in database
GPG Key ID: FB9F12F7C646A4AD
3 changed files with 5 additions and 5 deletions

View File

@ -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 }

View File

@ -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

View File

@ -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 %}
{%