View Source nuntius (nuntius v0.0.3)
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.
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.
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.
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.
Note: this code should only be used inside an expect fun.
Returns the PID of a mocked process (the original one with that name).
Equivalent to new(ProcessName, #{}).
Injects a new mock process in front of the process with the provided name.
Options:
Options:
passthrough
: iftrue
, 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
- default:
history
: iftrue
, the mocking process will keep the history of messages received.- default:
true
- default:
Passes the current message down to the mocked process.
Note: this code should only be used inside an expect fun.
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.
Note: this code should only be used inside an expect fun.
Returns whether a particular message was received already.
Note: it only works with
Note: it only works with
history => true.
Erases the history for a mocked process.
Equivalent to application:ensure_all_started(nuntius).
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}.
-spec delete(process_name(), expect_id()) -> ok | {error, not_mocked}.
If the expect function was not already there, this function still returns 'ok'.
If the process is not mocked, an error is returned.
-spec expect(process_name(), expect_fun()) -> reference() | {error, not_mocked}.
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.
-spec expect(process_name(), expect_name(), expect_fun()) -> expect_name() | {error, not_mocked}.
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()}.
-spec history(process_name()) -> [event()] | {error, not_mocked}.
-spec mocked() -> [process_name()].
-spec mocked_process() -> pid().
Note: this code should only be used inside an expect fun.
-spec mocked_process(process_name()) -> pid() | {error, not_mocked}.
-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}.
Options:
passthrough
: iftrue
, 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
- default:
history
: iftrue
, the mocking process will keep the history of messages received.- default:
true
- default:
-spec passthrough() -> ok.
Note: this code should only be used inside an expect fun.
-spec passthrough(term()) -> ok.
Note: this code should only be used inside an expect fun.
-spec received(process_name(), term()) -> boolean() | {error, not_mocked}.
Note: it only works with
history => true.
-spec reset_history(process_name()) -> ok | {error, not_mocked}.
-spec start() -> {ok, [module()]}.
Equivalent to application:ensure_all_started(nuntius).
Starts the application.-spec stop() -> ok.