mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Improve source line detection
This commit is contained in:
parent
1ad41ac016
commit
1d359efcb0
2 changed files with 13 additions and 12 deletions
|
@ -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
|
||||||
|
|
|
@ -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}}
|
||||||
|
|
Loading…
Reference in a new issue