Skip to content

Commit 6ce7086

Browse files
superhawk610Olshansk
authored andcommitted
docs: add missing with_mock block (#113)
1 parent ae887cf commit 6ce7086

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -346,27 +346,29 @@ defmodule MyTest do
346346
import Mock
347347

348348
test "test_name" do
349-
Network.V2.update(%User{id: 456, name: "Jane Doe"}, %{name: "John Doe"})
350-
Network.V2.update(123, %{name: "John Doe", email: "john.doe@gmail.com"})
351-
Network.V2.update(nil, %{})
352-
353-
# assert that `update` was called with user id 456
354-
assert_called Network.V2.update(
355-
:meck.is(fn
356-
%User{id: 456} -> true
357-
_ -> false
358-
end),
359-
:_
360-
)
361-
362-
# assert that `update` was called with an email change
363-
assert_called Network.V2.update(
364-
:_,
365-
:meck.is(fn
366-
%{email: "john.doe@gmail.com"} -> true
367-
_ -> false
368-
end)
369-
)
349+
with_mock Network.V2, [update: fn(_user, _changes) -> :ok end] do
350+
Network.V2.update(%User{id: 456, name: "Jane Doe"}, %{name: "John Doe"})
351+
Network.V2.update(123, %{name: "John Doe", email: "john.doe@gmail.com"})
352+
Network.V2.update(nil, %{})
353+
354+
# assert that `update` was called with user id 456
355+
assert_called Network.V2.update(
356+
:meck.is(fn
357+
%User{id: 456} -> true
358+
_ -> false
359+
end),
360+
:_
361+
)
362+
363+
# assert that `update` was called with an email change
364+
assert_called Network.V2.update(
365+
:_,
366+
:meck.is(fn
367+
%{email: "john.doe@gmail.com"} -> true
368+
_ -> false
369+
end)
370+
)
371+
end
370372
end
371373
end
372374
````

0 commit comments

Comments
 (0)