Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocks on nameless splats #51

Closed
kaukas opened this issue Jan 26, 2023 · 2 comments
Closed

Mocks on nameless splats #51

kaukas opened this issue Jan 26, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@kaukas
Copy link

kaukas commented Jan 26, 2023

Hi! Thanks for your library! It makes me, an RSpec lover, feel more at home. :-)

After a while I tried to run my project specs (that used to work) and something is failing now. I don't really know what caused the failure; perhaps a newer Crystal version.

My tail of shards.lock:

  spectator:
    git: https://gitlab.com/arctic-fox/spectator.git
    version: 0.11.5
$ crystal --version
Crystal 1.7.2 (2023-01-23)

LLVM: 14.0.6
Default target: aarch64-apple-darwin22.1.0

$ git clone https://github.com/kaukas/crystal-cassandra
$ shards install
$ crystal spec spec/cassandra/dbapi_spec.cr --error-trace
There was a problem expanding macro 'default_stub'

Called macro defined in lib/spectator/src/spectator/mocks/stubbable.cr:108:13

 108 | private macro default_stub(method)

Which expanded to:

 >  1 |
 >  2 |
 >  3 |
 >  4 |
 >  5 |
 >  6 |        def should(
 >  7 |         expectation : BeAExpectation(T), failure_message : String | ::Nil = nil, *, file = __FILE__, line = __LINE__,
 >  8 |
 >  9 |
 > 10 |       ) : T forall T
 > 11 |         super(expectation, failure_message, file: file, line: line)
 > 12 |       end
 > 13 |
 > 14 |
 > 15 |
 > 16 |
 > 17 |        def should(
 > 18 |         expectation : BeAExpectation(T), failure_message : String | ::Nil = nil, *, file = __FILE__, line = __LINE__,
 > 19 |
 > 20 |
 > 21 |       ) : T forall T
 > 22 |
 > 23 |         # Capture information about the call.
 > 24 |         __temp_153 = ::Spectator::MethodCall.build(
 > 25 |           :should,
 > 26 |           ::NamedTuple.new(
 > 27 |             "expectation": expectation, "failure_message": failure_message,
 > 28 |           ),
 > 29 |           :"", ,
 > 30 |           ::NamedTuple.new(
 > 31 |             "file": file, "line": line,
 > 32 |           ).merge()
 > 33 |         )
 > 34 |         _spectator_record_call(__temp_153)
 > 35 |
 > 36 |         # Attempt to find a stub that satisfies the method call and arguments.
 > 37 |         # Finding a suitable stub is delegated to the type including the `Stubbable` module.
 > 38 |         if __temp_154 = _spectator_find_stub(__temp_153)
 > 39 |           # Cast the stub or return value to the expected type.
 > 40 |           # This is necessary to match the expected return type of the original method.
 > 41 |           _spectator_cast_stub_value(__temp_154, __temp_153, typeof(previous_def),
 > 42 |           :raise)
 > 43 |         else
 > 44 |           # Delegate missing stub behavior to concrete type.
 > 45 |           _spectator_stub_fallback(__temp_153, typeof(previous_def)) do
 > 46 |             # Use the default response for the method.
 > 47 |             previous_def
 > 48 |           end
 > 49 |         end
 > 50 |       end
 > 51 |
Error: unterminated call

From what I gather splat names are expected to either be non empty strings on nils. However, this particular should definition has an unnamed splat which ends up as an empty string when rendered in the macro (see :"", , on line 29).

Unfortunately, my quick attempt to reproduce it with a spec in spectator failed. Perhaps you'd have better luck?..

Thank you!

@icy-arctic-fox icy-arctic-fox self-assigned this Jan 26, 2023
@icy-arctic-fox icy-arctic-fox added the bug Something isn't working label Jan 26, 2023
@icy-arctic-fox
Copy link
Owner

Luckily this has been fixed on a branch and will be merged soon.

icy-arctic-fox added a commit that referenced this issue Jan 27, 2023
@kaukas
Copy link
Author

kaukas commented Jan 27, 2023

Thank you so much!

@kaukas kaukas closed this as completed Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants