Some initial work on sample groups

This commit is contained in:
Michael Miller 2019-09-26 12:31:23 -06:00
parent 422c805e21
commit 5d9e7002d6
2 changed files with 47 additions and 0 deletions

View file

@ -25,5 +25,26 @@ module Spectator
macro describe(what, &block)
context({{what}}) {{block}}
end
macro sample(what, &block)
{% block_arg = block.args.empty? ? :value.id : block.args.first.id %}
class Sample%sample < {{@type.id}}
def %collection
{{what}}
end
end
class Context%sample < {{@type.id}}
::Spectator::SpecBuilder.start_sample_group({{what.stringify}})
def {{block_arg}}
1
end
{{block.body}}
::Spectator::SpecBuilder.end_group
end
end
end
end

View file

@ -0,0 +1,26 @@
require "./nested_example_group_builder"
module Spectator::SpecBuilder
class SampleExampleGroupBuilder < NestedExampleGroupBuilder
def initialize(@what : String)
end
def build(parent_group)
context = TestContext.new(parent_group.context, build_hooks)
NestedExampleGroup.new(@what, parent_group, context).tap do |group|
group.children = [:TODO].map do |element|
build_sub_group(group, element).as(ExampleComponent)
end
end
end
private def build_sub_group(parent_group, element)
context = TestContext.new(parent_group.context, ExampleHooks.empty)
NestedExampleGroup.new("TODO", parent_group, context).tap do |group|
group.children = children.map do |child|
child.build(group).as(ExampleComponent)
end
end
end
end
end