I have a webhook simulator I created for my QA team. In order to prevent the webhooks arriving before the synchronous request completes, I forked the code block that sends the webhook to delay sending for 60s.
I was curious if it is possible to test the code in the forked process with RSpec.
# Code block
Process.detach(
fork do
sleep(60)
hook_resp = Faraday.post(url, webhook_body, 'Content-Type' => 'application/json')
logger.debug("Pushed to webhook listener, HTTP #{hook_resp.status} received")
end
)
# RSpec test
it 'should sent to receiver' do
expect(Faraday).to receive(:post)
.with('http://web.hook', anything, anything).and_return(double(status: 200))
subject.call_method(params)
end
Obviously, I am getting a failing test. Is this testable at all? I do not really care about the response from the webhook receiver, just a fire and forget.