Pact
A module for managing dependencies in your application. You can set, get, and override dependencies globally or per-pid.
Example
Pact.start
Pact.put(:http, HTTPoison)
Pact.get(:http).get("https://google.com")
# You can also override per module
Pact.override(self, :http, FakeHTTP)
spawn(fn ->
Pact.get(:http).get("https://google.com") # Calls HTTPoison
end)
Pact.get(:http).get("https://google.com") # Calls FakeHTTP
Summary↑
get(name) | Gets the dependency with |
override(pid, name, module) | Override all calls to |
put(name, module) | Assign |
remove_override(pid, name) | Remove override from process |
replace(pid, name, expression) | Replace the given |
start(initial_modules \\ %{}) | |
stop() | Stop Pact |
Functions
Gets the dependency with name
Override all calls to name
in pid
with module
Assign module
to the key name
Remove override from process
Stop Pact
Macros
Replace the given name
for pid
with the given expression. This will
generate a new module with the given methods.
## Example
``` import Pact
Pact.put(:enum, Enum) Pact.replace self, :enum do
def map(_map, _fn) do
[1, 2, 3]
end
end ```
So now if you call Pact.get(:enum).map(%{}, fn -> end)
it will return
[1, 2, 3]
.