mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Working example creation from DSL
This commit is contained in:
parent
7c44cba667
commit
bc602d9b62
5 changed files with 41 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
# require "./dsl/*"
|
||||
require "./dsl/builder"
|
||||
require "./dsl/examples"
|
||||
require "./dsl/groups"
|
||||
|
||||
module Spectator
|
||||
|
|
|
@ -13,5 +13,9 @@ module Spectator::DSL
|
|||
def end_group(*args)
|
||||
@@builder.end_group(*args)
|
||||
end
|
||||
|
||||
def add_example(*args, &block : Example, Context ->)
|
||||
@@builder.add_example(*args, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,29 @@
|
|||
require "../source"
|
||||
require "../spec_builder"
|
||||
require "./builder"
|
||||
|
||||
module Spectator
|
||||
module DSL
|
||||
module Spectator::DSL
|
||||
module Examples
|
||||
macro example(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||
def %test
|
||||
{{block.body}}
|
||||
end
|
||||
|
||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||
::Spectator::DSL::Builder.add_example(
|
||||
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
|
||||
%source,
|
||||
{{@type.name}}.new
|
||||
) { |example, context| context.as({{@type.name}}).%test }
|
||||
end
|
||||
|
||||
macro it(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||
example({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
|
||||
end
|
||||
|
||||
macro specify(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||
example({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
|
||||
end
|
||||
end
|
||||
macro it(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||
{% if block.is_a?(Nop) %}
|
||||
{% if description.is_a?(Call) %}
|
||||
|
@ -60,5 +81,4 @@ module Spectator
|
|||
macro xit(description = nil, &block)
|
||||
pending({{description}}) {{block}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require "../example"
|
||||
require "../example_context_method"
|
||||
require "../example_group"
|
||||
|
||||
module Spectator
|
||||
|
@ -38,6 +39,16 @@ module Spectator
|
|||
@group_stack.pop
|
||||
end
|
||||
|
||||
def add_example(name, source, context, &block : Example, Context ->)
|
||||
{% if flag?(:spectator_debug) %}
|
||||
puts "Add example: #{name} @ #{source}"
|
||||
puts "Context: #{context}"
|
||||
{% end %}
|
||||
delegate = ExampleContextDelegate.new(context, block)
|
||||
Example.new(delegate, name, source, current_group)
|
||||
# The example is added to the current group by `Example` initializer.
|
||||
end
|
||||
|
||||
def build
|
||||
raise NotImplementedError.new("#build")
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ require "./spectator_context"
|
|||
require "./spectator/dsl"
|
||||
|
||||
class SpectatorTestContext < SpectatorContext
|
||||
include ::Spectator::DSL::Examples
|
||||
include ::Spectator::DSL::Groups
|
||||
|
||||
# Initial implicit subject for tests.
|
||||
|
|
Loading…
Reference in a new issue