mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Change "what" to "description"
This commit is contained in:
parent
edabaa9447
commit
25778d7b41
10 changed files with 43 additions and 40 deletions
|
@ -24,7 +24,7 @@ module Spectator
|
||||||
# NOTE: Inside the block, the `Spectator` prefix is no longer needed.
|
# NOTE: Inside the block, the `Spectator` prefix is no longer needed.
|
||||||
# Actually, prefixing methods and macros with `Spectator`
|
# Actually, prefixing methods and macros with `Spectator`
|
||||||
# most likely won't work and can cause compiler errors.
|
# most likely won't work and can cause compiler errors.
|
||||||
macro describe(what, &block)
|
macro describe(description, &block)
|
||||||
# This macro creates the foundation for all specs.
|
# This macro creates the foundation for all specs.
|
||||||
# Every group of examples is defined a separate module - `SpectatorExamples`.
|
# Every group of examples is defined a separate module - `SpectatorExamples`.
|
||||||
# There's multiple reasons for this.
|
# There's multiple reasons for this.
|
||||||
|
@ -39,15 +39,15 @@ module Spectator
|
||||||
|
|
||||||
# Root-level class that contains all examples and example groups.
|
# Root-level class that contains all examples and example groups.
|
||||||
class SpectatorTest
|
class SpectatorTest
|
||||||
# Pass off the "what" argument and block to `DSL::StructureDSL.describe`.
|
# Pass off the description argument and block to `DSL::StructureDSL.describe`.
|
||||||
# That method will handle creating a new group for this spec.
|
# That method will handle creating a new group for this spec.
|
||||||
describe({{what}}) {{block}}
|
describe({{description}}) {{block}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# ditto
|
# ditto
|
||||||
macro context(what, &block)
|
macro context(description, &block)
|
||||||
describe({{what}}) {{block}}
|
describe({{description}}) {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Flag indicating whether Spectator should automatically run tests.
|
# Flag indicating whether Spectator should automatically run tests.
|
||||||
|
|
|
@ -3,14 +3,14 @@ require "../spec_builder"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
module DSL
|
module DSL
|
||||||
macro it(what, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro it(description, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
{% if block.is_a?(Nop) %}
|
{% if block.is_a?(Nop) %}
|
||||||
{% if what.is_a?(Call) %}
|
{% if description.is_a?(Call) %}
|
||||||
def %run
|
def %run
|
||||||
{{what}}
|
{{description}}
|
||||||
end
|
end
|
||||||
{% else %}
|
{% else %}
|
||||||
{% raise "Unrecognized syntax: `it #{what}` at #{_source_file}:#{_source_line}" %}
|
{% raise "Unrecognized syntax: `it #{description}` at #{_source_file}:#{_source_line}" %}
|
||||||
{% end %}
|
{% end %}
|
||||||
{% else %}
|
{% else %}
|
||||||
def %run
|
def %run
|
||||||
|
@ -20,7 +20,7 @@ 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(
|
||||||
{{what.is_a?(StringLiteral) ? what : what.stringify}},
|
{{description.is_a?(StringLiteral) ? description : description.stringify}},
|
||||||
%source,
|
%source,
|
||||||
{{@type.name}}
|
{{@type.name}}
|
||||||
) { |test| test.as({{@type.name}}).%run }
|
) { |test| test.as({{@type.name}}).%run }
|
||||||
|
|
|
@ -2,26 +2,26 @@ require "../spec_builder"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
module DSL
|
module DSL
|
||||||
macro context(what, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro context(description, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
class Context%context < {{@type.id}}
|
class Context%context < {{@type.id}}
|
||||||
{%
|
{%
|
||||||
description = if what.is_a?(StringLiteral)
|
description = if description.is_a?(StringLiteral)
|
||||||
if what.starts_with?("#") || what.starts_with?(".")
|
if description.starts_with?("#") || description.starts_with?(".")
|
||||||
what.id.symbolize
|
description.id.symbolize
|
||||||
else
|
else
|
||||||
what
|
description
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
what.symbolize
|
description.symbolize
|
||||||
end
|
end
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||||
::Spectator::SpecBuilder.start_group({{description}}, %source)
|
::Spectator::SpecBuilder.start_group({{description}}, %source)
|
||||||
|
|
||||||
{% if what.is_a?(Path) || what.is_a?(Generic) %}
|
{% if description.is_a?(Path) || description.is_a?(Generic) %}
|
||||||
macro described_class
|
macro described_class
|
||||||
{{what}}
|
{{description}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def subject(*args)
|
def subject(*args)
|
||||||
|
@ -35,8 +35,8 @@ module Spectator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
macro describe(what, &block)
|
macro describe(description, &block)
|
||||||
context({{what}}) {{block}}
|
context({{description}}) {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro sample(collection, count = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro sample(collection, count = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Spectator
|
||||||
@test_wrapper.source
|
@test_wrapper.source
|
||||||
end
|
end
|
||||||
|
|
||||||
def what : String | Symbol
|
def description : String | Symbol
|
||||||
@test_wrapper.description
|
@test_wrapper.description
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ module Spectator
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
@group.to_s(io)
|
@group.to_s(io)
|
||||||
io << ' ' unless symbolic? && @group.symbolic?
|
io << ' ' unless symbolic? && @group.symbolic?
|
||||||
io << what
|
io << description
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates the JSON representation of the example,
|
# Creates the JSON representation of the example,
|
||||||
|
|
|
@ -3,8 +3,11 @@ module Spectator
|
||||||
# This is used as the base node type for the composite design pattern.
|
# This is used as the base node type for the composite design pattern.
|
||||||
abstract class ExampleComponent
|
abstract class ExampleComponent
|
||||||
# Text that describes the context or test.
|
# Text that describes the context or test.
|
||||||
# TODO: Rename to description.
|
abstract def description : Symbol | String
|
||||||
abstract def what : Symbol | String
|
|
||||||
|
def full_description
|
||||||
|
to_s
|
||||||
|
end
|
||||||
|
|
||||||
abstract def source : Source
|
abstract def source : Source
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ module Spectator::Formatting
|
||||||
# Produces a single character output based on a result.
|
# Produces a single character output based on a result.
|
||||||
def end_example(result)
|
def end_example(result)
|
||||||
@previous_hierarchy.size.times { @io.print INDENT }
|
@previous_hierarchy.size.times { @io.print INDENT }
|
||||||
@io.puts result.call(Color) { result.example.what }
|
@io.puts result.call(Color) { result.example.description }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Produces a list of groups making up the hierarchy for an example.
|
# Produces a list of groups making up the hierarchy for an example.
|
||||||
|
@ -56,7 +56,7 @@ module Spectator::Formatting
|
||||||
private def print_sub_hierarchy(index, sub_hierarchy)
|
private def print_sub_hierarchy(index, sub_hierarchy)
|
||||||
sub_hierarchy.each do |group|
|
sub_hierarchy.each do |group|
|
||||||
index.times { @io.print INDENT }
|
index.times { @io.print INDENT }
|
||||||
@io.puts group.what
|
@io.puts group.description
|
||||||
index += 1
|
index += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Spectator
|
||||||
class NestedExampleGroup < ExampleGroup
|
class NestedExampleGroup < ExampleGroup
|
||||||
# Description from the user of the group's contents.
|
# Description from the user of the group's contents.
|
||||||
# This is a symbol when referencing a type.
|
# This is a symbol when referencing a type.
|
||||||
getter what : Symbol | String
|
getter description : Symbol | String
|
||||||
|
|
||||||
getter source : Source
|
getter source : Source
|
||||||
|
|
||||||
|
@ -14,23 +14,23 @@ module Spectator
|
||||||
getter parent : ExampleGroup
|
getter parent : ExampleGroup
|
||||||
|
|
||||||
# Creates a new example group.
|
# Creates a new example group.
|
||||||
# The *what* argument is a description from the user.
|
# The *description* argument is a description from the user.
|
||||||
# The *parent* should contain this group.
|
# The *parent* should contain this group.
|
||||||
# After creating this group, the parent's children should be updated.
|
# After creating this group, the parent's children should be updated.
|
||||||
# The parent's children must contain this group,
|
# The parent's children must contain this group,
|
||||||
# otherwise there may be unexpected behavior.
|
# otherwise there may be unexpected behavior.
|
||||||
# The *hooks* are stored to be triggered later.
|
# The *hooks* are stored to be triggered later.
|
||||||
def initialize(@what, @source, @parent, context)
|
def initialize(@description, @source, @parent, context)
|
||||||
super(context)
|
super(context)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indicates wheter the group references a type.
|
# Indicates wheter the group references a type.
|
||||||
def symbolic? : Bool
|
def symbolic? : Bool
|
||||||
@what.is_a?(Symbol)
|
@description.is_a?(Symbol)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a string representation of the group.
|
# Creates a string representation of the group.
|
||||||
# The string consists of `#what` appended to the parent.
|
# The string consists of `#description` appended to the parent.
|
||||||
# This results in a string like:
|
# This results in a string like:
|
||||||
# ```text
|
# ```text
|
||||||
# Foo#bar does something
|
# Foo#bar does something
|
||||||
|
@ -48,7 +48,7 @@ module Spectator
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
parent.to_s(io)
|
parent.to_s(io)
|
||||||
io << ' ' unless (symbolic? || parent.is_a?(RootExampleGroup)) && parent.symbolic?
|
io << ' ' unless (symbolic? || parent.is_a?(RootExampleGroup)) && parent.symbolic?
|
||||||
io << what
|
io << description
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,8 @@ module Spectator
|
||||||
# The root has no parent.
|
# The root has no parent.
|
||||||
class RootExampleGroup < ExampleGroup
|
class RootExampleGroup < ExampleGroup
|
||||||
# Dummy value - this should never be used.
|
# Dummy value - this should never be used.
|
||||||
def what : Symbol | String
|
def description : Symbol | String
|
||||||
"ROOT"
|
:root
|
||||||
end
|
end
|
||||||
|
|
||||||
def source : Source
|
def source : Source
|
||||||
|
|
|
@ -3,12 +3,12 @@ require "./example_group_builder"
|
||||||
|
|
||||||
module Spectator::SpecBuilder
|
module Spectator::SpecBuilder
|
||||||
class NestedExampleGroupBuilder < ExampleGroupBuilder
|
class NestedExampleGroupBuilder < ExampleGroupBuilder
|
||||||
def initialize(@what : String | Symbol, @source : Source)
|
def initialize(@description : String | Symbol, @source : Source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(parent_group)
|
def build(parent_group)
|
||||||
context = TestContext.new(parent_group.context, build_hooks, parent_group.context.values)
|
context = TestContext.new(parent_group.context, build_hooks, parent_group.context.values)
|
||||||
NestedExampleGroup.new(@what, @source, parent_group, context).tap do |group|
|
NestedExampleGroup.new(@description, @source, parent_group, context).tap do |group|
|
||||||
group.children = children.map do |child|
|
group.children = children.map do |child|
|
||||||
child.build(group).as(ExampleComponent)
|
child.build(group).as(ExampleComponent)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,15 +2,15 @@ require "./nested_example_group_builder"
|
||||||
|
|
||||||
module Spectator::SpecBuilder
|
module Spectator::SpecBuilder
|
||||||
class SampleExampleGroupBuilder(T) < NestedExampleGroupBuilder
|
class SampleExampleGroupBuilder(T) < NestedExampleGroupBuilder
|
||||||
def initialize(what : String | Symbol, source : Source, @id : Symbol, @label : String, @collection_builder : TestValues -> Array(T))
|
def initialize(description : String | Symbol, source : Source, @id : Symbol, @label : String, @collection_builder : TestValues -> Array(T))
|
||||||
super(what, source)
|
super(description, source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(parent_group)
|
def build(parent_group)
|
||||||
values = parent_group.context.values
|
values = parent_group.context.values
|
||||||
collection = @collection_builder.call(values)
|
collection = @collection_builder.call(values)
|
||||||
context = TestContext.new(parent_group.context, build_hooks, values)
|
context = TestContext.new(parent_group.context, build_hooks, values)
|
||||||
NestedExampleGroup.new(@what, @source, parent_group, context).tap do |group|
|
NestedExampleGroup.new(@description, @source, parent_group, context).tap do |group|
|
||||||
group.children = collection.map do |element|
|
group.children = collection.map do |element|
|
||||||
build_sub_group(group, element).as(ExampleComponent)
|
build_sub_group(group, element).as(ExampleComponent)
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,7 @@ module Spectator::SpecBuilder
|
||||||
end
|
end
|
||||||
|
|
||||||
private def build_sub_group(parent_group, element)
|
private def build_sub_group(parent_group, element)
|
||||||
values = parent_group.context.values.add(@id, @what.to_s, element)
|
values = parent_group.context.values.add(@id, @description.to_s, element)
|
||||||
context = TestContext.new(parent_group.context, ExampleHooks.empty, values)
|
context = TestContext.new(parent_group.context, ExampleHooks.empty, values)
|
||||||
NestedExampleGroup.new("#{@label} = #{element.inspect}", @source, parent_group, context).tap do |group|
|
NestedExampleGroup.new("#{@label} = #{element.inspect}", @source, parent_group, context).tap do |group|
|
||||||
group.children = children.map do |child|
|
group.children = children.map do |child|
|
||||||
|
|
Loading…
Reference in a new issue