From 92dbfc2a8e37f7eacffe49d45bbc79572e42574f Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 2 Jul 2021 21:52:56 -0600 Subject: [PATCH] Avoid calling NoReturn methods --- src/spectator/mocks/stubs.cr | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/spectator/mocks/stubs.cr b/src/spectator/mocks/stubs.cr index ba20cbe..4e7cd10 100644 --- a/src/spectator/mocks/stubs.cr +++ b/src/spectator/mocks/stubs.cr @@ -82,7 +82,11 @@ module Spectator::Mocks %call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args) %harness.mocks.record_call(self, %call) if (%stub = %harness.mocks.find_stub(self, %call)) - return %stub.call!(%args) { {{original}} } + if typeof({{original}}) == NoReturn + return %stub.call!(%args) { nil } + else + return %stub.call!(%args) { {{original}} } + end end {% if body && !body.is_a?(Nop) || return_type.is_a?(ArrayLiteral) %} @@ -101,7 +105,11 @@ module Spectator::Mocks %call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args) %harness.mocks.record_call(self, %call) if (%stub = %harness.mocks.find_stub(self, %call)) - return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } } + if typeof({{original}}) == NoReturn + return %stub.call!(%args) { nil } + else + return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } } + end end {% if body && !body.is_a?(Nop) || return_type.is_a?(ArrayLiteral) %}