mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Fix sample iteration with single block arg (not tuple)
This commit is contained in:
parent
4e7318b964
commit
92e839415d
3 changed files with 43 additions and 3 deletions
|
@ -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]
|
||||
###
|
||||
- Fixed usage of `sample` with single block argument. [#41](https://github.com/icy-arctic-fox/spectator/issues/41#issuecomment-1022525702)
|
||||
|
||||
## [0.10.4] - 2022-01-11
|
||||
### Added
|
||||
- Support string interpolation for example name/description. [#41](https://github.com/icy-arctic-fox/spectator/issues/41)
|
||||
|
|
30
spec/issues/github_issue_41_spec.cr
Normal file
30
spec/issues/github_issue_41_spec.cr
Normal file
|
@ -0,0 +1,30 @@
|
|||
require "../spec_helper"
|
||||
|
||||
Spectator.describe "GitHub Issue #41" do
|
||||
sample [1, 2, 3] do |i|
|
||||
it "is itself" do
|
||||
expect(i).to eq i
|
||||
end
|
||||
end
|
||||
|
||||
def self.an_array
|
||||
[1, 2, 3]
|
||||
end
|
||||
|
||||
sample an_array do |i|
|
||||
it "is itself" do
|
||||
expect(i).to eq(i)
|
||||
end
|
||||
end
|
||||
|
||||
# NOTE: NamedTuple does not work, must be Enumerable(T) for `sample`.
|
||||
def self.a_hash
|
||||
{:a => "a", :b => "b", :c => "c"}
|
||||
end
|
||||
|
||||
sample a_hash do |k, v|
|
||||
it "works on hashes" do
|
||||
expect(v).to eq(k.to_s)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -101,9 +101,15 @@ module Spectator::DSL
|
|||
)
|
||||
|
||||
\{% if block %}
|
||||
\{% for arg, i in block.args %}
|
||||
let(\{{arg}}) do |example|
|
||||
example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item[\{{i}}]
|
||||
\{% if block.args.size > 1 %}
|
||||
\{% for arg, i in block.args %}
|
||||
let(\{{arg}}) do |example|
|
||||
example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item[\{{i}}]
|
||||
end
|
||||
\{% end %}
|
||||
\{% else %}
|
||||
let(\{{block.args[0]}}) do |example|
|
||||
example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item
|
||||
end
|
||||
\{% end %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue