From d9306652b3dc714d9843c4bffdea12eaf00ebdc4 Mon Sep 17 00:00:00 2001 From: Tymon Tobolski Date: Mon, 26 Jul 2021 17:45:38 +0200 Subject: [PATCH] Change return type of mock/1 & global_mock/1 --- lib/tesla/mock.ex | 25 +++++++++++++++++-------- mix.exs | 3 ++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/tesla/mock.ex b/lib/tesla/mock.ex index 58a36d6a..5aea1371 100644 --- a/lib/tesla/mock.ex +++ b/lib/tesla/mock.ex @@ -135,8 +135,11 @@ defmodule Tesla.Mock do This mock will only be available to the current process. """ - @spec mock((Tesla.Env.t() -> Tesla.Env.t() | {integer, map, any})) :: no_return - def mock(fun) when is_function(fun), do: pdict_set(fun) + @spec mock((Tesla.Env.t() -> Tesla.Env.t() | {integer, map, any})) :: :ok + def mock(fun) when is_function(fun) do + pdict_set(fun) + :ok + end @doc """ Setup global mocks. @@ -144,8 +147,11 @@ defmodule Tesla.Mock do **WARNING**: This mock will be available to ALL processes. It might cause conflicts when running tests in parallel! """ - @spec mock_global((Tesla.Env.t() -> Tesla.Env.t() | {integer, map, any})) :: no_return - def mock_global(fun) when is_function(fun), do: agent_set(fun) + @spec mock_global((Tesla.Env.t() -> Tesla.Env.t() | {integer, map, any})) :: :ok + def mock_global(fun) when is_function(fun) do + agent_set(fun) + :ok + end ## HELPERS @@ -225,10 +231,13 @@ defmodule Tesla.Mock do defp agent_set(fun) do case Process.whereis(__MODULE__) do nil -> - ExUnit.Callbacks.start_supervised!(%{ - id: __MODULE__, - start: {Agent, :start_link, [fn -> fun end, [{:name, __MODULE__}]]} - }) + ExUnit.Callbacks.start_supervised!( + %{ + id: __MODULE__, + start: {Agent, :start_link, [fn -> fun end, [{:name, __MODULE__}]]} + }, + [] + ) pid -> Agent.update(pid, fn _ -> fun end) diff --git a/mix.exs b/mix.exs index ca2987b4..ce64013b 100644 --- a/mix.exs +++ b/mix.exs @@ -16,7 +16,8 @@ defmodule Tesla.Mixfile do lockfile: lockfile(System.get_env("LOCKFILE")), test_coverage: [tool: ExCoveralls], dialyzer: [ - plt_add_apps: [:inets, :idna, :ssl_verify_fun], + plt_core_path: "_build/#{Mix.env()}", + plt_add_apps: [:mix, :inets, :idna, :ssl_verify_fun, :ex_unit], plt_add_deps: :project ], docs: docs()