View Source Nuntiux (Nuntiux v1.0.0)
This is Nuntiux.
Summary
Types
A timestamped message.
An expectation handler: a function that matches on a message and potentially does something with it.
The identifier of an expectation.
If the expectation is not named, this is "an almost unique reference", as per Kernel.make_ref/0
The name of an expectation.
A map of expectation identifiers to their expectation handlers.
A list of event()
.
Options to pass to the mocker process
The name of a process.
Functions
Removes a mocking process or expect function. If the expect function was not already there, this function still returns 'ok'.
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 the expect function is named, and there was already an expect function with that name, it's replaced. If the expect function is named, when it is successfully added or replaced, it'll keep the name as its identifier. Otherwise, a reference is returned as an identifier.
The same as expect/3
but raises a Nuntiux.Exception
in case of error.
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.
The same as new/2
but raises a Nuntiux.Exception
in case of error.
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.
Starts the application.
Stops the application.
Types
@type event() :: Nuntiux.Mocker.event()
A timestamped message.
@type expect_fun() :: Nuntiux.Mocker.expect_fun()
An expectation handler: a function that matches on a message and potentially does something with it.
@type expect_id() :: Nuntiux.Mocker.expect_id()
The identifier of an expectation.
If the expectation is not named, this is "an almost unique reference", as per Kernel.make_ref/0
@type expect_name() :: Nuntiux.Mocker.expect_name()
The name of an expectation.
@type expects() :: Nuntiux.Mocker.expects()
A map of expectation identifiers to their expectation handlers.
@type history() :: Nuntiux.Mocker.history()
A list of event()
.
@type opts() :: Nuntiux.Mocker.opts()
Options to pass to the mocker process:
:passthrough?
: indicates if messages received by the mock process are passed through to the mocked process (defaults totrue
):history?
: indicates if the mock is to keep a history of messages it receives (defaults totrue
)
@type process_name() :: atom()
The name of a process.
Functions
@spec delete(process_name, expect_id) :: ok | error when process_name: process_name(), expect_id: nil | expect_id(), ok: :ok, error: {:error, :not_mocked}
Removes a mocking process or expect function. If the expect function was not already there, this function still returns 'ok'.
@spec expect(process_name, expect_name, expect_fun) :: expect_id | error when process_name: process_name(), expect_name: nil | expect_name(), expect_fun: expect_fun(), expect_id: expect_id(), error: {: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 the expect function is named, and there was already an expect function with that name, it's replaced. If the expect function is named, when it is successfully added or replaced, it'll keep the name as its identifier. Otherwise, a reference is returned as an identifier.
@spec expect!(process_name, expect_name, expect_fun) :: process_name when process_name: process_name(), expect_name: nil | expect_name(), expect_fun: expect_fun()
The same as expect/3
but raises a Nuntiux.Exception
in case of error.
@spec expects(process_name) :: expects | error when process_name: process_name(), expects: expects(), error: {:error, :not_mocked}
Returns the list of expect functions for a process.
@spec history(process_name) :: history | error when process_name: process_name(), history: history(), error: {:error, :not_mocked}
Returns the history of messages received by a mocked process.
@spec mocked() :: process_names when process_names: [process_name()]
Returns the list of mocked processes.
@spec mocked_process() :: pid when pid: pid()
Returns the PID of the currently mocked process. Note: this code should only be used inside an expect fun.
@spec mocked_process(process_name) :: ok | error when process_name: process_name(), ok: pid(), error: {:error, :not_mocked}
Returns the PID of a mocked process (the original one with that name).
@spec new(process_name, opts) :: ok | error when process_name: process_name(), opts: opts(), ok: :ok, error: {:error, :not_found}
Injects a new mock process in front of the process with the provided name.
@spec new!(process_name, opts) :: process_name when process_name: process_name(), opts: opts()
The same as new/2
but raises a Nuntiux.Exception
in case of error.
@spec passthrough() :: ok when ok: :ok
Passes the current message down to the mocked process. Note: this code should only be used inside an expect fun.
@spec passthrough(message) :: ok when message: term(), ok: :ok
Passes a message down to the mocked process. Note: this code should only be used inside an expect fun.
@spec received?(process_name, message) :: received? | error when process_name: process_name(), message: term(), received?: boolean(), error: {:error, :not_mocked}
Returns whether a particular message was received already.
Note: it only works with history?: true
.
@spec reset_history(process_name) :: ok | error when process_name: process_name(), ok: :ok, error: {:error, :not_mocked}
Erases the history for a mocked process.
@spec start() :: ok when ok: {:ok, [module()]}
Starts the application.
@spec stop() :: ok when ok: :ok
Stops the application.