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

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Description of a `provided` example can be set by using `it` as an argument. [#69](https://gitlab.com/arctic-fox/spectator/-/issues/69)
## [0.10.2] - 2021-10-22
### Fixed
- Fix usage of `be ===` and `be =~` [#34](https://github.com/icy-arctic-fox/spectator/issues/34)

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