Skip to content

Separate snapshot persistence from query logic in parser rendering tests #389

Description

@coderabbitai

Background

In PR #326, snapshot regression tests were added for localised CLI long-help output (src/cli/parser_tests.rs). The tests currently embed insta::assert_snapshot! directly inside the test body, which causes irreversible filesystem I/O (reading or writing snapshot files) as an indistinguishable side-effect of what should be a pure query operation.

Problem

insta's assert_snapshot! macro unconditionally performs filesystem mutations during test execution. There is no clear boundary between:

  • the query path – rendering, normalising, and asserting on the help text; and
  • the command path – persisting or verifying the snapshot on disk.

This violates the CQS principle and makes test intent harder to reason about.

Proposed resolution

Refactor the snapshot tests to separate concerns explicitly:

  1. Extract a pure helper function that returns the normalised rendered help string for a given locale.
  2. Assert on the returned string in unit-style tests (no I/O).
  3. Invoke assert_snapshot! only from a clearly labelled snapshot-acceptance layer, or use insta's explicit Settings API (Settings::bind, Settings::set_snapshot_path, etc.) in a dedicated snapshot-acceptance test function that is clearly named and documented as having filesystem side-effects.

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions