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
Source

Summary

get(name)

Gets the dependency with name

override(pid, name, module)

Override all calls to name in pid with module

put(name, module)

Assign module to the key name

remove_override(pid, name)

Remove override from process

replace(pid, name, expression)

Replace the given name for pid with the given expression. This will generate a new module with the given methods

start(initial_modules \\ %{})
stop()

Stop Pact

Functions

get(name)

Gets the dependency with name

Source
override(pid, name, module)

Override all calls to name in pid with module

Source
put(name, module)

Assign module to the key name

Source
remove_override(pid, name)

Remove override from process

Source
start(initial_modules \\ %{})
Source
stop()

Stop Pact

Source

Macros

replace(pid, name, expression)

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].

Source