Skip to content

Commit

Permalink
Creating an allowance in global mode is now ignored (#48)
Browse files Browse the repository at this point in the history
This can be useful if you create a shim to assist in testing. Now you can use
your shim all of the time without having to know if Mox is in global mode or not.

Fixes #46
  • Loading branch information
axelson authored and josevalim committed Oct 9, 2018
1 parent e47615c commit d1b102e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 2 additions & 5 deletions lib/mox.ex
Expand Up @@ -464,11 +464,8 @@ defmodule Mox do
"""

{:error, :in_global_mode} ->
raise ArgumentError, """
cannot allow #{inspect(allowed_pid)} to use #{inspect(mock)} from #{inspect(owner_pid)} \
because Mox is in global mode, the process already has access to all \
defined expectations/stubs
"""
# Already allowed
mock
end
end

Expand Down
8 changes: 3 additions & 5 deletions test/mox_test.exs
Expand Up @@ -715,15 +715,13 @@ defmodule MoxTest do
end
end

test "raises if you try to allow process while in global mode" do
test "is ignored if you allow process while in global mode" do
set_mox_global()
{:ok, child_pid} = Task.start_link(fn -> Process.sleep(:infinity) end)

Task.async(fn ->
assert_raise ArgumentError, ~r"already has access to all defined expectations", fn ->
CalcMock
|> allow(self(), child_pid)
end
mock = CalcMock
assert allow(mock, self(), child_pid) == mock
end)
|> Task.await()
end
Expand Down

0 comments on commit d1b102e

Please sign in to comment.