View Source Repatch.Application (Repatch v1.6.0)
Helper module for patching application env.
Usage
In your
test_helper.exs
add this lineRepatch.Application.setup()
Add this to your test file
use Repatch.ExUnit, isolate_env: :local # or :shared or :global
Or if just call
Repatch.Application.patch_application_env/1
andRepatch.Application.cleanup/1
manually in setup or tests.Done! Now you can just call regular
Application
functions and they will affect only local (or shared) application env, so changes are not affecting other processes
How it works
It just patches :application
module functions which work with application env and replaces
their implementation with a thing which calls repatch-driven application env.
Drawbacks
It may not work for code which calls to internal and unspecified Erlang application env
implementation like ac_tab
ets table or application_controller
directly.
It also ignores persistent
and timeout
options.
Summary
Types
See Repatch.patch_option/0
for more information.
Functions
Cleans up a temporary env set up by the process. Use it after the test ends or if you want to reset application env back to what it used to be before the patch_application_env call.
Patches functions related to application env so that env is isolated. Accepts a list of options like the regular process.
Sets up the state for patching application env
Types
@type patch_application_env_option() :: Repatch.patch_option()
See Repatch.patch_option/0
for more information.
Functions
@spec cleanup(pid()) :: :ok
Cleans up a temporary env set up by the process. Use it after the test ends or if you want to reset application env back to what it used to be before the patch_application_env call.
Example
iex> Application.get_env(:ex_unit, :any)
nil
iex> Repatch.Application.patch_application_env(force: true)
iex> Application.put_env(:ex_unit, :any, :thing)
iex> Application.get_env(:ex_unit, :any)
:thing
iex> Repatch.Application.cleanup()
iex> Application.get_env(:ex_unit, :any)
nil
@spec patch_application_env([patch_application_env_option()]) :: :ok
Patches functions related to application env so that env is isolated. Accepts a list of options like the regular process.
Example
iex> Application.get_env(:ex_unit, :any)
nil
iex> Repatch.Application.patch_application_env(force: true)
iex> Application.put_env(:ex_unit, :any, :thing)
iex> Application.get_env(:ex_unit, :any)
:thing
iex> Task.await(Task.async(fn -> Application.get_env(:ex_unit, :any) end))
nil
@spec setup() :: :ok
Sets up the state for patching application env
Example
in your test/test_helper.exs
file:
ExUnit.start()
Repatch.setup()
Repatch.Application.setup()