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
§Assertions
impl Assert
§Assertions
pub fn new() -> Assert
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.exeon 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<(), Error>
pub fn normalize(&self, actual: Data, expected: Data) -> (Data, Data)
Source§impl Assert
§Customize Behavior
impl Assert
§Customize Behavior
Sourcepub fn action_env(self, var_name: &str) -> Assert
pub fn action_env(self, var_name: &str) -> Assert
Read the failure action from an environment variable
Sourcepub fn redact_with(self, substitutions: Redactions) -> Assert
pub fn redact_with(self, substitutions: Redactions) -> Assert
Override the default Redactions
Sourcepub fn substitutions(self, substitutions: Redactions) -> Assert
👎Deprecated since 0.6.2: Replaced with Assert::redact_with
pub fn substitutions(self, substitutions: Redactions) -> Assert
Replaced with Assert::redact_with
Override the default Redactions
Sourcepub fn normalize_paths(self, yes: bool) -> Assert
pub fn normalize_paths(self, yes: bool) -> Assert
Specify whether text should have path separators normalized
The default is normalized
Source§impl Assert
impl Assert
pub fn selected_action(&self) -> Action
pub fn redactions(&self) -> &Redactions
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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more