DEV Community

Piotr Romańczuk
Piotr Romańczuk

Posted on

4 2

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay