Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When assert_called we can see what was expected and what was captured #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ defmodule Mock do
defmacro assert_called({{:., _, [module, f]}, _, args}) do
quote do
unquoted_module = unquote(module)
value = :meck.called(unquoted_module, unquote(f), unquote(args))
unquoted_f = unquote(f)
unquote_args = unquote(args)
value = :meck.called(unquoted_module, unquoted_f, unquote_args)

unless value do
calls = unquoted_module
Expand All @@ -185,7 +187,11 @@ defmodule Mock do
|> Enum.join("\n")

raise ExUnit.AssertionError,
message: "Expected call but did not receive it. Calls which were received:\n\n#{calls}"
message: """
Expected call but did not receive it. Calls which were captured:\n\n#{calls}.
\n
Expected call: #{unquoted_module}.#{unquoted_f}(#{unquote_args |> Enum.map(&Kernel.inspect/1) |> Enum.join(",")})
"""
end
end
end
Expand Down