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 = "something";
Assert::new().matches(file!["output.txt"], actual);
Implementations§
source§impl Assert
impl Assert
§Assertions
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 actual = "something";
let expected = "something";
Assert::new().eq(expected, actual);
Can combine this with file!
let actual = "something";
Assert::new().eq(file!["output.txt"], actual);
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 actual = "something";
let expected = "so[..]g";
Assert::new().matches(expected, actual);
Can combine this with file!
let actual = "something";
Assert::new().matches(file!["output.txt"], actual);
source§impl Assert
impl Assert
§Customize Behavior
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
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Assert
impl RefUnwindSafe for Assert
impl Send for Assert
impl Sync for Assert
impl Unpin for Assert
impl UnwindSafe for Assert
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more