---
title: "Reliving Your Happiest HTTP Interactions with Ruby’s VCR Gem"
description: "Ruby’s VCR library records HTTP interactions and replays them in test suites, verifying requests and returning predictable responses; the post presents it as a way to manage complex WebMock stubs and multi-step or unreliable API behavior. It contrasts recordings from a live API with manually authored stubs: cassettes preserve observed behavior at recording time but are harder to change and do not update when the API changes. The guidance covers VCR.use_cassette, configurable request matching, YAML cassettes, before_filter logging, filter_sensitive_data, and safer recording modes such as :once and :none instead of :new_episodes. It recommends VCR for integration-focused tests involving unpredictable sequences, multiple calls, or troublesome APIs, while favoring WebMock or decomposition for simple calls and specific states; cassette isolation and inspection add debugging value but can hide interactions."
---

# Reliving Your Happiest HTTP Interactions with Ruby’s VCR Gem

[Shopify](https://yomu.fyi/company/shopify) · 2023-10-18 · Jan 5, 2023

**Type:** Tutorial

## Summary

Ruby’s VCR library records HTTP interactions and replays them in test suites, verifying requests and returning predictable responses; the post presents it as a way to manage complex WebMock stubs and multi-step or unreliable API behavior. It contrasts recordings from a live API with manually authored stubs: cassettes preserve observed behavior at recording time but are harder to change and do not update when the API changes. The guidance covers VCR.use\_cassette, configurable request matching, YAML cassettes, before\_filter logging, filter\_sensitive\_data, and safer recording modes such as :once and :none instead of :new\_episodes. It recommends VCR for integration-focused tests involving unpredictable sequences, multiple calls, or troublesome APIs, while favoring WebMock or decomposition for simple calls and specific states; cassette isolation and inspection add debugging value but can hide interactions.

## Context

The post addresses difficulty maintaining complex WebMock stubs, debugging or testing complicated sequences of remote API operations, and working with APIs that are slow, unreliable, difficult to understand, or produce non-deterministic interactions. It also notes that VCR requires access to a running copy of the collaborator API and can be excessive for simple, well-understood calls.

## Approach / What changed

Use VCR to record live HTTP interactions into YAML cassettes and replay them through VCR.use\_cassette, with configurable request matching. The post recommends :once or :none instead of :new\_episodes in many cases, before\_filter for request logging, filter\_sensitive\_data for credentials and dynamic values, and separate cassettes for troublesome collaborators. It also suggests combining VCR integration tests with WebMock or unit tests for specific behaviors.

## Takeaways

- VCR recordings reflect the collaborator API at the time they are created, making them more accurate than manually authored stubs but harder to change; recordings do not automatically change when the API changes.
- The post recommends avoiding :new\_episodes unless silently recording unmatched requests is intentional; :once records only on first playback, while :none rejects new HTTP requests.
- before\_filter can log outgoing requests independently of cassette capture, while filter\_sensitive\_data replaces credentials and environment-specific or dynamic values with runtime placeholders.

**Tags:** [Authentication](https://yomu.fyi/topic/authentication), [Privacy](https://yomu.fyi/topic/privacy), [REST APIs](https://yomu.fyi/topic/rest-api), [Testing](https://yomu.fyi/topic/testing)

- Source: [Shopify](https://shopify.engineering/how-to-program-your-vcr)
- Source URL: https://shopify.engineering/how-to-program-your-vcr
- Ingested by Yomu: 2026-08-30T13:36:26.828Z

[Read original post](https://shopify.engineering/how-to-program-your-vcr)
