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? %}
|
||||
\%test
|
||||
\{% else %}
|
||||
\%test(example)
|
||||
\%test(example.unwrap_metadata(typeof(\{{@type.name}}.\%metadata)))
|
||||
\{% end %}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require "./example_context_delegate"
|
||||
require "./example_group"
|
||||
require "./harness"
|
||||
require "./metadata_example"
|
||||
require "./pending_result"
|
||||
require "./result"
|
||||
require "./source"
|
||||
|
@ -26,8 +27,9 @@ module Spectator
|
|||
# The *source* tracks where the example exists in source code.
|
||||
# The example will be assigned to *group* if it is provided.
|
||||
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)
|
||||
@metadata = Wrapper.new(metadata)
|
||||
end
|
||||
|
||||
# Creates a dynamic example.
|
||||
|
@ -37,9 +39,11 @@ module Spectator
|
|||
# It can be a `Symbol` to describe a type.
|
||||
# The *source* tracks where the example exists in source code.
|
||||
# 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
|
||||
@entrypoint = block
|
||||
@metadata = Wrapper.new(metadata)
|
||||
end
|
||||
|
||||
# Executes the test case.
|
||||
|
@ -93,6 +97,11 @@ module Spectator
|
|||
with context yield
|
||||
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.
|
||||
# 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