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 Spectator::DSL
module Examples module Examples
macro define_example(name) macro define_example(name)
macro {{name.id}}(what = nil) macro {{name.id}}(what = nil, &block)
def %test def %test
\{{yield}} \{{block.body}}
end end
%source = ::Spectator::Source.new(__FILE__, __LINE__)
::Spectator::DSL::Builder.add_example( ::Spectator::DSL::Builder.add_example(
\{{what.is_a?(StringLiteral) || what.is_a?(NilLiteral) ? what : what.stringify}}, \{{what.is_a?(StringLiteral) || what.is_a?(StringInterpolation) || what.is_a?(NilLiteral) ? what : what.stringify}},
%source, ::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
@ -25,7 +24,7 @@ module Spectator::DSL
define_example :specify define_example :specify
end 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 block.is_a?(Nop) %}
{% if description.is_a?(Call) %} {% if description.is_a?(Call) %}
def %run def %run
@ -48,11 +47,11 @@ module Spectator::DSL
) { |test| test.as({{@type.name}}).%run } ) { |test| test.as({{@type.name}}).%run }
end end
macro skip(description = nil, &block) macro skip(description = nil, &block)
pending({{description}}) {{block}} pending({{description}}) {{block}}
end end
macro xit(description = nil, &block) macro xit(description = nil, &block)
pending({{description}}) {{block}} pending({{description}}) {{block}}
end end
end end

View file

@ -8,13 +8,15 @@ module Spectator::DSL
macro define_example_group(name) macro define_example_group(name)
# Defines a new example group. # Defines a new example group.
# The *what* argument is a name or description of the 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) macro {{name.id}}(what, &block)
class Group%group < \{{@type.id}}; _spectator_group_subject(\{{what}}) class Group%group < \{{@type.id}}
# TODO: Handle string interpolation in examples and groups. _spectator_group_subject(\{{what}})
::Spectator::DSL::Builder.start_group( ::Spectator::DSL::Builder.start_group(
::Spectator::Source.new(__FILE__, __LINE__)
_spectator_group_name(\{{what}}), _spectator_group_name(\{{what}}),
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}})
) )
\{{block.body}} \{{block.body}}