mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Workaround for stubbing NoReturn method with Nil
Fixes spec/issues/github_issue_29_spec.cr:15
This commit is contained in:
parent
82f26dbb91
commit
06f9f380c9
1 changed files with 16 additions and 2 deletions
|
@ -83,7 +83,14 @@ 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) { 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
|
else
|
||||||
return %stub.call!(%args) { {{original}} }
|
return %stub.call!(%args) { {{original}} }
|
||||||
end
|
end
|
||||||
|
@ -106,7 +113,14 @@ 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) { 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
|
else
|
||||||
return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } }
|
return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue