From 82f26dbb9175d2b6bd7e0666eb26217f82c20df4 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 8 Jul 2021 11:36:07 -0600 Subject: [PATCH] Don't return nil for NoReturn stubs Raise instead, which prevents making the method's return type nilable. --- src/spectator/mocks/stubs.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spectator/mocks/stubs.cr b/src/spectator/mocks/stubs.cr index 4e7cd10..f9f4e2c 100644 --- a/src/spectator/mocks/stubs.cr +++ b/src/spectator/mocks/stubs.cr @@ -83,7 +83,7 @@ module Spectator::Mocks %harness.mocks.record_call(self, %call) if (%stub = %harness.mocks.find_stub(self, %call)) if typeof({{original}}) == NoReturn - return %stub.call!(%args) { nil } + return %stub.call!(%args) { raise "Cannot call original implementation of {{name}} - it won't return." } else return %stub.call!(%args) { {{original}} } end @@ -106,7 +106,7 @@ module Spectator::Mocks %harness.mocks.record_call(self, %call) if (%stub = %harness.mocks.find_stub(self, %call)) if typeof({{original}}) == NoReturn - return %stub.call!(%args) { nil } + return %stub.call!(%args) { raise "Cannot call original implementation of {{name}} - it won't return." } else return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } } end