mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add null constructor
This commit is contained in:
parent
7d0ba752e9
commit
cf422eca02
1 changed files with 9 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
require "./context"
|
||||
require "./context_method"
|
||||
require "./null_context"
|
||||
|
||||
module Spectator
|
||||
# Stores a test context and a method to call within it.
|
||||
|
@ -10,6 +11,14 @@ module Spectator
|
|||
def initialize(@context : Context, @method : ContextMethod)
|
||||
end
|
||||
|
||||
# Creates a delegate with a null context.
|
||||
# The context will be ignored and the block will be executed in its original scope.
|
||||
def self.null(&block : -> _)
|
||||
context = NullContext.new
|
||||
method = ContextMethod.new { block.call }
|
||||
new(context, method)
|
||||
end
|
||||
|
||||
# Invokes a method in the test context.
|
||||
def call
|
||||
@method.call(@context)
|
||||
|
|
Loading…
Reference in a new issue