mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
More checks for missing block in DSL
Improved some error messages.
This commit is contained in:
parent
640857bef2
commit
76a23131cb
2 changed files with 30 additions and 28 deletions
|
@ -45,7 +45,7 @@ module Spectator::DSL
|
||||||
metadata
|
metadata
|
||||||
)
|
)
|
||||||
|
|
||||||
\{{block.body}}
|
\{{block.body if block}}
|
||||||
|
|
||||||
::Spectator::DSL::Builder.end_group
|
::Spectator::DSL::Builder.end_group
|
||||||
end
|
end
|
||||||
|
@ -136,14 +136,6 @@ module Spectator::DSL
|
||||||
{{collection}}
|
{{collection}}
|
||||||
end
|
end
|
||||||
|
|
||||||
{% if block.args.size == 1 %}
|
|
||||||
let({{block.args.first}}) do |example|
|
|
||||||
example.group.as(::Spectator::ExampleGroupIteration(typeof(Group%group.%collection.first))).item
|
|
||||||
end
|
|
||||||
{% elsif block.args.size > 1 %}
|
|
||||||
{% raise "Expected 1 argument for 'sample' block, but got #{block.args.size}" %}
|
|
||||||
{% end %}
|
|
||||||
|
|
||||||
::Spectator::DSL::Builder.start_iterative_group(
|
::Spectator::DSL::Builder.start_iterative_group(
|
||||||
%collection,
|
%collection,
|
||||||
{{collection.stringify}},
|
{{collection.stringify}},
|
||||||
|
@ -152,7 +144,17 @@ module Spectator::DSL
|
||||||
metadata
|
metadata
|
||||||
)
|
)
|
||||||
|
|
||||||
{{block.body}}
|
{% if block %}
|
||||||
|
{% if block.args.size == 1 %}
|
||||||
|
let({{block.args.first}}) do |example|
|
||||||
|
example.group.as(::Spectator::ExampleGroupIteration(typeof(Group%group.%collection.first))).item
|
||||||
|
end
|
||||||
|
{% elsif block.args.size > 1 %}
|
||||||
|
{% raise "Expected 1 argument for 'sample' block, but got #{block.args.size}" %}
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{{block.body}}
|
||||||
|
{% end %}
|
||||||
|
|
||||||
::Spectator::DSL::Builder.end_group
|
::Spectator::DSL::Builder.end_group
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,9 +9,9 @@ module Spectator::DSL
|
||||||
# The block is evaluated only on the first time the getter is used
|
# The block is evaluated only on the first time the getter is used
|
||||||
# and the return value is saved for subsequent calls.
|
# and the return value is saved for subsequent calls.
|
||||||
macro let(name, &block)
|
macro let(name, &block)
|
||||||
{% raise "Block required for 'let'" unless block %}
|
{% raise "Missing block for 'let'" unless block %}
|
||||||
{% raise "Cannot use 'let' inside of a test block" if @def %}
|
{% raise "Expected zero or one arguments for 'let', but got #{block.args.size}" if block.args.size > 1 %}
|
||||||
{% raise "Block argument count for 'let' must be 0..1" if block.args.size > 1 %}
|
{% raise "Cannot use 'let' inside of an example block" if @def %}
|
||||||
{% raise "Cannot use '#{name.id}' for 'let'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
{% raise "Cannot use '#{name.id}' for 'let'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||||
|
|
||||||
@%value = ::Spectator::LazyWrapper.new
|
@%value = ::Spectator::LazyWrapper.new
|
||||||
|
@ -31,9 +31,9 @@ module Spectator::DSL
|
||||||
# The block is evaluated once before the example runs
|
# The block is evaluated once before the example runs
|
||||||
# and the return value is saved.
|
# and the return value is saved.
|
||||||
macro let!(name, &block)
|
macro let!(name, &block)
|
||||||
{% raise "Block required for 'let!'" unless block %}
|
{% raise "Missing block for 'let!'" unless block %}
|
||||||
{% raise "Cannot use 'let!' inside of a test block" if @def %}
|
{% raise "Expected zero or one arguments for 'let!', but got #{block.args.size}" if block.args.size > 1 %}
|
||||||
{% raise "Block argument count for 'let!' must be 0..1" if block.args.size > 1 %}
|
{% raise "Cannot use 'let!' inside of an example block" if @def %}
|
||||||
{% raise "Cannot use '#{name.id}' for 'let!'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
{% raise "Cannot use '#{name.id}' for 'let!'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||||
|
|
||||||
let({{name}}) {{block}}
|
let({{name}}) {{block}}
|
||||||
|
@ -45,9 +45,9 @@ module Spectator::DSL
|
||||||
# The block is evaluated only the first time the subject is referenced
|
# The block is evaluated only the first time the subject is referenced
|
||||||
# and the return value is saved for subsequent calls.
|
# and the return value is saved for subsequent calls.
|
||||||
macro subject(&block)
|
macro subject(&block)
|
||||||
{% raise "Block required for 'subject'" unless block %}
|
{% raise "Missing block for 'subject'" unless block %}
|
||||||
{% raise "Cannot use 'subject' inside of a test block" if @def %}
|
{% raise "Expected zero or one arguments for 'let!', but got #{block.args.size}" if block.args.size > 1 %}
|
||||||
{% raise "Block argument count for 'subject' must be 0..1" if block.args.size > 1 %}
|
{% raise "Cannot use 'subject' inside of an example block" if @def %}
|
||||||
|
|
||||||
let(subject) {{block}}
|
let(subject) {{block}}
|
||||||
end
|
end
|
||||||
|
@ -58,9 +58,9 @@ module Spectator::DSL
|
||||||
# The block is evaluated only the first time the subject is referenced
|
# The block is evaluated only the first time the subject is referenced
|
||||||
# and the return value is saved for subsequent calls.
|
# and the return value is saved for subsequent calls.
|
||||||
macro subject(name, &block)
|
macro subject(name, &block)
|
||||||
{% raise "Block required for 'subject'" unless block %}
|
{% raise "Missing block for 'subject'" unless block %}
|
||||||
{% raise "Cannot use 'subject' inside of a test block" if @def %}
|
{% raise "Expected zero or one arguments for 'subject', but got #{block.args.size}" if block.args.size > 1 %}
|
||||||
{% raise "Block argument count for 'subject' must be 0..1" if block.args.size > 1 %}
|
{% raise "Cannot use 'subject' inside of an example block" if @def %}
|
||||||
{% raise "Cannot use '#{name.id}' for 'subject'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
{% raise "Cannot use '#{name.id}' for 'subject'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||||
|
|
||||||
let({{name.id}}) {{block}}
|
let({{name.id}}) {{block}}
|
||||||
|
@ -77,9 +77,9 @@ module Spectator::DSL
|
||||||
# The block is evaluated once before the example runs
|
# The block is evaluated once before the example runs
|
||||||
# and the return value is saved for subsequent calls.
|
# and the return value is saved for subsequent calls.
|
||||||
macro subject!(&block)
|
macro subject!(&block)
|
||||||
{% raise "Block required for 'subject!'" unless block %}
|
{% raise "Missing block for 'subject'" unless block %}
|
||||||
{% raise "Cannot use 'subject!' inside of a test block" if @def %}
|
{% raise "Expected zero or one arguments for 'subject!', but got #{block.args.size}" if block.args.size > 1 %}
|
||||||
{% raise "Block argument count for 'subject!' must be 0..1" if block.args.size > 1 %}
|
{% raise "Cannot use 'subject!' inside of an example block" if @def %}
|
||||||
|
|
||||||
let!(subject) {{block}}
|
let!(subject) {{block}}
|
||||||
end
|
end
|
||||||
|
@ -90,9 +90,9 @@ module Spectator::DSL
|
||||||
# The block is evaluated once before the example runs
|
# The block is evaluated once before the example runs
|
||||||
# and the return value is saved for subsequent calls.
|
# and the return value is saved for subsequent calls.
|
||||||
macro subject!(name, &block)
|
macro subject!(name, &block)
|
||||||
{% raise "Block required for 'subject!'" unless block %}
|
{% raise "Missing block for 'subject'" unless block %}
|
||||||
{% raise "Cannot use 'subject!' inside of a test block" if @def %}
|
{% raise "Expected zero or one arguments for 'subject!', but got #{block.args.size}" if block.args.size > 1 %}
|
||||||
{% raise "Block argument count for 'subject!' must be 0..1" if block.args.size > 1 %}
|
{% raise "Cannot use 'subject!' inside of an example block" if @def %}
|
||||||
{% raise "Cannot use '#{name.id}' for 'subject!'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
{% raise "Cannot use '#{name.id}' for 'subject!'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||||
|
|
||||||
let!({{name.id}}) {{block}}
|
let!({{name.id}}) {{block}}
|
||||||
|
|
Loading…
Reference in a new issue