GivenExampleGroupBuilder produces group of groups

Now a group is created for each element in the collection.
A group to contain the sub-groups is returned.
This commit is contained in:
Michael Miller 2018-09-24 00:25:15 -06:00
parent 1c7c6e5e90
commit ef7e0462cb
2 changed files with 21 additions and 8 deletions

View file

@ -10,15 +10,18 @@ module Spectator
def build(parent : ExampleGroup?, sample_values : Internals::SampleValues) : ExampleGroup
ExampleGroup.new(@what, parent, build_hooks).tap do |group|
children = [] of ExampleGroup::Child
@collection.each do |value|
iter_values = sample_values.add(@symbol, @symbol.to_s, value)
iter_children = @children.map do |child|
child.build(group, iter_values)
end
children.concat(iter_children)
group.children = @collection.map do |value|
build_sub_group(group, sample_values, value).as(ExampleGroup::Child)
end
end
end
private def build_sub_group(parent : ExampleGroup, sample_values : Internals::SampleValues, value : T) : ExampleGroup
sub_values = sample_values.add(@symbol, @symbol.to_s, value)
ExampleGroup.new(value.to_s, parent, ExampleHooks.empty).tap do |group|
group.children = @children.map do |child|
child.build(group, sub_values).as(ExampleGroup::Child)
end
group.children = children
end
end
end

View file

@ -1,5 +1,15 @@
module Spectator
class ExampleHooks
def self.empty
new(
[] of ->,
[] of ->,
[] of ->,
[] of ->,
[] of Proc(Nil) ->
)
end
def initialize(
@before_all : Array(->),
@before_each : Array(->),