Sycophant.Tesla.RecorderMiddleware (sycophant v0.4.2)

Copy Markdown

Tesla middleware for recording and replaying HTTP exchanges in tests.

In replay mode (default), reads a fixture file and returns the stored response. In record mode, passes through to the real API, captures the exchange, and writes it to disk.

The middleware is a no-op when no recording tag is set in the process dictionary, so it is safe to always include in the test middleware stack.

Usage

Set the recording name via the process dictionary before making a request:

Sycophant.Tesla.RecorderMiddleware.set_recording("openai/gpt-4o/basic")

Options

  • :fixtures_path - directory where fixture files are stored. Defaults to "test/fixtures/recordings".
  • :record - when true, forces recording (same as RECORD=force). Defaults to checking the RECORD env var.

Environment

  • RECORD=true - records only missing fixtures, replays existing ones
  • RECORD=force - re-records all fixtures regardless of existence

Summary

Functions

Clears the recording name from the process dictionary.

Gets the current recording name from the process dictionary.

Sets the recording name in the process dictionary and resets the call counter.

Functions

clear_recording()

@spec clear_recording() :: term()

Clears the recording name from the process dictionary.

get_recording()

@spec get_recording() :: String.t() | nil

Gets the current recording name from the process dictionary.

set_recording(name)

@spec set_recording(String.t()) :: term()

Sets the recording name in the process dictionary and resets the call counter.