Don't invoke fallback if there are stubs for the method

This commit is contained in:
Michael Miller 2022-03-25 22:30:39 -06:00
parent fc51c1d730
commit 28488d308e
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2

View file

@ -102,21 +102,25 @@ module Spectator
end
private def _spectator_stub_fallback(call : MethodCall, &)
Log.trace { "Fallback for #{call} - call original" }
yield
if @stubs.any? { |stub| stub.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
Log.trace { "Fallback for #{call} - call original" }
yield
end
end
private def _spectator_stub_fallback(call : MethodCall, type, &)
Log.trace { "Fallback for #{call} - call original" }
yield
private def _spectator_stub_fallback(call : MethodCall, _type, &)
_spectator_stub_fallback(call) { yield }
end
private def _spectator_abstract_stub_fallback(call : MethodCall)
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
end
private def _spectator_abstract_stub_fallback(call : MethodCall, type)
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
private def _spectator_abstract_stub_fallback(call : MethodCall, _type)
_spectator_abstract_stub_fallback(call)
end
# "Hide" existing methods and methods from ancestors by overriding them.