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§
source§impl Assert
impl Assert
pub fn new() -> Self
sourcepub fn eq(&self, expected: impl Into<Data>, actual: impl Into<Data>)
pub fn eq(&self, expected: impl Into<Data>, actual: impl Into<Data>)
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);
sourcepub fn matches(&self, pattern: impl Into<Data>, actual: impl Into<Data>)
pub fn matches(&self, pattern: impl Into<Data>, actual: impl Into<Data>)
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);
sourcepub fn eq_path(&self, expected_path: impl AsRef<Path>, actual: impl Into<Data>)
pub fn eq_path(&self, expected_path: impl AsRef<Path>, actual: impl Into<Data>)
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);
sourcepub fn matches_path(
&self,
pattern_path: impl AsRef<Path>,
actual: impl Into<Data>
)
pub fn matches_path(
&self,
pattern_path: impl AsRef<Path>,
actual: impl Into<Data>
)
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 withAssert::substitutions
)
Normalization:
- Newlines
\
to/
let output = "something";
let expected_path = "tests/snapshots/output.txt";
snapbox::Assert::new().matches_path(expected_path, output);
source§impl Assert
impl Assert
sourcepub fn action_env(self, var_name: &str) -> Self
pub fn action_env(self, var_name: &str) -> Self
Read the failure action from an environment variable
sourcepub fn substitutions(self, substitutions: Substitutions) -> Self
pub fn substitutions(self, substitutions: Substitutions) -> Self
Override the default Substitutions
sourcepub fn normalize_paths(self, yes: bool) -> Self
pub fn normalize_paths(self, yes: bool) -> Self
Specify whether text should have path separators normalized
The default is normalized