Struct snapbox::assert::Assert

source ·
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

source

pub fn new() -> Self

source

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"]);
source

pub fn eq_(&self, actual: impl IntoData, expected: impl IntoData)

👎Deprecated since 0.6.0: Replaced with Assert::eq
source

pub fn try_eq( &self, actual_name: Option<&dyn Display>, actual: Data, expected: Data ) -> Result<()>

source§

impl Assert

§Directory Assertions

source

pub fn subset_eq( &self, expected_root: impl Into<PathBuf>, actual_root: impl Into<PathBuf> )

Available on crate feature dir only.
source

pub fn subset_matches( &self, pattern_root: impl Into<PathBuf>, actual_root: impl Into<PathBuf> )

Available on crate feature dir only.
source§

impl Assert

§Customize Behavior

source

pub fn palette(self, palette: Palette) -> Self

Override the color palette

source

pub fn action_env(self, var_name: &str) -> Self

Read the failure action from an environment variable

source

pub fn action(self, action: Action) -> Self

Override the failure action

source

pub fn redact_with(self, substitutions: Redactions) -> Self

Override the default Redactions

source

pub fn substitutions(self, substitutions: Redactions) -> Self

👎Deprecated since 0.6.2: Replaced with Assert::redact_with

Override the default Redactions

source

pub fn normalize_paths(self, yes: bool) -> Self

Specify whether text should have path separators normalized

The default is normalized

source§

impl Assert

source

pub fn selected_action(&self) -> Action

Trait Implementations§

source§

impl Clone for Assert

source§

fn clone(&self) -> Assert

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Assert

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Assert

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<D> ToDebug for D
where D: Debug,

source§

fn to_debug(&self) -> Data

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.