mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Switch to using tags instead of metadata
This commit is contained in:
parent
11cb16fb3a
commit
8cf498c9e9
5 changed files with 28 additions and 36 deletions
|
@ -26,16 +26,22 @@ module Spectator::DSL
|
||||||
\{% raise "A description or block must be provided. Cannot use '{{name.id}}' alone." unless what || block %}
|
\{% raise "A description or block must be provided. Cannot use '{{name.id}}' alone." unless what || block %}
|
||||||
\{% raise "Block argument count '{{name.id}}' hook must be 0..1" if block.args.size > 1 %}
|
\{% raise "Block argument count '{{name.id}}' hook must be 0..1" if block.args.size > 1 %}
|
||||||
|
|
||||||
def self.\%metadata
|
def self.\%tags
|
||||||
\{% if tags.empty? && metadata.empty? %}
|
\{% if tags.empty? && metadata.empty? %}
|
||||||
_spectator_metadata
|
_spectator_tags
|
||||||
\{% else %}
|
\{% else %}
|
||||||
_spectator_metadata.merge(
|
_spectator_tags.concat({\{{tags.map(&.id.stringify).splat}}}).tap do |tags|
|
||||||
\{% for tag in tags %}
|
\{% for k, v in metadata %}
|
||||||
\{{tag.id.stringify}}: true,
|
cond = begin
|
||||||
|
\{{v}}
|
||||||
|
end
|
||||||
|
if cond
|
||||||
|
tags.add(\{{k.id.stringify}})
|
||||||
|
else
|
||||||
|
tags.remove(\{{k.id.stringify}})
|
||||||
|
end
|
||||||
\{% end %}
|
\{% end %}
|
||||||
\{{metadata.double_splat}}
|
end
|
||||||
)
|
|
||||||
\{% end %}
|
\{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,13 +53,13 @@ module Spectator::DSL
|
||||||
_spectator_example_name(\{{what}}),
|
_spectator_example_name(\{{what}}),
|
||||||
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}),
|
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}),
|
||||||
\{{@type.name}}.new.as(::Spectator::Context),
|
\{{@type.name}}.new.as(::Spectator::Context),
|
||||||
\{{@type.name}}.\%metadata
|
\{{@type.name}}.\%tags
|
||||||
) do |example|
|
) do |example|
|
||||||
example.with_context(\{{@type.name}}) do
|
example.with_context(\{{@type.name}}) do
|
||||||
\{% if block.args.empty? %}
|
\{% if block.args.empty? %}
|
||||||
\%test
|
\%test
|
||||||
\{% else %}
|
\{% else %}
|
||||||
\%test(example.unwrap_metadata(typeof(\{{@type.name}}.\%metadata)))
|
\%test(example)
|
||||||
\{% end %}
|
\{% end %}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require "./example_context_delegate"
|
require "./example_context_delegate"
|
||||||
require "./example_group"
|
require "./example_group"
|
||||||
require "./harness"
|
require "./harness"
|
||||||
require "./metadata_example"
|
|
||||||
require "./pending_result"
|
require "./pending_result"
|
||||||
require "./result"
|
require "./result"
|
||||||
require "./source"
|
require "./source"
|
||||||
|
@ -10,6 +9,9 @@ require "./spec/node"
|
||||||
module Spectator
|
module Spectator
|
||||||
# Standard example that runs a test case.
|
# Standard example that runs a test case.
|
||||||
class Example < Spec::Node
|
class Example < Spec::Node
|
||||||
|
# User-defined keywords used for filtering and behavior modification.
|
||||||
|
alias Tags = Set(String)
|
||||||
|
|
||||||
# Currently running example.
|
# Currently running example.
|
||||||
class_getter! current : Example
|
class_getter! current : Example
|
||||||
|
|
||||||
|
@ -19,6 +21,9 @@ module Spectator
|
||||||
# Retrieves the result of the last time the example ran.
|
# Retrieves the result of the last time the example ran.
|
||||||
getter result : Result = PendingResult.new
|
getter result : Result = PendingResult.new
|
||||||
|
|
||||||
|
# User-defined keywords used for filtering and behavior modification.
|
||||||
|
getter tags : Set(String)
|
||||||
|
|
||||||
# Creates the example.
|
# Creates the example.
|
||||||
# An instance to run the test code in is given by *context*.
|
# An instance to run the test code in is given by *context*.
|
||||||
# The *entrypoint* defines the test code (typically inside *context*).
|
# The *entrypoint* defines the test code (typically inside *context*).
|
||||||
|
@ -27,9 +32,8 @@ module Spectator
|
||||||
# The *source* tracks where the example exists in source code.
|
# The *source* tracks where the example exists in source code.
|
||||||
# The example will be assigned to *group* if it is provided.
|
# The example will be assigned to *group* if it is provided.
|
||||||
def initialize(@context : Context, @entrypoint : self ->,
|
def initialize(@context : Context, @entrypoint : self ->,
|
||||||
name : String? = nil, source : Source? = nil, group : ExampleGroup? = nil, metadata = NamedTuple.new)
|
name : String? = nil, source : Source? = nil, group : ExampleGroup? = nil, @tags = Tags.new)
|
||||||
super(name, source, group)
|
super(name, source, group)
|
||||||
@metadata = Wrapper.new(metadata)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a dynamic example.
|
# Creates a dynamic example.
|
||||||
|
@ -40,11 +44,10 @@ module Spectator
|
||||||
# The *source* tracks where the example exists in source code.
|
# The *source* tracks where the example exists in source code.
|
||||||
# The example will be assigned to *group* if it is provided.
|
# The example will be assigned to *group* if it is provided.
|
||||||
def initialize(name : String? = nil, source : Source? = nil, group : ExampleGroup? = nil,
|
def initialize(name : String? = nil, source : Source? = nil, group : ExampleGroup? = nil,
|
||||||
metadata = NamedTuple.new, &block : self ->)
|
@tags = Tags.new, &block : self ->)
|
||||||
super(name, source, group)
|
super(name, source, group)
|
||||||
@context = NullContext.new
|
@context = NullContext.new
|
||||||
@entrypoint = block
|
@entrypoint = block
|
||||||
@metadata = Wrapper.new(metadata)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes the test case.
|
# Executes the test case.
|
||||||
|
@ -98,11 +101,6 @@ module Spectator
|
||||||
with context yield
|
with context yield
|
||||||
end
|
end
|
||||||
|
|
||||||
protected def unwrap_metadata(klass)
|
|
||||||
metadata = @metadata.get(klass)
|
|
||||||
MetadataExample.new(self, metadata)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Casts the example's test context to a specific type.
|
# Casts the example's test context to a specific type.
|
||||||
# This is an advanced method intended for internal usage only.
|
# This is an advanced method intended for internal usage only.
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
require "./example"
|
|
||||||
|
|
||||||
module Spectator
|
|
||||||
class MetadataExample(Metadata)
|
|
||||||
getter metadata : Metadata
|
|
||||||
|
|
||||||
def initialize(@example : Example, @metadata : Metadata)
|
|
||||||
end
|
|
||||||
|
|
||||||
forward_missing_to @example
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -93,8 +93,8 @@ module Spectator
|
||||||
# It is expected that the test code runs when the block is called.
|
# It is expected that the test code runs when the block is called.
|
||||||
#
|
#
|
||||||
# The newly created example is returned.
|
# The newly created example is returned.
|
||||||
def add_example(name, source, context, metadata, &block : Example -> _) : Example
|
def add_example(name, source, context, tags, &block : Example -> _) : Example
|
||||||
Log.trace { "Add example: #{name} @ #{source}; metadata: #{metadata}" }
|
Log.trace { "Add example: #{name} @ #{source}; tags: #{tags}" }
|
||||||
Example.new(context, block, name, source, current_group)
|
Example.new(context, block, name, source, current_group)
|
||||||
# The example is added to the current group by `Example` initializer.
|
# The example is added to the current group by `Example` initializer.
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,9 +28,9 @@ class SpectatorTestContext < SpectatorContext
|
||||||
@subject.get { _spectator_implicit_subject }
|
@subject.get { _spectator_implicit_subject }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Initial metadata for tests.
|
# Initial tags for tests.
|
||||||
# This method should be overridden by example groups and examples.
|
# This method should be overridden by example groups and examples.
|
||||||
def self._spectator_metadata
|
def self._spectator_tags
|
||||||
NamedTuple.new
|
::Spectator::Example::Tags.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue