View Source nuntius (nuntius v0.0.3)

The main interface for the system.

Link to this section Summary

Functions

Removes a mocking process.
Removes an expect function.
If the expect function was not already there, this function still returns 'ok'.
If the process is not mocked, an error is returned.
Adds a new expect function to a mocked process.
When a message is received by the process, this function will be run on it.
If the message doesn't match any clause, nothing will be done.
If the process is not mocked, an error is returned.
When the function is successfully added, a reference is returned as an identifier.
Adds a new named expect function to a mocked process.
When a message is received by the process, this function will be run on it.
If the message doesn't match any clause, nothing will be done.
If the process is not mocked, an error is returned.
If there was already an expect function with that name, it's replaced.
When the expect function is successfully added or replaced, it'll keep the name as its identifier.
Returns the list of expect functions for a process.
Returns the history of messages received by a mocked process.
Returns the list of mocked processes.
Returns the PID of the currently mocked process.
Note: this code should only be used inside an expect fun.
Returns the PID of a mocked process (the original one with that name).
Injects a new mock process in front of the process with the provided name.

Options:
  • passthrough: if true, all messages are passed through to the process by default. If false, messages that are not handled by any expectation are just dropped.
    • default: true
  • history: if true, the mocking process will keep the history of messages received.
    • default: true
Passes the current message down to the mocked process.
Note: this code should only be used inside an expect fun.
Passes a message down to the mocked process.
Note: this code should only be used inside an expect fun.
Returns whether a particular message was received already.
Note: it only works with history => true.
Erases the history for a mocked process.
Stops the application.

Link to this section Types

-type event() ::
    #{timestamp := integer(), message := term(), mocked := boolean(), passed_through := boolean()}.
-type expect_fun() :: fun((_) -> _).
-type expect_id() :: reference() | expect_name().
-type expect_name() :: atom().
-type opts() :: #{passthrough => boolean(), history => boolean()}.
-type process_name() :: atom().

Link to this section Functions

-spec delete(process_name()) -> ok | {error, not_mocked}.
Removes a mocking process.
Link to this function

delete(ProcessName, ExpectId)

View Source
-spec delete(process_name(), expect_id()) -> ok | {error, not_mocked}.
Removes an expect function.
If the expect function was not already there, this function still returns 'ok'.
If the process is not mocked, an error is returned.
Link to this function

expect(ProcessName, Function)

View Source
-spec expect(process_name(), expect_fun()) -> reference() | {error, not_mocked}.
Adds a new expect function to a mocked process.
When a message is received by the process, this function will be run on it.
If the message doesn't match any clause, nothing will be done.
If the process is not mocked, an error is returned.
When the function is successfully added, a reference is returned as an identifier.
Link to this function

expect(ProcessName, ExpectName, Function)

View Source
-spec expect(process_name(), expect_name(), expect_fun()) -> expect_name() | {error, not_mocked}.
Adds a new named expect function to a mocked process.
When a message is received by the process, this function will be run on it.
If the message doesn't match any clause, nothing will be done.
If the process is not mocked, an error is returned.
If there was already an expect function with that name, it's replaced.
When the expect function is successfully added or replaced, it'll keep the name as its identifier.
-spec expects(process_name()) -> Expectations | {error, not_mocked}
           when Expectations :: #{expect_id() => expect_fun()}.
Returns the list of expect functions for a process.
-spec history(process_name()) -> [event()] | {error, not_mocked}.
Returns the history of messages received by a mocked process.
-spec mocked() -> [process_name()].
Returns the list of mocked processes.
-spec mocked_process() -> pid().
Returns the PID of the currently mocked process.
Note: this code should only be used inside an expect fun.
Link to this function

mocked_process(ProcessName)

View Source
-spec mocked_process(process_name()) -> pid() | {error, not_mocked}.
Returns the PID of a mocked process (the original one with that name).
-spec new(process_name()) -> ok | {error, not_found}.

Equivalent to new(ProcessName, #{}).

Injects a new mock process in front of the process with the provided name.
Returns an error if there is no process registered under that name.
-spec new(process_name(), opts()) -> ok | {error, not_found}.
Injects a new mock process in front of the process with the provided name.

Options:
  • passthrough: if true, all messages are passed through to the process by default. If false, messages that are not handled by any expectation are just dropped.
    • default: true
  • history: if true, the mocking process will keep the history of messages received.
    • default: true
-spec passthrough() -> ok.
Passes the current message down to the mocked process.
Note: this code should only be used inside an expect fun.
-spec passthrough(term()) -> ok.
Passes a message down to the mocked process.
Note: this code should only be used inside an expect fun.
Link to this function

received(ProcessName, Message)

View Source
-spec received(process_name(), term()) -> boolean() | {error, not_mocked}.
Returns whether a particular message was received already.
Note: it only works with history => true.
Link to this function

reset_history(ProcessName)

View Source
-spec reset_history(process_name()) -> ok | {error, not_mocked}.
Erases the history for a mocked process.
-spec start() -> {ok, [module()]}.

Equivalent to application:ensure_all_started(nuntius).

Starts the application.
-spec stop() -> ok.
Stops the application.