Don't return nil for NoReturn stubs

Raise instead, which prevents making the method's return type nilable.
This commit is contained in:
Michael Miller 2021-07-08 11:36:07 -06:00
parent 78de2be994
commit 82f26dbb91
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD

View file

@ -83,7 +83,7 @@ module Spectator::Mocks
%harness.mocks.record_call(self, %call) %harness.mocks.record_call(self, %call)
if (%stub = %harness.mocks.find_stub(self, %call)) if (%stub = %harness.mocks.find_stub(self, %call))
if typeof({{original}}) == NoReturn 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 else
return %stub.call!(%args) { {{original}} } return %stub.call!(%args) { {{original}} }
end end
@ -106,7 +106,7 @@ module Spectator::Mocks
%harness.mocks.record_call(self, %call) %harness.mocks.record_call(self, %call)
if (%stub = %harness.mocks.find_stub(self, %call)) if (%stub = %harness.mocks.find_stub(self, %call))
if typeof({{original}}) == NoReturn 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 else
return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } } return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } }
end end