mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow uninteresting messages through mocks
If they are stubbed, but don't match arguments, raise an error.
This commit is contained in:
parent
4b21c9e6c1
commit
6f04e0b9da
1 changed files with 21 additions and 6 deletions
|
@ -12,7 +12,16 @@ module Spectator
|
||||||
# The stubbed method returns the value returned by this method.
|
# The stubbed method returns the value returned by this method.
|
||||||
# This method can also raise an error if it's impossible to return something.
|
# This method can also raise an error if it's impossible to return something.
|
||||||
def _spectator_stub_fallback(call : MethodCall, &)
|
def _spectator_stub_fallback(call : MethodCall, &)
|
||||||
raise "oof"
|
if _spectator_stub_for_method?(call.method)
|
||||||
|
# FIXME: Don't log to top-level Spectator logger (use mock or double logger).
|
||||||
|
Spectator::Log.info do
|
||||||
|
"Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)."
|
||||||
|
end
|
||||||
|
|
||||||
|
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||||
|
end
|
||||||
|
|
||||||
|
yield # Uninteresting message, allow through.
|
||||||
end
|
end
|
||||||
|
|
||||||
# Method called when a stub isn't found.
|
# Method called when a stub isn't found.
|
||||||
|
@ -22,8 +31,8 @@ module Spectator
|
||||||
# Yield to call the original method's implementation.
|
# Yield to call the original method's implementation.
|
||||||
# The stubbed method returns the value returned by this method.
|
# The stubbed method returns the value returned by this method.
|
||||||
# This method can also raise an error if it's impossible to return something.
|
# This method can also raise an error if it's impossible to return something.
|
||||||
def _spectator_stub_fallback(call : MethodCall, type, &)
|
def _spectator_stub_fallback(call : MethodCall, _type, &)
|
||||||
raise "oof"
|
_spectator_stub_fallback(call) { yield }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Method called when a stub isn't found.
|
# Method called when a stub isn't found.
|
||||||
|
@ -34,7 +43,13 @@ module Spectator
|
||||||
# The stubbed method returns the value returned by this method.
|
# The stubbed method returns the value returned by this method.
|
||||||
# This method can also raise an error if it's impossible to return something.
|
# This method can also raise an error if it's impossible to return something.
|
||||||
def _spectator_abstract_stub_fallback(call : MethodCall)
|
def _spectator_abstract_stub_fallback(call : MethodCall)
|
||||||
raise "oof"
|
Spectator::Log.info do # FIXME: Don't log to top-level Spectator logger (use mock or double logger).
|
||||||
|
break unless _spectator_stub_for_method?(call.method)
|
||||||
|
|
||||||
|
"Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)."
|
||||||
|
end
|
||||||
|
|
||||||
|
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Method called when a stub isn't found.
|
# Method called when a stub isn't found.
|
||||||
|
@ -45,8 +60,8 @@ module Spectator
|
||||||
# The expected return type is provided by *type*.
|
# The expected return type is provided by *type*.
|
||||||
# The stubbed method returns the value returned by this method.
|
# The stubbed method returns the value returned by this method.
|
||||||
# This method can also raise an error if it's impossible to return something.
|
# This method can also raise an error if it's impossible to return something.
|
||||||
def _spectator_abstract_stub_fallback(call : MethodCall, type)
|
def _spectator_abstract_stub_fallback(call : MethodCall, _type)
|
||||||
raise "oof"
|
_spectator_abstract_stub_fallback(call)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue