pub struct Assert { /* private fields */ }
Expand description

Snapshot assertion against a file’s contents

Useful for one-off assertions with the snapshot stored in a file

Examples

let actual = "...";
snapbox::Assert::new()
    .action_env("SNAPSHOTS")
    .matches_path(actual, "tests/fixtures/help_output_is_clean.txt");

Implementations

Check if a value is the same as an expected value

When the content is text, newlines are normalized.

let output = "something";
let expected = "something";
snapbox::Assert::new().eq(expected, output);

Check if a value matches a pattern

Pattern syntax:

  • ... is a line-wildcard when on a line by itself
  • [..] is a character-wildcard when inside a line
  • [EXE] matches .exe on Windows

Normalization:

  • Newlines
  • \ to /
let output = "something";
let expected = "so[..]g";
snapbox::Assert::new().matches(expected, output);

Check if a value matches the content of a file

When the content is text, newlines are normalized.

let output = "something";
let expected_path = "tests/snapshots/output.txt";
snapbox::Assert::new().eq_path(output, expected_path);

Check if a value matches the pattern in a file

Pattern syntax:

  • ... is a line-wildcard when on a line by itself
  • [..] is a character-wildcard when inside a line
  • [EXE] matches .exe on Windows (override with Assert::substitutions)

Normalization:

  • Newlines
  • \ to /
let output = "something";
let expected_path = "tests/snapshots/output.txt";
snapbox::Assert::new().matches_path(expected_path, output);
Available on crate feature path only.
Available on crate feature path only.

Override the color palette

Read the failure action from an environment variable

Override the failure action

Override the default Substitutions

Specify whether the content should be treated as binary or not

The default is to auto-detect

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.