mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle collection for sample group
This commit is contained in:
parent
cd0ba81417
commit
e5bd582f5f
3 changed files with 14 additions and 9 deletions
|
@ -35,7 +35,10 @@ module Spectator
|
|||
end
|
||||
|
||||
class Context%sample < {{@type.id}}
|
||||
::Spectator::SpecBuilder.start_sample_group({{what.stringify}})
|
||||
::Spectator::SpecBuilder.start_sample_group({{what.stringify}}, :%sample) do |values|
|
||||
sample = Sample%sample.new(values)
|
||||
sample.%collection.to_a
|
||||
end
|
||||
|
||||
def {{block_arg}}
|
||||
1
|
||||
|
|
|
@ -26,8 +26,8 @@ module Spectator
|
|||
# when the group being started is finished.
|
||||
# See `SampleExampleGroupBuilder#initialize` for the arguments
|
||||
# as arguments to this method are passed directly to it.
|
||||
def start_sample_group(*args) : Nil
|
||||
group = SampleExampleGroupBuilder.new(*args)
|
||||
def start_sample_group(*args, &block : TestValues -> Array(T)) : Nil forall T
|
||||
group = SampleExampleGroupBuilder(T).new(*args, block)
|
||||
@@stack.push(group)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
require "./nested_example_group_builder"
|
||||
|
||||
module Spectator::SpecBuilder
|
||||
class SampleExampleGroupBuilder < NestedExampleGroupBuilder
|
||||
def initialize(@what : String | Symbol)
|
||||
@id = :TODO
|
||||
class SampleExampleGroupBuilder(T) < NestedExampleGroupBuilder
|
||||
def initialize(what : String | Symbol, @id : Symbol, @collection_builder : TestValues -> Array(T))
|
||||
super(what)
|
||||
end
|
||||
|
||||
def build(parent_group)
|
||||
context = TestContext.new(parent_group.context, build_hooks, parent_group.context.values)
|
||||
values = parent_group.context.values
|
||||
collection = @collection_builder.call(values)
|
||||
context = TestContext.new(parent_group.context, build_hooks, values)
|
||||
NestedExampleGroup.new(@what, parent_group, context).tap do |group|
|
||||
group.children = [:TODO].map do |element|
|
||||
group.children = collection.map do |element|
|
||||
build_sub_group(group, element).as(ExampleComponent)
|
||||
end
|
||||
end
|
||||
|
@ -18,7 +20,7 @@ module Spectator::SpecBuilder
|
|||
private def build_sub_group(parent_group, element)
|
||||
values = parent_group.context.values.add(@id, @what.to_s, element)
|
||||
context = TestContext.new(parent_group.context, ExampleHooks.empty, values)
|
||||
NestedExampleGroup.new("TODO", parent_group, context).tap do |group|
|
||||
NestedExampleGroup.new(element.inspect, parent_group, context).tap do |group|
|
||||
group.children = children.map do |child|
|
||||
child.build(group).as(ExampleComponent)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue