Cleanup group description handling

This commit is contained in:
Michael Miller 2020-09-26 19:11:52 -06:00
parent cccfa8ea1d
commit 1ad41ac016
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD

View file

@ -13,8 +13,8 @@ module Spectator::DSL
class Group%group < \{{@type.id}}; _spectator_group_subject(\{{what}})
# TODO: Handle string interpolation in examples and groups.
::Spectator::DSL::Builder.start_group(
\{{what.is_a?(StringLiteral) ? what : what.stringify}},
::Spectator::Source.new(__FILE__, __LINE__)
_spectator_group_name(\{{what}}),
)
\{{block.body}}
@ -24,6 +24,27 @@ module Spectator::DSL
end
end
# Inserts the correct representation of a group's name.
# If *what* appears to be a type name, it will be symbolized.
# If it's 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_group_name(what)
{% if (what.is_a?(Generic) ||
what.is_a?(Path) ||
what.is_a?(TypeNode) ||
what.is_a?(Union)) &&
(described_type = what.resolve?).is_a?(TypeNode) %}
{{what.symbolize}}
{% elsif what.is_a?(StringLiteral) ||
what.is_a?(StringInterpolation) ||
what.is_a?(NilLiteral) %}
{{what}}
{% else %}
{{what.stringify}}
{% end %}
end
define_example_group :example_group
define_example_group :describe