Moxinet (moxinet v0.2.0)
Moxinet
helps you mock the internet at the HTTP layer
without sacrificing parallel testing.
Summary
Functions
Returns the header needed to be included in requests to the mock servers in order to support parallel runs.
Mocks a call for the passed module when used from a certain pid, defaulting self()
Turns a pid into a reference which could be used for indexing the signatures.
The start functions which will start the Moxinet
server.
Types
decoded_json_request_body()
header()
http_method()
@type http_method() :: :get | :post | :patch | :put | :delete | :options
mock_function()
@type mock_function() :: (request_body() | decoded_json_request_body() -> Moxinet.Response.t()) | (request_body() | decoded_json_request_body(), [header()] -> Moxinet.Response.t())
request_body()
@type request_body() :: String.t()
Functions
build_mock_header(pid \\ self())
Returns the header needed to be included in requests to the mock servers in order to support parallel runs.
expect(module, http_method, path, callback, from_pid \\ self())
@spec expect(module(), http_method(), binary(), mock_function(), pid()) :: :ok
Mocks a call for the passed module when used from a certain pid, defaulting self()
pid_reference(pid)
Turns a pid into a reference which could be used for indexing the signatures.
start(opts)
The start functions which will start the Moxinet
server.
You'd most likely want to put run this function from
your test_helper.exs
:
{:ok, _pid} = Moxinet.start(router: MyMockServer, port: 4010)
Options
router
: A reference to your mock server. Requiredport
: The port your mock server will run on. Requiredname
: Name of the moxinet supervisor. Defaults toMoxinet