mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Somewhat functional metadata unwrap
This commit is contained in:
parent
466a388558
commit
a56b1e0eb1
3 changed files with 24 additions and 3 deletions
|
@ -53,7 +53,7 @@ module Spectator::DSL
|
||||||
\{% if block.args.empty? %}
|
\{% if block.args.empty? %}
|
||||||
\%test
|
\%test
|
||||||
\{% else %}
|
\{% else %}
|
||||||
\%test(example)
|
\%test(example.unwrap_metadata(typeof(\{{@type.name}}.\%metadata)))
|
||||||
\{% end %}
|
\{% end %}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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"
|
||||||
|
@ -26,8 +27,9 @@ 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)
|
name : String? = nil, source : Source? = nil, group : ExampleGroup? = nil, metadata = NamedTuple.new)
|
||||||
super(name, source, group)
|
super(name, source, group)
|
||||||
|
@metadata = Wrapper.new(metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a dynamic example.
|
# Creates a dynamic example.
|
||||||
|
@ -37,9 +39,11 @@ module Spectator
|
||||||
# It can be a `Symbol` to describe a type.
|
# It can be a `Symbol` to describe a type.
|
||||||
# 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, &block : self ->)
|
def initialize(name : String? = nil, source : Source? = nil, group : ExampleGroup? = nil,
|
||||||
|
metadata = NamedTuple.new, &block : self ->)
|
||||||
@context = NullContext.new
|
@context = NullContext.new
|
||||||
@entrypoint = block
|
@entrypoint = block
|
||||||
|
@metadata = Wrapper.new(metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes the test case.
|
# Executes the test case.
|
||||||
|
@ -93,6 +97,11 @@ 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.
|
||||||
#
|
#
|
||||||
|
|
12
src/spectator/metadata_example.cr
Normal file
12
src/spectator/metadata_example.cr
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
require "./example"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
class MetadataExample(Metadata)
|
||||||
|
getter metadata : Metadata
|
||||||
|
|
||||||
|
def initialize(@example : Example, @metadata : Metadata)
|
||||||
|
end
|
||||||
|
|
||||||
|
forward_missing_to @example
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue