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
|
end
|
||||||
|
|
||||||
class Context%sample < {{@type.id}}
|
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}}
|
def {{block_arg}}
|
||||||
1
|
1
|
||||||
|
|
|
@ -26,8 +26,8 @@ module Spectator
|
||||||
# when the group being started is finished.
|
# when the group being started is finished.
|
||||||
# See `SampleExampleGroupBuilder#initialize` for the arguments
|
# See `SampleExampleGroupBuilder#initialize` for the arguments
|
||||||
# as arguments to this method are passed directly to it.
|
# as arguments to this method are passed directly to it.
|
||||||
def start_sample_group(*args) : Nil
|
def start_sample_group(*args, &block : TestValues -> Array(T)) : Nil forall T
|
||||||
group = SampleExampleGroupBuilder.new(*args)
|
group = SampleExampleGroupBuilder(T).new(*args, block)
|
||||||
@@stack.push(group)
|
@@stack.push(group)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
require "./nested_example_group_builder"
|
require "./nested_example_group_builder"
|
||||||
|
|
||||||
module Spectator::SpecBuilder
|
module Spectator::SpecBuilder
|
||||||
class SampleExampleGroupBuilder < NestedExampleGroupBuilder
|
class SampleExampleGroupBuilder(T) < NestedExampleGroupBuilder
|
||||||
def initialize(@what : String | Symbol)
|
def initialize(what : String | Symbol, @id : Symbol, @collection_builder : TestValues -> Array(T))
|
||||||
@id = :TODO
|
super(what)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(parent_group)
|
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|
|
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)
|
build_sub_group(group, element).as(ExampleComponent)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,7 +20,7 @@ module Spectator::SpecBuilder
|
||||||
private def build_sub_group(parent_group, element)
|
private def build_sub_group(parent_group, element)
|
||||||
values = parent_group.context.values.add(@id, @what.to_s, element)
|
values = parent_group.context.values.add(@id, @what.to_s, element)
|
||||||
context = TestContext.new(parent_group.context, ExampleHooks.empty, values)
|
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|
|
group.children = children.map do |child|
|
||||||
child.build(group).as(ExampleComponent)
|
child.build(group).as(ExampleComponent)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue