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

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.

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)
Michael Leimstädtner Over 1 year ago