DEV Community

loading...

When VCR seems to heavy try cURL & WebMock

Piotr Romańczuk
・1 min read

Do you want to mock exact response (body and headers) for some file download?

VCR is overkill for such small task. One can handcraft it and pass to WebMock's stub_request. I'd rather go with saving full real response.

There are fine istructions in WebMock README. I want to share it here for reference:

Replaying raw responses recorded with curl -is

In console:

curl -is www.example.com > /tmp/example_curl_-is_output.txt
Enter fullscreen mode Exit fullscreen mode

In your test:

raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
stub_request(:get, "www.example.com").to_return(raw_response_file)
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Forem Open with the Forem app