From ab4d5d985058cb82b5fcba5f4751576a07595452 Mon Sep 17 00:00:00 2001 From: Aaron Ross Date: Sun, 8 Dec 2019 22:14:12 -0500 Subject: [PATCH] docs: add missing `with_mock` block --- README.md | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 9351282..35ba029 100644 --- a/README.md +++ b/README.md @@ -346,27 +346,29 @@ defmodule MyTest do import Mock test "test_name" do - Network.V2.update(%User{id: 456, name: "Jane Doe"}, %{name: "John Doe"}) - Network.V2.update(123, %{name: "John Doe", email: "john.doe@gmail.com"}) - Network.V2.update(nil, %{}) - - # assert that `update` was called with user id 456 - assert_called Network.V2.update( - :meck.is(fn - %User{id: 456} -> true - _ -> false - end), - :_ - ) - - # assert that `update` was called with an email change - assert_called Network.V2.update( - :_, - :meck.is(fn - %{email: "john.doe@gmail.com"} -> true - _ -> false - end) - ) + with_mock Network.V2, [update: fn(_user, _changes) -> :ok end] do + Network.V2.update(%User{id: 456, name: "Jane Doe"}, %{name: "John Doe"}) + Network.V2.update(123, %{name: "John Doe", email: "john.doe@gmail.com"}) + Network.V2.update(nil, %{}) + + # assert that `update` was called with user id 456 + assert_called Network.V2.update( + :meck.is(fn + %User{id: 456} -> true + _ -> false + end), + :_ + ) + + # assert that `update` was called with an email change + assert_called Network.V2.update( + :_, + :meck.is(fn + %{email: "john.doe@gmail.com"} -> true + _ -> false + end) + ) + end end end ````