dashbitco / mox

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

Rewrite examples to show mocking an API #99

Closed nathanl closed 4 years ago

nathanl commented 4 years ago

When I first looked at the Mox documentation, I found this example confusing:

test "invokes add and mult" do
  MyApp.CalcMock
  |> expect(:add, fn x, y -> x + y end)
  |> expect(:mult, fn x, y -> x * y end)

  assert MyApp.CalcMock.add(2, 3) == 5
  assert MyApp.CalcMock.mult(2, 3) == 6
end

This demonstrates that Mox works, but it doesn't show using a mock to test other code. This PR changes the calculator examples to instead mock an API interface and test the code which calls it.

josevalim commented 4 years ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: