diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index ec38175..3719dca 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -146,7 +146,13 @@ module Spectator end end - ::Spectator::Definitions::GROUPS[\{{@type.symbolize}}].children << Example%example.new + class Factory%example < ::Spectator::ExampleFactory + def build + Example%example.new + end + end + + ::Spectator::Definitions::GROUPS[\{{@type.symbolize}}].children << Factory%example.new end macro pending(description, &block) diff --git a/src/spectator/example_factory.cr b/src/spectator/example_factory.cr new file mode 100644 index 0000000..f7ccef3 --- /dev/null +++ b/src/spectator/example_factory.cr @@ -0,0 +1,5 @@ +module Spectator + abstract class ExampleFactory + abstract def build : Example + end +end diff --git a/src/spectator/example_group.cr b/src/spectator/example_group.cr index 54017a8..72be711 100644 --- a/src/spectator/example_group.cr +++ b/src/spectator/example_group.cr @@ -11,7 +11,7 @@ module Spectator getter after_all_hooks = [] of -> getter after_each_hooks = [] of -> getter around_each_hooks = [] of Proc(Nil) -> - getter children = [] of Example | ExampleGroup + getter children = [] of ExampleFactory | ExampleGroup @before_all_hooks_run = false @after_all_hooks_run = false @@ -22,8 +22,8 @@ module Spectator end end - def examples : Enumerable(Example) - @children.select { |child| child.is_a?(Example) }.map { |child| child.unsafe_as(Example) } + def examples : Enumerable(ExampleFactory) + @children.select { |child| child.is_a?(ExampleFactory) }.map { |child| child.unsafe_as(ExampleFactory) } end def groups : Enumerable(ExampleGroup) @@ -97,8 +97,8 @@ module Spectator protected def add_examples(array : Array(Example)) @children.each do |child| - if child.is_a?(Example) - array << child + if child.is_a?(ExampleFactory) + array << child.build else child.add_examples(array) end