Get rid of #add_examples

Added #example_count method to help with array sizing.
This commit is contained in:
Michael Miller 2018-09-19 23:13:43 -06:00
parent 8b8981494d
commit 007572f0b8
2 changed files with 21 additions and 15 deletions

View file

@ -30,9 +30,21 @@ module Spectator
@children.select { |child| child.is_a?(ExampleGroup) }.map { |child| child.unsafe_as(ExampleGroup) } @children.select { |child| child.is_a?(ExampleGroup) }.map { |child| child.unsafe_as(ExampleGroup) }
end end
def example_count
@children.sum do |child|
child.is_a?(ExampleFactory) ? 1 : child.example_count
end
end
def all_examples def all_examples
Array(Example).new.tap do |array| Array(Example).new(example_count).tap do |array|
add_examples(array) @children.each do |child|
if child.is_a?(ExampleFactory)
array << child.build
else
array.concat(child.all_examples)
end
end
end end
end end
@ -94,15 +106,5 @@ module Spectator
private def wrap_proc(inner : Proc(Nil) ->, wrapper : ->) private def wrap_proc(inner : Proc(Nil) ->, wrapper : ->)
-> { inner.call(wrapper) } -> { inner.call(wrapper) }
end end
def add_examples(array : Array(Example))
@children.each do |child|
if child.is_a?(ExampleFactory)
array << child.build
else
array.concat(child.all_examples)
end
end
end
end end
end end

View file

@ -8,9 +8,13 @@ module Spectator
super(what, parent) super(what, parent)
end end
protected def add_examples(array : Array(Example)) def example_count
@collection.each do |value| super.example_count * @collection.size
examples = super.all_examples end
def all_examples
Array(Example).new(example_count).tap do |array|
examples = super
examples.each do |example| examples.each do |example|
@mapping[example] = value @mapping[example] = value
end end