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