Hi all
I am using http poison for request some stuff from my SAP server. My question is, how to create a mock for the request?
Thanks
Hi all
I am using http poison for request some stuff from my SAP server. My question is, how to create a mock for the request?
Thanks
I’ve done this two ways.
You can either use something like https://github.com/jjh42/mock and wrap the test in a with_mock HTTPoison, [request: &MockHTTPoison.mock_request/5] and implement a mock function. This excels at timeout testing.
or
use something like https://github.com/PSPDFKit-labs/bypass which spins up a quick plug server that will return the actual response u want. Its nice because you can put assertions inside the bypass server. This is very hard to do timeout tests but probably excels at everything else.
the bypass is a better choice?
As @ctrlshiftbryan indicated, for most testing bypass
will be great… But if you want to test anything that involves a request timeout, then probably better to mock that test than having bypass
block until the timeout happens (which, with default settings, would make it a really slow test).
You could probably provide different timeout settings to the HTTPoison call if you’re in control of the parameters passed, of course, as a possible alternative to mocking.