mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Define test context types
This commit is contained in:
parent
d31b8f4093
commit
9c6502234b
4 changed files with 43 additions and 0 deletions
8
src/spectator/context.cr
Normal file
8
src/spectator/context.cr
Normal file
|
@ -0,0 +1,8 @@
|
|||
require "../spectator_context"
|
||||
|
||||
module Spectator
|
||||
# Base class that all test cases run in.
|
||||
# This type is used to store all test case contexts as a single type.
|
||||
# The instance must be downcast to the correct type before calling a context method.
|
||||
alias Context = ::SpectatorContext
|
||||
end
|
18
src/spectator/context_delegate.cr
Normal file
18
src/spectator/context_delegate.cr
Normal file
|
@ -0,0 +1,18 @@
|
|||
require "./context"
|
||||
require "./context_method"
|
||||
|
||||
module Spectator
|
||||
# Stores a test context and a method to call within it.
|
||||
struct ContextDelegate
|
||||
# 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 : ContextMethod)
|
||||
end
|
||||
|
||||
# Invokes a method in the test context.
|
||||
def call
|
||||
@method.call(@context)
|
||||
end
|
||||
end
|
||||
end
|
10
src/spectator/context_method.cr
Normal file
10
src/spectator/context_method.cr
Normal file
|
@ -0,0 +1,10 @@
|
|||
require "./context"
|
||||
|
||||
module Spectator
|
||||
# Encapsulates a method in a 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.
|
||||
alias ContextMethod = Context ->
|
||||
end
|
7
src/spectator_contnext.cr
Normal file
7
src/spectator_contnext.cr
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Base class that all test cases run in.
|
||||
# This type is used to store all test case contexts as a single type.
|
||||
# The instance must be downcast to the correct type before calling a context method.
|
||||
# This type is intentionally outside the `Spectator` module.
|
||||
# The reason for this is to prevent name collision when using the DSL to define a spec.
|
||||
abstract class SpectatorContext
|
||||
end
|
Loading…
Reference in a new issue