From cf422eca02f0b743578029f7171eba0458243d47 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 9 Jan 2021 10:56:33 -0700 Subject: [PATCH] Add null constructor --- src/spectator/context_delegate.cr | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/spectator/context_delegate.cr b/src/spectator/context_delegate.cr index 1beef83..ac927b9 100644 --- a/src/spectator/context_delegate.cr +++ b/src/spectator/context_delegate.cr @@ -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)