dashbitco / mox

Mocks and explicit contracts in Elixir
1.35k stars 77 forks source link

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

Closed rbino closed 1 year ago

rbino commented 1 year ago

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.

josevalim commented 1 year ago

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