mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Pass original (and type constraint) to stub via block
This commit is contained in:
parent
51a47fec98
commit
2dee50f19e
5 changed files with 9 additions and 7 deletions
|
@ -12,7 +12,9 @@ module Spectator::Mocks
|
||||||
call = ::Spectator::Mocks::GenericMethodCall.new({{call.name.symbolize}}, args)
|
call = ::Spectator::Mocks::GenericMethodCall.new({{call.name.symbolize}}, args)
|
||||||
::Spectator::Harness.current.mocks.record_call(self, call)
|
::Spectator::Harness.current.mocks.record_call(self, call)
|
||||||
if (stub = ::Spectator::Harness.current.mocks.find_stub(self, call))
|
if (stub = ::Spectator::Harness.current.mocks.find_stub(self, call))
|
||||||
stub.call!(args, typeof(@values.fetch({{call.name.symbolize}}) { raise }))
|
stub.call!(args) do
|
||||||
|
@values.fetch({{call.name.symbolize}}) { raise "Consistency error - method stubbed with no implementation" }
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@values.fetch({{call.name.symbolize}}) do
|
@values.fetch({{call.name.symbolize}}) do
|
||||||
return nil if ::Spectator::Harness.current.mocks.expected?(self, {{call.name.symbolize}})
|
return nil if ::Spectator::Harness.current.mocks.expected?(self, {{call.name.symbolize}})
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Spectator::Mocks
|
||||||
call = ::Spectator::Mocks::GenericMethodCall.new({{call.name.symbolize}}, args)
|
call = ::Spectator::Mocks::GenericMethodCall.new({{call.name.symbolize}}, args)
|
||||||
::Spectator::Harness.current.mocks.record_call(self, call)
|
::Spectator::Harness.current.mocks.record_call(self, call)
|
||||||
if (stub = ::Spectator::Harness.current.mocks.find_stub(self, call))
|
if (stub = ::Spectator::Harness.current.mocks.find_stub(self, call))
|
||||||
stub.call!(args, typeof(@values.fetch({{call.name.symbolize}}) { self }))
|
stub.call!(args) { @values.fetch({{call.name.symbolize}}) { self } }
|
||||||
else
|
else
|
||||||
@values.fetch({{call.name.symbolize}}) { self }
|
@values.fetch({{call.name.symbolize}}) { self }
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ module Spectator::Mocks
|
||||||
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
||||||
::Spectator::Harness.current.mocks.record_call(self, %call)
|
::Spectator::Harness.current.mocks.record_call(self, %call)
|
||||||
if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call))
|
if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call))
|
||||||
%stub.call!(%args, typeof(%method({{args.splat}})))
|
%stub.call!(%args) { %method({{args.splat}}) }
|
||||||
else
|
else
|
||||||
%method({{args.splat}})
|
%method({{args.splat}})
|
||||||
end
|
end
|
||||||
|
@ -50,7 +50,7 @@ module Spectator::Mocks
|
||||||
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
||||||
::Spectator::Harness.current.mocks.record_call(self, %call)
|
::Spectator::Harness.current.mocks.record_call(self, %call)
|
||||||
if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call))
|
if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call))
|
||||||
%stub.call!(%args, typeof(%method({{args.splat}}) { |*%ya| yield *%ya }))
|
%stub.call!(%args) { %method({{args.splat}}) { |*%ya| yield *%ya } }
|
||||||
else
|
else
|
||||||
%method({{args.splat}}) do |*%yield_args|
|
%method({{args.splat}}) do |*%yield_args|
|
||||||
yield *%yield_args
|
yield *%yield_args
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Spectator::Mocks
|
||||||
|
|
||||||
abstract def call(args : GenericArguments(T, NT)) forall T, NT
|
abstract def call(args : GenericArguments(T, NT)) forall T, NT
|
||||||
|
|
||||||
def call!(args : GenericArguments(T, NT), _rt : RT.class) : RT forall T, NT, RT
|
def call!(args : GenericArguments(T, NT), &original : -> RT) : RT forall T, NT, RT
|
||||||
value = call(args)
|
value = call(args)
|
||||||
if value.is_a?(RT)
|
if value.is_a?(RT)
|
||||||
value.as(RT)
|
value.as(RT)
|
||||||
|
|
|
@ -56,7 +56,7 @@ module Spectator::Mocks
|
||||||
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
||||||
%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))
|
||||||
return %stub.call!(%args, typeof({{original}}({{args.splat}})))
|
return %stub.call!(%args) { {{original}}({{args.splat}}) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
{{original}}({{args.splat}})
|
{{original}}({{args.splat}})
|
||||||
|
@ -68,7 +68,7 @@ module Spectator::Mocks
|
||||||
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
|
||||||
%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))
|
||||||
return %stub.call!(%args, typeof({{original}}({{args.splat}}) { |*%ya| yield *%ya }))
|
return %stub.call!(%args) { {{original}}({{args.splat}}) { |*%ya| yield *%ya } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
{{original}}({{args.splat}}) do |*%yield_args|
|
{{original}}({{args.splat}}) do |*%yield_args|
|
||||||
|
|
Loading…
Reference in a new issue