More logging

This commit is contained in:
Michael Miller 2022-03-24 02:39:15 -06:00
parent b97a367be7
commit fc51c1d730
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
3 changed files with 13 additions and 2 deletions

View file

@ -81,6 +81,7 @@ module Spectator
#
# NOTE: Defining a stub for a method not defined in the double's type has no effect.
protected def _spectator_define_stub(stub : Stub) : Nil
Log.debug { "Defined stub for #{_spectator_stubbed_name} #{stub}" }
@stubs.unshift(stub)
end
@ -101,10 +102,12 @@ module Spectator
end
private def _spectator_stub_fallback(call : MethodCall, &)
Log.trace { "Fallback for #{call} - call original" }
yield
end
private def _spectator_stub_fallback(call : MethodCall, type, &)
Log.trace { "Fallback for #{call} - call original" }
yield
end
@ -124,7 +127,7 @@ module Spectator
# Handle all methods but only respond to configured messages.
# Raises an `UnexpectedMessage` error for non-configures messages.
macro method_missing(call)
Log.debug { "Got undefined method `{{call.name}}({{*call.args}}{% if call.named_args %}{% unless call.args.empty? %}, {% end %}{{*call.named_args}}{% end %}){% if call.block %} { ... }{% end %}`" }
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)
raise ::Spectator::UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")

View file

@ -28,6 +28,8 @@ module Spectator
# Handles all messages.
macro method_missing(call)
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 %}`" }
# 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)

View file

@ -23,22 +23,27 @@ module Spectator
end
private def _spectator_stub_fallback(call : MethodCall, &)
Log.trace { "Fallback for #{call} - return self" }
self
end
private def _spectator_stub_fallback(call : MethodCall, type : self, &)
Log.trace { "Fallback for #{call} - return self" }
self
end
private def _spectator_stub_fallback(call : MethodCall, type, &)
Log.trace { "Fallback for #{call} - call original" }
yield
end
private def _spectator_abstract_stub_fallback(call : MethodCall)
Log.trace { "Fallback for #{call} - return self" }
self
end
private def _spectator_abstract_stub_fallback(call : MethodCall, type : self)
Log.trace { "Fallback for #{call} - return self" }
self
end
@ -48,7 +53,8 @@ module Spectator
# Handle all methods but only respond to configured messages.
# Returns self.
macro method_missing(_call)
macro method_missing(call)
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 %}` - returning self" }
self
end
end