Fetch iteration item from group

This commit is contained in:
Michael Miller 2021-07-17 12:07:04 -06:00
parent c79cb62a61
commit d8e9d3128a
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 10 additions and 0 deletions

View file

@ -136,6 +136,14 @@ module Spectator::DSL
{{collection}}
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(
%collection,
::Spectator::Location.new({{block.filename}}, {{block.line_number}}),

View file

@ -2,6 +2,8 @@ require "./example_group"
module Spectator
class ExampleGroupIteration(T) < ExampleGroup
getter item : T
def initialize(@item : T, name : Label = nil, location : Location? = nil,
group : ExampleGroup? = nil, metadata : Metadata = Metadata.new)
super(name, location, group, metadata)