mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Create example context variants
This commit is contained in:
parent
3f7e0d7882
commit
b866bc7e08
4 changed files with 34 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
require "./context"
|
require "./context"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
# Encapsulates a method in a context.
|
# Encapsulates a method in a test context.
|
||||||
# This could be used to invoke a test case or hook method.
|
# This could be used to invoke a test case or hook method.
|
||||||
# The context is passed as an argument.
|
# The context is passed as an argument.
|
||||||
# The proc should downcast the context instance to the desired type
|
# The proc should downcast the context instance to the desired type
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require "./context_delegate"
|
require "./example_context_delegate"
|
||||||
require "./example_group"
|
require "./example_group"
|
||||||
require "./example_node"
|
require "./example_node"
|
||||||
require "./result"
|
require "./result"
|
||||||
|
@ -19,7 +19,7 @@ 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(@delegate : ContextDelegate,
|
def initialize(@delegate : ExampleContextDelegate,
|
||||||
name : String | Symbol? = nil, source : Source? = nil, group : ExampleGroup? = nil)
|
name : String | Symbol? = nil, source : Source? = nil, group : ExampleGroup? = nil)
|
||||||
super(name, source, group)
|
super(name, source, group)
|
||||||
end
|
end
|
||||||
|
|
20
src/spectator/example_context_delegate.cr
Normal file
20
src/spectator/example_context_delegate.cr
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
require "./context"
|
||||||
|
require "./example_context_method"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
# Stores a test context and a method to call within it.
|
||||||
|
# This is a variant of `ContextDelegate` that accepts the current running example.
|
||||||
|
struct ExampleContextDelegate
|
||||||
|
# Creates the delegate.
|
||||||
|
# The *context* is the instance of the test context.
|
||||||
|
# The *method* is proc that downcasts *context* and calls a method on it.
|
||||||
|
def initialize(@context : Context, @method : ExampleContextMethod)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Invokes a method in the test context.
|
||||||
|
# The *example* is the current running example.
|
||||||
|
def call(example : Example)
|
||||||
|
@method.call(example, @context)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
11
src/spectator/example_context_method.cr
Normal file
11
src/spectator/example_context_method.cr
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
require "./context"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
# Encapsulates a method in a test context.
|
||||||
|
# This could be used to invoke a test case or hook method.
|
||||||
|
# The context is passed as an argument.
|
||||||
|
# The proc should downcast the context instance to the desired type
|
||||||
|
# and call a method on that context.
|
||||||
|
# The current example is also passed as an argument.
|
||||||
|
alias ExampleContextMethod = Example, Context ->
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue