Fix call expansion in debug log

Macro expansion somehow generated an error when calling a missing method with a block.

```
syntax error in :1
Error: unknown token: 'n'
```

It seems like 'n' is from the '\n' that was previously generated:

```
Log.debug { "Got undefined method " + "baz do\n  yield\nend" }
```
This commit is contained in:
Michael Miller 2022-03-19 16:32:25 -06:00
parent 17e97cb39a
commit 2f1999b377
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF

View file

@ -124,8 +124,8 @@ 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.stringify}} }
args = ::Spectator::Arguments.capture({{call.args.splat(", ")}}{% if call.named_args %}{{call.named_args.splat}}{% end %})
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 %}`" }
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.name}} with #{args}")
nil # Necessary for compiler to infer return type as nil. Avoids runtime "can't execute ... `x` has no type errors".