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().eq(actual, file!["output.txt"]);
Implementations§
source§impl Assert
impl Assert
§Assertions
pub fn new() -> Self
sourcepub fn eq(&self, actual: impl IntoData, expected: impl IntoData)
pub fn eq(&self, actual: impl IntoData, expected: impl IntoData)
Check if a value is the same as an expected value
By default filters
are applied, including:
...
is a line-wildcard when on a line by itself[..]
is a character-wildcard when inside a line[EXE]
matches.exe
on Windows"{...}"
is a JSON value wildcard"...": "{...}"
is a JSON key-value wildcard\
to/
- Newlines
To limit this to newline normalization for text, call Data::raw
on expected
.
§Examples
let actual = "something";
let expected = "so[..]g";
Assert::new().eq(actual, expected);
Can combine this with file!
let actual = "something";
Assert::new().eq(actual, file!["output.txt"]);
pub fn eq_(&self, actual: impl IntoData, expected: impl IntoData)
👎Deprecated since 0.6.0: Replaced with
Assert::eq
pub fn try_eq( &self, actual_name: Option<&dyn Display>, actual: Data, expected: Data ) -> Result<()>
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 redact_with(self, substitutions: Redactions) -> Self
pub fn redact_with(self, substitutions: Redactions) -> Self
Override the default Redactions
sourcepub fn substitutions(self, substitutions: Redactions) -> Self
👎Deprecated since 0.6.2: Replaced with Assert::redact_with
pub fn substitutions(self, substitutions: Redactions) -> Self
Assert::redact_with
Override the default Redactions
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