mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Playing around with line numbers
Trying to find some pattern in the line descripancies reported to the macros compared to the source file.
This commit is contained in:
parent
bc602d9b62
commit
9103bfde0f
4 changed files with 38 additions and 36 deletions
|
@ -25,23 +25,8 @@ module Spectator
|
||||||
# Actually, prefixing methods and macros with `Spectator`
|
# Actually, prefixing methods and macros with `Spectator`
|
||||||
# most likely won't work and can cause compiler errors.
|
# most likely won't work and can cause compiler errors.
|
||||||
macro describe(description, &block)
|
macro describe(description, &block)
|
||||||
# This macro creates the foundation for all specs.
|
|
||||||
# Every group of examples is defined a separate module - `SpectatorExamples`.
|
|
||||||
# There's multiple reasons for this.
|
|
||||||
#
|
|
||||||
# The first reason is to provide namespace isolation.
|
|
||||||
# We don't want the spec code to accidentally pickup types and values from the `Spectator` module.
|
|
||||||
# Another reason is that we need a root module to put all examples and groups in.
|
|
||||||
# And lastly, the spec DSL needs to be given to the block of code somehow.
|
|
||||||
# The DSL is included in the `SpectatorTest` class.
|
|
||||||
#
|
|
||||||
# For more information on how the DSL works, see the `DSL` module.
|
|
||||||
|
|
||||||
# Root-level class that contains all examples and example groups.
|
|
||||||
class ::SpectatorTestContext
|
class ::SpectatorTestContext
|
||||||
# Pass off the description argument and block to `DSL::StructureDSL.describe`.
|
example_group({{description}}) {{block}}
|
||||||
# That method will handle creating a new group for this spec.
|
|
||||||
describe({{description}}) {{block}}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,30 @@ require "./builder"
|
||||||
|
|
||||||
module Spectator::DSL
|
module Spectator::DSL
|
||||||
module Examples
|
module Examples
|
||||||
macro example(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro define_example(name)
|
||||||
|
macro {{name.id}}(what = nil)
|
||||||
|
def %test
|
||||||
|
\{{yield}}
|
||||||
|
end
|
||||||
|
|
||||||
|
%source = ::Spectator::Source.new(__FILE__, __LINE__)
|
||||||
|
::Spectator::DSL::Builder.add_example(
|
||||||
|
\{{what.is_a?(StringLiteral) || what.is_a?(NilLiteral) ? what : what.stringify}},
|
||||||
|
%source,
|
||||||
|
\{{@type.name}}.new
|
||||||
|
) { |example, context| context.as(\{{@type.name}}).%test }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
define_example(:example)
|
||||||
|
|
||||||
|
macro it(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
|
{% puts "#{_source_file}:#{_source_line}" %}
|
||||||
def %test
|
def %test
|
||||||
{{block.body}}
|
{{yield}}
|
||||||
end
|
end
|
||||||
|
|
||||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
%source = ::Spectator::Source.new(__FILE__, __LINE__)
|
||||||
::Spectator::DSL::Builder.add_example(
|
::Spectator::DSL::Builder.add_example(
|
||||||
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
|
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
|
||||||
%source,
|
%source,
|
||||||
|
@ -16,12 +34,18 @@ module Spectator::DSL
|
||||||
) { |example, context| context.as({{@type.name}}).%test }
|
) { |example, context| context.as({{@type.name}}).%test }
|
||||||
end
|
end
|
||||||
|
|
||||||
macro it(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
|
||||||
example({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
|
|
||||||
end
|
|
||||||
|
|
||||||
macro specify(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro specify(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
example({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
|
{% puts "#{_source_file}:#{_source_line}" %}
|
||||||
|
def %test
|
||||||
|
{{yield}}
|
||||||
|
end
|
||||||
|
|
||||||
|
%source = ::Spectator::Source.new(__FILE__, __LINE__)
|
||||||
|
::Spectator::DSL::Builder.add_example(
|
||||||
|
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
|
||||||
|
%source,
|
||||||
|
{{@type.name}}.new
|
||||||
|
) { |example, context| context.as({{@type.name}}).%test }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
macro it(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro it(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
|
|
|
@ -8,19 +8,13 @@ module Spectator::DSL
|
||||||
# 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`.
|
# If it isn't a string literal, then it is symbolized for `ExampleNode#name`.
|
||||||
macro example_group(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
|
||||||
|
|
||||||
# Example group: {{what.stringify}}
|
# Example group: {{what.stringify}}
|
||||||
# Source: {{_source_file}}:{{_source_line}}
|
# Source: {{_source_file}}:{{_source_line}}
|
||||||
class Group%group < {{@type.id}}
|
macro example_group(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
_spectator_group_subject({{what}})
|
class Group%group < {{@type.id}}; _spectator_group_subject({{what}}); ::Spectator::DSL::Builder.start_group({{what.is_a?(StringLiteral) ? what : what.stringify}}, ::Spectator::Source.new(__FILE__, __LINE__)); {{block.body}}; ::Spectator::DSL::Builder.end_group; end
|
||||||
|
{% debug(false) %}
|
||||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
|
||||||
::Spectator::DSL::Builder.start_group({{what.is_a?(StringLiteral) ? what : what.stringify}}, %source)
|
|
||||||
|
|
||||||
{{block.body}}
|
|
||||||
|
|
||||||
::Spectator::DSL::Builder.end_group
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
macro describe(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro describe(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
|
|
|
@ -42,7 +42,6 @@ module Spectator
|
||||||
def add_example(name, source, context, &block : Example, Context ->)
|
def add_example(name, source, context, &block : Example, Context ->)
|
||||||
{% if flag?(:spectator_debug) %}
|
{% if flag?(:spectator_debug) %}
|
||||||
puts "Add example: #{name} @ #{source}"
|
puts "Add example: #{name} @ #{source}"
|
||||||
puts "Context: #{context}"
|
|
||||||
{% end %}
|
{% end %}
|
||||||
delegate = ExampleContextDelegate.new(context, block)
|
delegate = ExampleContextDelegate.new(context, block)
|
||||||
Example.new(delegate, name, source, current_group)
|
Example.new(delegate, name, source, current_group)
|
||||||
|
|
Loading…
Reference in a new issue