Struct snapbox::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().matches(file!["output.txt"], actual);

Implementations§

source§

impl Assert

§Assertions

source

pub fn new() -> Self

source

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

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

§Directory Assertions

source

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

Available on crate feature path only.
source

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

Available on crate feature path 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 substitutions(self, substitutions: Substitutions) -> Self

Override the default Substitutions

source

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

Specify whether text should have path separators normalized

The default is normalized

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<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.