Explicit "provided" block description

Implements https://gitlab.com/arctic-fox/spectator/-/issues/69
This commit is contained in:
Michael Miller 2021-12-01 19:11:36 -07:00
parent 01f9499828
commit 315a318d7d
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
2 changed files with 17 additions and 4 deletions

View file

@ -14,8 +14,9 @@ module Spectator::DSL
# Tags and metadata cannot be used with this macro.
#
# ```
# given x = 42 do
# provided x = 42, y: 123 do
# expect(x).to eq(42)
# expect(y).to eq(123)
# end
# ```
macro provided(*assignments, **kwargs, &block)
@ -26,13 +27,21 @@ module Spectator::DSL
let({{assignment.target}}) { {{assignment.value}} }
{% end %}
{% for name, value in kwargs %}
let({{name}}) { {{value}} }
{% if name != :it %}let({{name}}) { {{value}} }{% end %}
{% end %}
{% if block %}
example {{block}}
{% if description = kwargs[:it] %}
example {{description}} {{block}}
{% else %}
example {{block}}
{% end %}
{% else %}
example {{assignments.splat.stringify}}
{% if description = kwargs[:it] %}
example {{description}} {{block}}
{% else %}
example {{assignments.splat.stringify}}
{% end %}
{% end %}
end
end