mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Introduce _spectator_stub_for_method? utility method
This commit is contained in:
parent
3961662bf6
commit
4b21c9e6c1
5 changed files with 16 additions and 5 deletions
|
@ -110,6 +110,10 @@ module Spectator
|
|||
stub
|
||||
end
|
||||
|
||||
private def _spectator_stub_for_method?(method : Symbol) : Bool
|
||||
@stubs.any? { |stub| stub.method == method }
|
||||
end
|
||||
|
||||
# Returns the double's name formatted for user output.
|
||||
private def _spectator_stubbed_name : String
|
||||
{% if anno = @type.annotation(StubbedName) %}
|
||||
|
@ -130,7 +134,7 @@ module Spectator
|
|||
|
||||
private def _spectator_abstract_stub_fallback(call : MethodCall)
|
||||
Log.info do
|
||||
break unless @stubs.any? { |stub| stub.method == call.method }
|
||||
break unless _spectator_stub_for_method?(call.method)
|
||||
|
||||
"Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)."
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ module Spectator
|
|||
end
|
||||
|
||||
private def _spectator_stub_fallback(call : MethodCall, &)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
if _spectator_stub_for_method?(call.method)
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
else
|
||||
|
|
|
@ -23,10 +23,14 @@ module Spectator
|
|||
@_spectator_stubs.unshift(stub)
|
||||
end
|
||||
|
||||
def _spectator_find_stub(call : ::Spectator::MethodCall) : ::Spectator::Stub?
|
||||
private def _spectator_find_stub(call : ::Spectator::MethodCall) : ::Spectator::Stub?
|
||||
@_spectator_stubs.find &.===(call)
|
||||
end
|
||||
|
||||
private def _spectator_stub_for_method?(method : Symbol) : Bool
|
||||
@_spectator_stubs.any? { |stub| stub.method == method }
|
||||
end
|
||||
|
||||
# Returns the mock's name formatted for user output.
|
||||
private def _spectator_stubbed_name : String
|
||||
\{% if anno = @type.annotation(::Spectator::StubbedName) %}
|
||||
|
|
|
@ -24,7 +24,7 @@ module Spectator
|
|||
end
|
||||
|
||||
private def _spectator_abstract_stub_fallback(call : MethodCall)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
if _spectator_stub_for_method?(call.method)
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
else
|
||||
|
@ -40,7 +40,7 @@ module Spectator
|
|||
|
||||
# Default implementation that raises a `TypeCastError` since the return type isn't self.
|
||||
private def _spectator_abstract_stub_fallback(call : MethodCall, type)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
if _spectator_stub_for_method?(call.method)
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
else
|
||||
|
|
|
@ -22,6 +22,9 @@ module Spectator
|
|||
# or nil if no stubs satisfy it.
|
||||
abstract def _spectator_find_stub(call : MethodCall) : Stub?
|
||||
|
||||
# Utility method that looks for stubs for methods with the name specified.
|
||||
abstract def _spectator_stub_for_method?(method : Symbol) : Bool
|
||||
|
||||
# Defines a stub to change the behavior of a method.
|
||||
abstract def _spectator_define_stub(stub : Stub) : Nil
|
||||
|
||||
|
|
Loading…
Reference in a new issue