mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Some initial work on sample groups
This commit is contained in:
parent
422c805e21
commit
5d9e7002d6
2 changed files with 47 additions and 0 deletions
|
@ -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
|
||||
|
|
26
src/spectator/spec_builder/sample_example_group_builder.cr
Normal file
26
src/spectator/spec_builder/sample_example_group_builder.cr
Normal 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
|
Loading…
Reference in a new issue