Pass along class type instead of collection

This commit is contained in:
Michael Miller 2019-08-15 17:38:54 -06:00
parent 01c4b78716
commit 34b5487e6f
3 changed files with 9 additions and 4 deletions

View file

@ -41,10 +41,10 @@ module Spectator::DSL
# that is, a group defined by the `StructureDSL#sample` macro in the DSL.
# A corresponding `#end_group` call must be made
# when the group being started is finished.
# See `SampleExampleGroupBuilder#initialize` for the arguments
# See `SampleExampleGroupBuilder#create` for the arguments
# as arguments to this method are passed directly to it.
def start_sample_group(*args) : Nil
group = SampleExampleGroupBuilder.new(*args)
group = SampleExampleGroupBuilder.create(*args)
push_group(group)
end

View file

@ -29,6 +29,11 @@ module Spectator::DSL
super(what)
end
def self.create(what, collection_type : C.class, name, symbol) forall C
collection = collection_type.new(sample_values).to_a
SampleExampleGroupBuilder.new(what, collection, name, symbol)
end
# Builds the example group.
# A new `NestedExampleGroup` will be returned
# which can have instances of `Example` and `ExampleGroup` nested in it.

View file

@ -558,7 +558,7 @@ module Spectator::DSL
# Sample groups require additional configuration.
::Spectator::DSL::Builder.start_sample_group(
{{collection.stringify}}, # String representation of the collection.
Sample%sample.new.%to_a, # All elements in the collection.
Sample%sample, # All elements in the collection.
{{name.stringify}}, # Name for the current element.
:%sample # Unique identifier for retrieving elements for the associated collection.
)
@ -678,7 +678,7 @@ module Spectator::DSL
# Sample groups require additional configuration.
::Spectator::DSL::Builder.start_sample_group(
{{collection.stringify}}, # String representation of the collection.
Sample%sample.new.%to_a, # All elements in the collection.
Sample%sample, # All elements in the collection.
{{name.stringify}}, # Name for the current element.
:%sample # Unique identifier for retrieving elements for the associated collection.
)