From e771489f1f56ee14de6096c41bf1f83efca02110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 3 Dec 2021 08:29:37 +0100 Subject: [PATCH] Fix docs, closes #122 --- lib/mox.ex | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/mox.ex b/lib/mox.ex index 906258b..6dd63f5 100644 --- a/lib/mox.ex +++ b/lib/mox.ex @@ -90,13 +90,20 @@ defmodule Mox do One last note, if the mock is used throughout the test suite, you might want the implementation to fall back to a stub (or actual) implementation when no - expectations are defined. You can use `stub_with/2` in your `test_helper.exs` - as follows: + expectations are defined. You can use `stub_with/2` in a case template that + is used throughout your test suite: - Mox.stub_with(MyApp.MockWeatherAPI, MyApp.StubWeatherAPI) + defmodule MyApp.Case do + use ExUnit.CaseTemplate - Now, if no expectations are defined it will call the implementation in - `MyApp.StubWeatherAPI`. + setup _ do + Mox.stub_with(MyApp.MockWeatherAPI, MyApp.StubWeatherAPI) + end + end + + Now, for every test case that uses `ExUnit.Case`, it can use `MyApp.Case` + instead. Then, if no expectations are defined it will call the implementation + in `MyApp.StubWeatherAPI`. ## Multiple behaviours