DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Piotr RomaΕ„czuk
Piotr RomaΕ„czuk

Posted on

When VCR seems to heavy try cURL & WebMock

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

Top comments (0)

πŸ€” Did you know?

Β 
πŸŽ™ DEV hosts some podcasts that you can find on our Podcasts page.