mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Better error for when stubs don't match return type
This commit is contained in:
parent
e6c1a6b2d2
commit
d1b54ad48f
1 changed files with 10 additions and 2 deletions
|
@ -41,7 +41,11 @@ module Spectator::Mocks
|
||||||
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
||||||
@spectator_stub_calls << %call
|
@spectator_stub_calls << %call
|
||||||
if (%stub = @spectator_stubs.find(&.callable?(%call)))
|
if (%stub = @spectator_stubs.find(&.callable?(%call)))
|
||||||
%stub.as(::Spectator::Mocks::GenericMethodStub(typeof(%method({{args.splat}})))).call(%args)
|
if (%cast = %stub.as?(::Spectator::Mocks::GenericMethodStub(typeof(%method({{args.splat}})))))
|
||||||
|
%cast.call(%args)
|
||||||
|
else
|
||||||
|
raise "The return type of stub #{%stub} doesn't match the expected type #{typeof(%method({{args.splat}}))}"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
%method({{args.splat}})
|
%method({{args.splat}})
|
||||||
end
|
end
|
||||||
|
@ -52,7 +56,11 @@ module Spectator::Mocks
|
||||||
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
||||||
@spectator_stub_calls << %call
|
@spectator_stub_calls << %call
|
||||||
if (%stub = @spectator_stubs.find(&.callable?(%call)))
|
if (%stub = @spectator_stubs.find(&.callable?(%call)))
|
||||||
%stub.as(::Spectator::Mocks::GenericMethodStub(typeof(%method({{args.splat}}) { |*%yield_args| yield *%yield_args }))).call(%args)
|
if (%cast = %stub.as?(::Spectator::Mocks::GenericMethodStub(typeof(%method({{args.splat}}) { |*%yield_args| yield *%yield_args }))))
|
||||||
|
%cast.call(%args)
|
||||||
|
else
|
||||||
|
raise "The return type of stub #{%stub} doesn't match the expected type #{typeof(%method({{args.splat}}) { |*%ya| yield *%ya })}"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
%method({{args.splat}}) do |*%yield_args|
|
%method({{args.splat}}) do |*%yield_args|
|
||||||
yield *%yield_args
|
yield *%yield_args
|
||||||
|
|
Loading…
Reference in a new issue