Improve source line detection

This commit is contained in:
Michael Miller 2020-09-26 19:12:42 -06:00
parent 1ad41ac016
commit 1d359efcb0
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 13 additions and 12 deletions

View file

@ -4,15 +4,14 @@ require "./builder"
module Spectator::DSL
module Examples
macro define_example(name)
macro {{name.id}}(what = nil)
macro {{name.id}}(what = nil, &block)
def %test
\{{yield}}
\{{block.body}}
end
%source = ::Spectator::Source.new(__FILE__, __LINE__)
::Spectator::DSL::Builder.add_example(
\{{what.is_a?(StringLiteral) || what.is_a?(NilLiteral) ? what : what.stringify}},
%source,
\{{what.is_a?(StringLiteral) || what.is_a?(StringInterpolation) || what.is_a?(NilLiteral) ? what : what.stringify}},
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}),
\{{@type.name}}.new
) { |example, context| context.as(\{{@type.name}}).%test }
end

View file

@ -8,13 +8,15 @@ module Spectator::DSL
macro define_example_group(name)
# Defines a new example group.
# The *what* argument is a name or description of the group.
# If it isn't a string literal, then it is symbolized for `ExampleNode#name`.
#
# TODO: Handle string interpolation in example and group names.
macro {{name.id}}(what, &block)
class Group%group < \{{@type.id}}; _spectator_group_subject(\{{what}})
# TODO: Handle string interpolation in examples and groups.
class Group%group < \{{@type.id}}
_spectator_group_subject(\{{what}})
::Spectator::DSL::Builder.start_group(
::Spectator::Source.new(__FILE__, __LINE__)
_spectator_group_name(\{{what}}),
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}})
)
\{{block.body}}