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

[proposal] Add a specialized function to refute a call #145

Closed
rbino opened this issue Nov 3, 2023 · 1 comment · Fixed by #146
Closed

[proposal] Add a specialized function to refute a call #145

rbino opened this issue Nov 3, 2023 · 1 comment · Fixed by #146

Comments

@rbino
Copy link
Contributor

rbino commented Nov 3, 2023

Hey everyone!
I've been using Mox a lot and one thing that bothers me a little is that when I define an expectation that I expect to be called 0 times (i.e. I refute it), it's not very evident since the only "different" thing is the 0 passed as argument, which sometimes gets lost in the surrounding noise.

My proposal is the introduction of a refute (or some other name, naming things is hard etc etc) function which makes the intention more evident when reading the test. I would also allow to pass the arity as an integer instead of passing a lambda (possibly allowing both), since I find that having to define a fun for something I expect not to be called is what generates most of the noise.

So the interface would look something like that

# Passing a fun
refute(MockWeatherAPI, :get_temp, fn _ -> {:ok, 30} end)

# Passing the arity
refute(MockWeatherAPI, :get_temp, 1)

If this sounds interesting I'd be happy to take a stab at it.

@rbino rbino changed the title [proposal] A specialized function to _refute_ a call [proposal] A specialized function to refute a call Nov 3, 2023
@rbino rbino changed the title [proposal] A specialized function to refute a call [proposal] Add a specialized function to refute a call Nov 3, 2023
@josevalim
Copy link
Member

I think adding a reject or deny function with the arity would definitely be clearer in scope. A PR is welcome.

rbino added a commit to rbino/mox that referenced this issue Nov 3, 2023
Allow rejecting a call to a mock with clearer intentions.
Closes dashbitco#145.
@rbino rbino mentioned this issue Nov 3, 2023
rbino added a commit to rbino/mox that referenced this issue Nov 4, 2023
Allow denying a call to a mock with clearer intentions.
Closes dashbitco#145.
josevalim pushed a commit that referenced this issue Nov 4, 2023
Allow denying a call to a mock with clearer intentions.

Closes #145.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants