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
sourceimpl 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);
sourceimpl 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
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Assert
impl Send for Assert
impl Sync for Assert
impl Unpin for Assert
impl UnwindSafe for Assert
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more