dashbitco / mox

Mocks and explicit contracts in Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Apply calls to functions with matching arguments and in the provided order

mpoeter opened this issue · comments

Issue #4 already asked whether something like this should be supported:

CalcMock
|> expect(:add, fn(1, 1) -> 2 end)
|> expect(:add, fn(2, 2) -> 4 end)
CalcMock.add(1, 1)
CalcMock.add(2, 2)

The issue provides a workaround for this via pattern matching on the arguments. This may work fine in some cases, but in my scenario I also have to consider the order of the calls. To stick with this simple example, I want to verify that the first call to add passes 1, 1 and the second one 2, 2.

In your case what you wrote will just work and the order will be enforced. 👍

Huh, you are right..! I swear I tried this yesterday several times, and I always received a match error that the arguments for the second call did not match the arguments of the first expectation. Now it mysteriously works. Not sure if I should be happy or concerned... 🤔