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/*"
|
||||||
require "./dsl/builder"
|
require "./dsl/builder"
|
||||||
|
require "./dsl/examples"
|
||||||
require "./dsl/groups"
|
require "./dsl/groups"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
|
|
|
@ -13,5 +13,9 @@ module Spectator::DSL
|
||||||
def end_group(*args)
|
def end_group(*args)
|
||||||
@@builder.end_group(*args)
|
@@builder.end_group(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_example(*args, &block : Example, Context ->)
|
||||||
|
@@builder.add_example(*args, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,29 @@
|
||||||
require "../source"
|
require "../source"
|
||||||
require "../spec_builder"
|
require "./builder"
|
||||||
|
|
||||||
module Spectator
|
module Spectator::DSL
|
||||||
module 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)
|
macro it(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
{% if block.is_a?(Nop) %}
|
{% if block.is_a?(Nop) %}
|
||||||
{% if description.is_a?(Call) %}
|
{% if description.is_a?(Call) %}
|
||||||
|
@ -61,4 +82,3 @@ module Spectator
|
||||||
pending({{description}}) {{block}}
|
pending({{description}}) {{block}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require "../example"
|
require "../example"
|
||||||
|
require "../example_context_method"
|
||||||
require "../example_group"
|
require "../example_group"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
|
@ -38,6 +39,16 @@ module Spectator
|
||||||
@group_stack.pop
|
@group_stack.pop
|
||||||
end
|
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
|
def build
|
||||||
raise NotImplementedError.new("#build")
|
raise NotImplementedError.new("#build")
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@ require "./spectator_context"
|
||||||
require "./spectator/dsl"
|
require "./spectator/dsl"
|
||||||
|
|
||||||
class SpectatorTestContext < SpectatorContext
|
class SpectatorTestContext < SpectatorContext
|
||||||
|
include ::Spectator::DSL::Examples
|
||||||
include ::Spectator::DSL::Groups
|
include ::Spectator::DSL::Groups
|
||||||
|
|
||||||
# Initial implicit subject for tests.
|
# Initial implicit subject for tests.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue