diff --git a/src/spectator/dsl/builder.cr b/src/spectator/dsl/builder.cr index a836559..82a0386 100644 --- a/src/spectator/dsl/builder.cr +++ b/src/spectator/dsl/builder.cr @@ -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 diff --git a/src/spectator/dsl/sample_example_group_builder.cr b/src/spectator/dsl/sample_example_group_builder.cr index 5ea6468..dbf83ec 100644 --- a/src/spectator/dsl/sample_example_group_builder.cr +++ b/src/spectator/dsl/sample_example_group_builder.cr @@ -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. diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index 10e59e6..176d358 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -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. )