-
Notifications
You must be signed in to change notification settings - Fork 36
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
Expect function call while still calling original function #85
Comments
Hi @DReigada, Thanks for such a well detailed issue report. I think the use case is super valid. Would you mind if I spend some time thinking about this before I reply? I want to experiment with this macro a bit before committing to something but in principle I like the idea 👍 Hoping to get some time before the end of the year Thanks! |
@edgurgel take your time, the macro is working for us so this is not urgent at all. Looking forward to knowing your thoughts on this. Let me know if you need to discuss this further. |
@DReigada hey after playing with it I think it's a good addition to the WDYT? |
@edgurgel that sounds great! Should I open a PR? |
Yes, please! 🙏 |
@edgurgel I didn't know about the Default syntax SomeModule |> expect_and_call_original(:some_function, [%{type: "some_type"}, :_]) Mimic.DSL expect_and_call_original SomeModule.some_function(%{type: "some_type"}, :_) |
I was thinking initially on using the existing expect_and_call_original SomeModule.some_function(%{type: "some_type"}, _) But we could support both if we really want to. WDYT? |
We've recently started using Mimic (migrating from Mock) and there's one pattern that we frequently use: assert that a function call happened but not changing the original behaviour of the function (calling the original)
This is what we end up doing most of the times:
This can become quite verbose if the function has multiple arguments that or if we want to expect multiple function calls on the same module.
We've decided to implement a macro to simplify this to the following (implementation below):
Macro Implementation
The macro fits our use case and simplifies the test code a lot, but I feel that it's a bit too complex and has some caveats (pinning variables for pattern matching can become cumbersome).
I wonder if you have any suggestion of how to make this better, or if this is even a feature that would make sense to add to Mimic.
The text was updated successfully, but these errors were encountered: