Cleanup example description handling

This commit is contained in:
Michael Miller 2020-09-26 19:14:08 -06:00
parent 1d359efcb0
commit b8ba38152e
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD

View file

@ -10,13 +10,27 @@ module Spectator::DSL
end end
::Spectator::DSL::Builder.add_example( ::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}}), ::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}),
\{{@type.name}}.new \{{@type.name}}.new
) { |example, context| context.as(\{{@type.name}}).%test } ) { |example, context| context.as(\{{@type.name}}).%test }
end end
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 :example
define_example :it define_example :it