Struct Assert
pub struct Assert {
pub(crate) action: Action,
action_var: Option<String>,
normalize_paths: bool,
substitutions: Redactions,
pub(crate) palette: Palette,
}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"]);Fields§
§action: Action§action_var: Option<String>§normalize_paths: bool§substitutions: Redactions§palette: PaletteImplementations§
§impl Assert
§Assertions
impl Assert
§Assertions
pub fn new() -> Assert
pub 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)
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)
§impl Assert
§Customize Behavior
impl Assert
§Customize Behavior
pub 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
pub fn redact_with(self, substitutions: Redactions) -> Assert
pub fn redact_with(self, substitutions: Redactions) -> Assert
Override the default Redactions
pub 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
pub 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
§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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 176 bytes