Allow test description to be blank

Currently defaults to the example's source.
This commit is contained in:
Michael Miller 2020-01-02 18:40:25 -07:00
parent 9f91e3a266
commit ff2cbcd4c7
5 changed files with 16 additions and 11 deletions

View file

@ -3,7 +3,7 @@ require "../spec_builder"
module Spectator
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 description.is_a?(Call) %}
def %run
@ -20,17 +20,17 @@ module Spectator
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
::Spectator::SpecBuilder.add_example(
{{description.is_a?(StringLiteral) ? description : description.stringify}},
{{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}},
%source,
{{@type.name}}
) { |test| test.as({{@type.name}}).%run }
end
macro specify(description, &block)
macro specify(description = nil, &block)
it({{description}}) {{block}}
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 description.is_a?(Call) %}
def %run
@ -47,17 +47,17 @@ module Spectator
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
::Spectator::SpecBuilder.add_pending_example(
{{description.is_a?(StringLiteral) ? description : description.stringify}},
{{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}},
%source,
{{@type.name}}
) { |test| test.as({{@type.name}}).%run }
end
macro skip(description, &block)
macro skip(description = nil, &block)
pending({{description}}) {{block}}
end
macro xit(description, &block)
macro xit(description = nil, &block)
pending({{description}}) {{block}}
end
end

View file

@ -23,7 +23,7 @@ module Spectator
@test_wrapper.source
end
def description : String | Symbol
def description : String | Symbol?
@test_wrapper.description
end

View file

@ -42,7 +42,7 @@ module Spectator
# Adds an example type to the current group.
# The class name of the example should be passed as an argument.
# 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
builder = ->(values : TestValues) { example_type.new(values).as(::SpectatorTest) }
factory = RunnableExampleBuilder.new(description, source, builder, runner)
@ -52,7 +52,7 @@ module Spectator
# Adds an example type to the current group.
# The class name of the example should be passed as an argument.
# 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
builder = ->(values : TestValues) { example_type.new(values).as(::SpectatorTest) }
factory = PendingExampleBuilder.new(description, source, builder, runner)

View file

@ -6,7 +6,7 @@ module Spectator::SpecBuilder
abstract class ExampleBuilder
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
abstract def build(group) : ExampleComponent

View file

@ -17,6 +17,11 @@ module Spectator
def initialize(@description : String, @source : Source, @test : ::SpectatorTest, @runner : TestMethod)
end
# Creates a wrapper for the test.
def initialize(description : Nil, @source : Source, @test : ::SpectatorTest, @runner : TestMethod)
@description = @source.to_s
end
def run
call(@runner)
end