Calque (calque v1.3.1)

View Source

Calque — a lightweight snapshot testing and review tool for Elixir projects.

Calque allows you to:

  • Record test outputs as snapshot files (*.snap)
  • Compare new outputs against previously accepted snapshots
  • Review and accept/reject snapshots interactively from the CLI

Typical usage

Calque.check(result, "my test title")

If no accepted snapshot exists, Calque will create one and fail the test, prompting you to review it with:

mix calque review

Calque stores all snapshots under calque_snapshots/ in your project root.

CLI commands

  • mix calque review — review new or changed snapshots interactively
  • mix calque accept-all — accept all pending snapshots
  • mix calque reject-all — reject all pending snapshots
  • mix calque help — show CLI usage information

Summary

Functions

Performs a snapshot test using the calling function name as the snapshot title.

Performs a snapshot test with the given title, saving the content to a new snapshot file and comparing it to the accepted one.

Types

cli_command()

@type cli_command() :: :review | :accept_all | :reject_all | :help

snapshot()

@type snapshot() :: Calque.Snapshot.t()

Functions

check(content)

(macro)

Performs a snapshot test using the calling function name as the snapshot title.

This macro is a convenience shorthand for check/2, where the required title parameter is automatically derived from the function in which the macro is called (e.g., the test block name in ExUnit).

It behaves exactly like check/2, comparing the given content to the accepted snapshot and raising an error if a new or differing snapshot is found.

Parameters

  • content — The stringified output to snapshot.

Returns

  • :ok — If the output matches the accepted snapshot.
  • Raises an error (no_return()) — If a new snapshot is created or the content differs from the accepted snapshot.

check(content, title)

@spec check(String.t(), String.t()) :: :ok | no_return()
@spec check(term(), String.t()) :: :ok | no_return()

Performs a snapshot test with the given title, saving the content to a new snapshot file and comparing it to the accepted one.

The check/1 macro is usually preferred for convenience, as it automatically infers the snapshot title from the calling function.

Parameters

  • content — The stringified output to snapshot.
  • title — A unique identifier (string) for the snapshot. This is often the test name.

Returns

  • :ok — If the output matches the accepted snapshot.
  • Raises an error (no_return()) — If a new snapshot is created or the content differs from the accepted snapshot.