mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow "it" syntax in #given block
This commit is contained in:
parent
17039d44f0
commit
ab90f946d9
1 changed files with 21 additions and 2 deletions
|
@ -382,6 +382,18 @@ module Spectator::DSL
|
||||||
# it expect(x).to eq(1)
|
# it expect(x).to eq(1)
|
||||||
# end
|
# end
|
||||||
# ```
|
# ```
|
||||||
|
#
|
||||||
|
# Additionally, the "it" syntax can be used and mixed in.
|
||||||
|
# This allows for flexibility and a more readable format when needed.
|
||||||
|
# ```
|
||||||
|
# given x = 1 do
|
||||||
|
# it "is odd" do
|
||||||
|
# expect(x.odd?).to be_true
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# it is(&.odd?)
|
||||||
|
# end
|
||||||
|
# ```
|
||||||
macro given(*assignments, &block)
|
macro given(*assignments, &block)
|
||||||
context({{assignments.splat.stringify}}) do
|
context({{assignments.splat.stringify}}) do
|
||||||
# Create a `let` entry for each assignment.
|
# Create a `let` entry for each assignment.
|
||||||
|
@ -403,10 +415,17 @@ module Spectator::DSL
|
||||||
end
|
end
|
||||||
%}
|
%}
|
||||||
|
|
||||||
# Create a one-liner "it" for each expression.
|
# Transform every item in the block to a test case.
|
||||||
{% for item in body %}
|
{% for item in body %}
|
||||||
|
# If the item starts with "it", then leave it as-is.
|
||||||
|
# Otherwise, prefix it with "it"
|
||||||
|
# and treat it as the one-liner "it" syntax.
|
||||||
|
{% if item.is_a?(Call) && item.name == "it".id %}
|
||||||
|
{{item}}
|
||||||
|
{% else %}
|
||||||
it {{item}}
|
it {{item}}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
{% end %}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue