You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found quite handy sometimes to have the possibility to execute some code when the mock is called. One good use case is raising an exception when the mock is called.
In RhinoMocks there is something like this:
Yes, this is possible. As can be seen in the first example:
defmoduleMyTestdouseExUnit.Case,async: falseimportMocktest"test_name"dowith_mockHTTPotion,[get: fn(_url)->"<html></html>"end]doHTTPotion.get("http://example.com")# Tests that make the expected callassertcalledHTTPotion.get("http://example.com")endendend
The get function is replaced by another function entirely, in this case an anonymous function. You can either do whatever you want in there, e.g. [get: fn(url) -> my_code(url) end] or just reference another function you wrote that takes the same number of arguments, e.g. [get: &my_code/1].
I have found quite handy sometimes to have the possibility to execute some code when the mock is called. One good use case is raising an exception when the mock is called.
In RhinoMocks there is something like this:
Is that possible with mock?
Thanks by the way for the nice library
The text was updated successfully, but these errors were encountered: