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
@ -25,7 +24,7 @@ module Spectator::DSL
define_example :specify
end
macro pending(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
macro pending(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
{% if block.is_a?(Nop) %}
{% if description.is_a?(Call) %}
def %run
@ -48,11 +47,11 @@ module Spectator::DSL
) { |test| test.as({{@type.name}}).%run }
end
macro skip(description = nil, &block)
macro skip(description = nil, &block)
pending({{description}}) {{block}}
end
macro xit(description = nil, &block)
macro xit(description = nil, &block)
pending({{description}}) {{block}}
end
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}}