Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion lib/mimic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,14 @@ defmodule Mimic do
```
"""
@spec set_mimic_global(map()) :: :ok
def set_mimic_global(_context \\ %{}), do: Server.set_global_mode(self())
def set_mimic_global(_context \\ %{})

def set_mimic_global(%{async: true}) do
raise "Mimic cannot be set to global mode when the ExUnit case is async. " <>
"If you want to use Mimic in global mode, remove \"async: true\" when using ExUnit.Case"
end

def set_mimic_global(_context), do: Server.set_global_mode(self())

@doc """
Chooses the mode based on ExUnit context. If `async` is `true` then
Expand Down
7 changes: 7 additions & 0 deletions test/mimic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,4 +1280,11 @@ defmodule Mimic.Test do
end
end
end

describe "set_mimic_global/1" do
test "raises if the test case is async" do
message = ~r/Mimic cannot be set to global mode when the ExUnit case is async/
assert_raise RuntimeError, message, fn -> set_mimic_global(%{async: true}) end
end
end
end
Loading