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
Problem with assert_receive in koans #93
Problem with assert_receive in koans #93
Conversation
This isn't failing due to an apparently problem with assert_receive in the koans. Not quite sure yet why that macro isn't working.
After a little more investigation, I'm leaning towards this being a bug in ExUnit. I'm going to take a little more time to verify I understand how |
Turns out the way assert_receive is implemented, the expression give the macro is used literally as the match for the expanded receive call.
Ok, here's what I know. The way ExUnit's assert_receive is implemented, the expression provided to the macro is used as a match for the receive statement expanded by the macro. So a variable used in the match would simply be overwritten unless it's pinned. That is exactly what's happening to the internal Add the pin works, adds a little more cognitive load to the test cases. How would we like to proceed? Is the pin not a big deal? Should we consider just writing the receive out instead of using assert receive? Are there any other options? |
It seems having assert_receive "leak" bindings into the calling code is an explicit feature of the macro. I still find it extremely surprising, but I suppose this is just a gotcha... elixir-lang/elixir@dbb6f35 |
Oh boy... this is hard. Explicitly pinning the blanks ( Writing the receive blocks out would work but again, it's longer and takes away the opportunity to teach users about I wonder if there's something we can do behind the scenes to make our tests work better with After all if we don't come up with a good alternative, I'm happy with making some changes on the user side but I'd like to avoid it if at all possible. Thank you for uncovering and investigating this issue by the way 👍 Had no idea this was even a problem. |
Great evaluation of the problem. I thought about trying to pin |
I just pushed a solution. TBH, I'm not thrilled with it. It seems hard to grok, BUT it does work. Let me know what you think :) |
I've got another idea. Instead of adding edge cases for Blanks, maybe we can just shim assert_receieve to add the pin for blanks. I'll give it a shot in a bit for comparison. |
Alright here's the alternative implementation: master...iamvery:assert-receive-alternative-fix Basically instead of having custom replacements for |
Amazing research! I remember having issues with I'll take a look tonight. |
I've had a brief look. |
I might have been overthinking it, but the reasoning was that there is nothing to replace when |
Also fwiw, I really don't like the name of |
I agree with everything that's been said here. I think the @iamvery @felipesere Any objections to hitting merge on this? |
I just really wish it was cleaner. I'm maybe not completely certain all edge cases are covered. |
However probably no reason to hold it up. No ideas coming to mind... |
I think the edge cases are not that big of a deal given that users never actually interact with this code. Any future problems that may crop up will affect us but users will be able to go through the koans just fine. That makes me a bit less concerned. As for cleanliness.. I kind of accept some of it because we opted for more complex test code in order to leave the user experience intact. It seems that we don't have any ideas on how to make it cleaner and until we do I'm okay using the code as it is. In the end we gain the ability to properly test koans with |
I sort of stumbled upon the fact that
assert_receive
isn't working as expected in the koans. It's proven by this typo. I'm not yet sure what the problem is, but I'm assuming it's something to do with the various metaprogramming that's happening amongst these macros... I'll keep working on it, but any input is welcome!