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}}) %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
::Spectator::SpecBuilder.add_example( ::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, %source,
{{@type.name}} {{@type.name}}
) { |test| test.as({{@type.name}}).%run } ) { |test| test.as({{@type.name}}).%run }
@ -47,7 +47,7 @@ module Spectator
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}}) %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
::Spectator::SpecBuilder.add_pending_example( ::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, %source,
{{@type.name}} {{@type.name}}
) { |test| test.as({{@type.name}}).%run } ) { |test| test.as({{@type.name}}).%run }

View file

@ -5,7 +5,7 @@ module Spectator
macro context(what, _source_file = __FILE__, _source_line = __LINE__, &block) macro context(what, _source_file = __FILE__, _source_line = __LINE__, &block)
class Context%context < {{@type.id}} 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?(".") if what.starts_with?("#") || what.starts_with?(".")
what.id.symbolize what.id.symbolize
else else

View file

@ -2,7 +2,7 @@ require "../mocks"
module Spectator::DSL module Spectator::DSL
macro double(name = "Anonymous", **stubs, &block) 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}}) anonymous_double({{name}}, {{stubs.double_splat}})
{% else %} {% else %}
{% {%
@ -56,7 +56,7 @@ module Spectator::DSL
end end
macro null_double(name, **stubs, &block) 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}}) anonymous_null_double({{name}}, {{stubs.double_splat}})
{% else %} {% else %}
{% {%