mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Pass current example as block argument
This commit is contained in:
parent
009ca4776a
commit
7451769a29
2 changed files with 22 additions and 4 deletions
|
@ -24,8 +24,9 @@ module Spectator::DSL
|
||||||
macro {{name.id}}(what = nil, &block)
|
macro {{name.id}}(what = nil, &block)
|
||||||
\{% raise "Cannot use '{{name.id}}' inside of a test block" if @def %}
|
\{% raise "Cannot use '{{name.id}}' inside of a test block" if @def %}
|
||||||
\{% raise "A description or block must be provided. Cannot use '{{name.id}}' alone." unless what || block %}
|
\{% raise "A description or block must be provided. Cannot use '{{name.id}}' alone." unless what || block %}
|
||||||
|
\{% raise "Block argument count '{{name.id}}' hook must be 0..1" if block.args.size > 1 %}
|
||||||
|
|
||||||
def \%test : Nil # TODO: Pass example instance.
|
def \%test(\{{block.args.splat}}) : Nil
|
||||||
\{{block.body}}
|
\{{block.body}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,7 +34,15 @@ module Spectator::DSL
|
||||||
_spectator_example_name(\{{what}}),
|
_spectator_example_name(\{{what}}),
|
||||||
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}),
|
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}),
|
||||||
\{{@type.name}}.new.as(::Spectator::Context)
|
\{{@type.name}}.new.as(::Spectator::Context)
|
||||||
) { |example| example.with_context(\{{@type.name}}) { \%test } }
|
) do |example|
|
||||||
|
example.with_context(\{{@type.name}}) do
|
||||||
|
\{% if block.args.empty? %}
|
||||||
|
\%test
|
||||||
|
\{% else %}
|
||||||
|
\%test(example)
|
||||||
|
\{% end %}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -26,15 +26,24 @@ module Spectator::DSL
|
||||||
macro define_example_hook(type)
|
macro define_example_hook(type)
|
||||||
macro {{type.id}}(&block)
|
macro {{type.id}}(&block)
|
||||||
\{% raise "Missing block for '{{type.id}}' hook" unless block %}
|
\{% raise "Missing block for '{{type.id}}' hook" unless block %}
|
||||||
|
\{% raise "Block argument count '{{type.id}}' hook must be 0..1" if block.args.size > 1 %}
|
||||||
\{% raise "Cannot use '{{type.id}}' inside of a test block" if @def %}
|
\{% raise "Cannot use '{{type.id}}' inside of a test block" if @def %}
|
||||||
|
|
||||||
def \%hook : Nil # TODO: Pass example instance.
|
def \%hook(\{{block.args.splat}}) : Nil
|
||||||
\{{block.body}}
|
\{{block.body}}
|
||||||
end
|
end
|
||||||
|
|
||||||
::Spectator::DSL::Builder.{{type.id}}(
|
::Spectator::DSL::Builder.{{type.id}}(
|
||||||
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}})
|
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}})
|
||||||
) { |example| example.with_context(\{{@type.name}}) { \%hook } }
|
) do |example|
|
||||||
|
example.with_context(\{{@type.name}}) do
|
||||||
|
\{% if block.args.empty? %}
|
||||||
|
\%hook
|
||||||
|
\{% else %}
|
||||||
|
\%hook(example)
|
||||||
|
\{% end %}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue