mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow test description to be blank
Currently defaults to the example's source.
This commit is contained in:
parent
9f91e3a266
commit
ff2cbcd4c7
5 changed files with 16 additions and 11 deletions
|
@ -3,7 +3,7 @@ require "../spec_builder"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
module DSL
|
module DSL
|
||||||
macro it(description, _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) %}
|
||||||
def %run
|
def %run
|
||||||
|
@ -20,17 +20,17 @@ module Spectator
|
||||||
|
|
||||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||||
::Spectator::SpecBuilder.add_example(
|
::Spectator::SpecBuilder.add_example(
|
||||||
{{description.is_a?(StringLiteral) ? description : description.stringify}},
|
{{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}},
|
||||||
%source,
|
%source,
|
||||||
{{@type.name}}
|
{{@type.name}}
|
||||||
) { |test| test.as({{@type.name}}).%run }
|
) { |test| test.as({{@type.name}}).%run }
|
||||||
end
|
end
|
||||||
|
|
||||||
macro specify(description, &block)
|
macro specify(description = nil, &block)
|
||||||
it({{description}}) {{block}}
|
it({{description}}) {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro pending(description, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro pending(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) %}
|
||||||
def %run
|
def %run
|
||||||
|
@ -47,17 +47,17 @@ module Spectator
|
||||||
|
|
||||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||||
::Spectator::SpecBuilder.add_pending_example(
|
::Spectator::SpecBuilder.add_pending_example(
|
||||||
{{description.is_a?(StringLiteral) ? description : description.stringify}},
|
{{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}},
|
||||||
%source,
|
%source,
|
||||||
{{@type.name}}
|
{{@type.name}}
|
||||||
) { |test| test.as({{@type.name}}).%run }
|
) { |test| test.as({{@type.name}}).%run }
|
||||||
end
|
end
|
||||||
|
|
||||||
macro skip(description, &block)
|
macro skip(description = nil, &block)
|
||||||
pending({{description}}) {{block}}
|
pending({{description}}) {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro xit(description, &block)
|
macro xit(description = nil, &block)
|
||||||
pending({{description}}) {{block}}
|
pending({{description}}) {{block}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Spectator
|
||||||
@test_wrapper.source
|
@test_wrapper.source
|
||||||
end
|
end
|
||||||
|
|
||||||
def description : String | Symbol
|
def description : String | Symbol?
|
||||||
@test_wrapper.description
|
@test_wrapper.description
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Spectator
|
||||||
# Adds an example type to the current group.
|
# Adds an example type to the current group.
|
||||||
# The class name of the example should be passed as an argument.
|
# The class name of the example should be passed as an argument.
|
||||||
# The example will be instantiated later.
|
# The example will be instantiated later.
|
||||||
def add_example(description : String, source : Source,
|
def add_example(description : String?, source : Source,
|
||||||
example_type : ::SpectatorTest.class, &runner : ::SpectatorTest ->) : Nil
|
example_type : ::SpectatorTest.class, &runner : ::SpectatorTest ->) : Nil
|
||||||
builder = ->(values : TestValues) { example_type.new(values).as(::SpectatorTest) }
|
builder = ->(values : TestValues) { example_type.new(values).as(::SpectatorTest) }
|
||||||
factory = RunnableExampleBuilder.new(description, source, builder, runner)
|
factory = RunnableExampleBuilder.new(description, source, builder, runner)
|
||||||
|
@ -52,7 +52,7 @@ module Spectator
|
||||||
# Adds an example type to the current group.
|
# Adds an example type to the current group.
|
||||||
# The class name of the example should be passed as an argument.
|
# The class name of the example should be passed as an argument.
|
||||||
# The example will be instantiated later.
|
# The example will be instantiated later.
|
||||||
def add_pending_example(description : String, source : Source,
|
def add_pending_example(description : String?, source : Source,
|
||||||
example_type : ::SpectatorTest.class, &runner : ::SpectatorTest ->) : Nil
|
example_type : ::SpectatorTest.class, &runner : ::SpectatorTest ->) : Nil
|
||||||
builder = ->(values : TestValues) { example_type.new(values).as(::SpectatorTest) }
|
builder = ->(values : TestValues) { example_type.new(values).as(::SpectatorTest) }
|
||||||
factory = PendingExampleBuilder.new(description, source, builder, runner)
|
factory = PendingExampleBuilder.new(description, source, builder, runner)
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Spectator::SpecBuilder
|
||||||
abstract class ExampleBuilder
|
abstract class ExampleBuilder
|
||||||
alias FactoryMethod = TestValues -> ::SpectatorTest
|
alias FactoryMethod = TestValues -> ::SpectatorTest
|
||||||
|
|
||||||
def initialize(@description : String, @source : Source, @builder : FactoryMethod, @runner : TestMethod)
|
def initialize(@description : String?, @source : Source, @builder : FactoryMethod, @runner : TestMethod)
|
||||||
end
|
end
|
||||||
|
|
||||||
abstract def build(group) : ExampleComponent
|
abstract def build(group) : ExampleComponent
|
||||||
|
|
|
@ -17,6 +17,11 @@ module Spectator
|
||||||
def initialize(@description : String, @source : Source, @test : ::SpectatorTest, @runner : TestMethod)
|
def initialize(@description : String, @source : Source, @test : ::SpectatorTest, @runner : TestMethod)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Creates a wrapper for the test.
|
||||||
|
def initialize(description : Nil, @source : Source, @test : ::SpectatorTest, @runner : TestMethod)
|
||||||
|
@description = @source.to_s
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
call(@runner)
|
call(@runner)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue