Read more

Heads up: network requests `Kernel#open` are not mocked with VCR

Michael Leimstädtner
December 13, 2022Software engineer at makandra GmbH

We usually rely on VCR Show archive.org snapshot and WebMock Show archive.org snapshot to prevent any real network connection when running our unit tests.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

This is not entirely true: They are both limited to a set of HTTP libraries listed below (as of 2022). Direct calls to Kernel#open or OpenURI#open_uri are not mocked and will trigger real network requests even in tests. This might bite you e.g. in older versions of CarrierWave Show archive.org snapshot with remote file URLs.

Supported libraries

VCR:

  • Patron (when using WebMock)
  • Curb (when using WebMock -- only supports Curl::Easy at the moment)
  • HTTPClient (when using WebMock)
  • em-http-request (when using WebMock)
  • Net::HTTP (when using WebMock)
  • Typhoeus (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
  • Excon
  • Faraday
  • Net::HTTP (inlcudes Mechanize, HTTParty, Rest Client, ..)

WebMock

  • Async::HTTP::Client
  • Curb (currently only Curb::Easy)
  • EM-HTTP-Request
  • Excon
  • HTTPClient
  • HTTP Gem (also known as http.rb)
  • httpx
  • Manticore
  • Net::HTTP and other libraries based on Net::HTTP, e.g.:
  • HTTParty
  • REST Client
  • Patron
  • Typhoeus (currently only Typhoeus::Hydra)
Posted by Michael Leimstädtner to makandra dev (2022-12-13 17:21)