mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Store calls to mocks and doubles
This commit is contained in:
parent
c98edcec5d
commit
3589f23475
9 changed files with 158 additions and 1 deletions
|
@ -117,6 +117,10 @@ module Spectator
|
|||
@calls << call
|
||||
end
|
||||
|
||||
def _spectator_calls
|
||||
@calls
|
||||
end
|
||||
|
||||
def _spectator_calls(method : Symbol) : Enumerable(MethodCall)
|
||||
@calls.select { |call| call.method == method }
|
||||
end
|
||||
|
@ -164,6 +168,8 @@ module Spectator
|
|||
Log.trace { "Got undefined method `{{call.name}}({{*call.args}}{% if call.named_args %}{% unless call.args.empty? %}, {% end %}{{*call.named_args}}{% end %}){% if call.block %} { ... }{% end %}`" }
|
||||
args = ::Spectator::Arguments.capture({{call.args.splat(", ")}}{% if call.named_args %}{{*call.named_args}}{% end %})
|
||||
call = ::Spectator::MethodCall.new({{call.name.symbolize}}, args)
|
||||
_spectator_record_call(call)
|
||||
|
||||
raise ::Spectator::UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
nil # Necessary for compiler to infer return type as nil. Avoids runtime "can't execute ... `x` has no type errors".
|
||||
end
|
||||
|
|
|
@ -48,6 +48,7 @@ module Spectator
|
|||
# Capture information about the call.
|
||||
%args = ::Spectator::Arguments.capture({{call.args.splat(", ")}}{% if call.named_args %}{{*call.named_args}}{% end %})
|
||||
%call = ::Spectator::MethodCall.new({{call.name.symbolize}}, %args)
|
||||
_spectator_record_call(%call)
|
||||
|
||||
# Attempt to find a stub that satisfies the method call and arguments.
|
||||
if %stub = _spectator_find_stub(%call)
|
||||
|
|
|
@ -52,7 +52,7 @@ module Spectator
|
|||
@_spectator_stubs = nil
|
||||
end
|
||||
|
||||
private getter _spectator_calls = [] of ::Spectator::MethodCall
|
||||
getter _spectator_calls = [] of ::Spectator::MethodCall
|
||||
|
||||
# Returns the mock's name formatted for user output.
|
||||
private def _spectator_stubbed_name : String
|
||||
|
|
|
@ -56,6 +56,7 @@ module Spectator
|
|||
# Capture information about the call.
|
||||
%args = ::Spectator::Arguments.capture({{call.args.splat(", ")}}{% if call.named_args %}{{*call.named_args}}{% end %})
|
||||
%call = ::Spectator::MethodCall.new({{call.name.symbolize}}, %args)
|
||||
_spectator_record_call(%call)
|
||||
|
||||
# Attempt to find a stub that satisfies the method call and arguments.
|
||||
if %stub = _spectator_find_stub(%call)
|
||||
|
|
|
@ -133,6 +133,7 @@ module Spectator
|
|||
{% if method.double_splat %}**{{method.double_splat}}{% end %}
|
||||
)
|
||||
%call = ::Spectator::MethodCall.new({{method.name.symbolize}}, %args)
|
||||
_spectator_record_call(%call)
|
||||
|
||||
# Attempt to find a stub that satisfies the method call and arguments.
|
||||
# Finding a suitable stub is delegated to the type including the `Stubbable` module.
|
||||
|
@ -222,6 +223,7 @@ module Spectator
|
|||
{% if method.double_splat %}**{{method.double_splat}}{% end %}
|
||||
)
|
||||
%call = ::Spectator::MethodCall.new({{method.name.symbolize}}, %args)
|
||||
_spectator_record_call(%call)
|
||||
|
||||
# Attempt to find a stub that satisfies the method call and arguments.
|
||||
# Finding a suitable stub is delegated to the type including the `Stubbable` module.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue