I've tried using a lambda in my custom response:
stub_request(
:post,
'http://blah.blah/token'
).to_return(
status: 200,
body: lambda { |a| '{"token":"' + SecureRandom.hex(20) + '","expires_in":"259200"}' }
)
Maybe this isn't the correct way to handle dynamic responses, but anyway, webmock seems to execute the lambda exactly once. The request is identical each time, so either:
- My asumption that using a lambda would allow me to generate dynamic content on a per-response basis was wrong.
- Because the repeated requests are identical, webmock just uses the last response it generated.