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

Add Mox.deny/3 #146

Merged
merged 3 commits into from
Nov 4, 2023
Merged

Add Mox.deny/3 #146

merged 3 commits into from
Nov 4, 2023

Conversation

rbino
Copy link
Contributor

@rbino rbino commented Nov 3, 2023

Allow denying a call to a mock with clearer intentions.
Closes #145.


reject(MockWeatherAPI, :get_temp, 1)
"""
@doc since: "1.2.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing next version number here (not sure if this or 1.1.1)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this per SemVer 👍

@whatyouhide
Copy link
Collaborator

I’m confused by a couple of things:

  • Why pass a function to reject, if the point is to make sure that it doesn't get called?
  • Instead of expect with 0, I always used stub(MyMock, :fun, fn ... -> flunk("Shouldn't have been called") end). Is reject really clearer than that?

@rbino
Copy link
Contributor Author

rbino commented Nov 4, 2023

  • Personally I use it for cases where the common setup uses stub_with but I want to verify that a specific function doesn't get called in a test
  • Using stub + flunk is better than expect (because at least it doesn't have the conflict between expecting and not expecting in the naming), but I think reject would be a little less boilerplate than having to manually specify flunk

@rbino rbino closed this Nov 4, 2023
@rbino rbino reopened this Nov 4, 2023
@rbino
Copy link
Contributor Author

rbino commented Nov 4, 2023

(accidentally closed from mobile finger slip)

@josevalim
Copy link
Member

Sorry, I had a change of mind and I think we should call it deny. :D I think it sounds stronger?

In any case, I am waiting on @whatyouhide's acceptance. :D

Allow denying a call to a mock with clearer intentions.
Closes dashbitco#145.
@rbino rbino changed the title Add reject/3 function Add deny/3 function Nov 4, 2023
@rbino
Copy link
Contributor Author

rbino commented Nov 4, 2023

Renamed to deny/3

@whatyouhide
Copy link
Collaborator

Personally I use it for cases where the common setup uses stub_with but I want to verify that a specific function doesn't get called in a test

Right, but this doesn't explain why we need to pass a function in, rather than the arity as an integer only. I see the function as more confusing than useful?

@rbino
Copy link
Contributor Author

rbino commented Nov 4, 2023

this doesn't explain why we need to pass a function in, rather than the arity as an integer only

Maybe I'm missing your point, deny/3 actually expects the arity instead of a function, so we don't need to pass a function in (that was one of the points of making this, because using other methods you have to come up with a fun even if you know that it will never get called)

@whatyouhide
Copy link
Collaborator

Man I gotta be honest I didn't even look at the code. I was discussing out of #145, which showed this code

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

🤦 Sorry!


reject(MockWeatherAPI, :get_temp, 1)
"""
@doc since: "1.2.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this per SemVer 👍

lib/mox.ex Show resolved Hide resolved
test/mox_test.exs Outdated Show resolved Hide resolved
test/mox_test.exs Outdated Show resolved Hide resolved
@whatyouhide whatyouhide changed the title Add deny/3 function Add Mox.deny/3 Nov 4, 2023
lib/mox.ex Outdated Show resolved Hide resolved
@josevalim josevalim merged commit 79cfb90 into dashbitco:master Nov 4, 2023
1 of 2 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

rbino added a commit to rbino/hammox that referenced this pull request Nov 6, 2023
Mirror new function in Mox (see dashbitco/mox#146).
Bump minimimum Mox version to ~> 1.2 since the function is included from the
1.2.0 release onwards.
@rbino rbino mentioned this pull request Nov 6, 2023
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 this pull request may close these issues.

[proposal] Add a specialized function to refute a call
3 participants