diff --git a/src/spectator/mocks/stubs.cr b/src/spectator/mocks/stubs.cr index f9f4e2c..469566a 100644 --- a/src/spectator/mocks/stubs.cr +++ b/src/spectator/mocks/stubs.cr @@ -83,7 +83,14 @@ 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) { raise "Cannot call original implementation of {{name}} - it won't return." } + # NOTE: This may break at some point if the Crystal compiler gets smarter. + # The `nil` after raise changes the return type of the method from `NoReturn` to `Nil`. + # Technically, the `nil` will never be reached and if the compiler realizes it, + # the return type could become `NoReturn` + return %stub.call!(%args) do + raise "Cannot call original implementation of {{name}} - it won't return." + nil + end else return %stub.call!(%args) { {{original}} } end @@ -106,7 +113,14 @@ 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) { raise "Cannot call original implementation of {{name}} - it won't return." } + # NOTE: This may break at some point if the Crystal compiler gets smarter. + # The `nil` after raise changes the return type of the method from `NoReturn` to `Nil`. + # Technically, the `nil` will never be reached and if the compiler realizes it, + # the return type could become `NoReturn` + return %stub.call!(%args) do + raise "Cannot call original implementation of {{name}} - it won't return." + nil + end else return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } } end