Struct insta::Settings[][src]

pub struct Settings { /* fields omitted */ }

Configures how insta operates at test time.

Settings are always bound to a thread and some default settings are always available. These settings can be changed and influence how insta behaves on that thread. They can either temporarily or permanently changed.

This can be used to influence how the snapshot macros operate. For instance it can be useful to force ordering of maps when unordered structures are used through settings.

Some of the settings can be changed but shuoldn’t as it will make it harder for tools like cargo-insta or an editor integration to locate the snapshot files.

Settings can also be configured with the with_settings! macro.


use insta;

let mut settings = insta::Settings::clone_current();
settings.bind(|| {
    // runs the assertion with the changed settings enabled


impl Settings[src]

pub fn new() -> Settings[src]

Returns the default settings.

It’s recommended to use clone_current instead so that already applied modifications are not discarded.

pub fn clone_current() -> Settings[src]

Returns a copy of the current settings.

pub fn set_sort_maps(&mut self, value: bool)[src]

Enables forceful sorting of maps before serialization.

Note that this only applies to snapshots that undergo serialization (eg: does not work for assert_debug_snapshot!.)

The default value is false.

pub fn sort_maps(&self) -> bool[src]

Returns the current value for map sorting.

pub fn set_prepend_module_to_snapshot(&mut self, value: bool)[src]

Disables prepending of modules to the snapshot filename.

By default the filename of a snapshot is <module>__<name>.snap. Setting this flag to false changes the snapshot filename to just <name>.snap.

The default value is true.

pub fn prepend_module_to_snapshot(&self) -> bool[src]

Returns the current value for module name prepending.

pub fn set_allow_empty_glob(&mut self, value: bool)[src]

Allows the glob! macro to succeed if it matches no files.

By default the glob macro will fail the test if it does not find any files to prevent accidental typos. This can be disabled when fixtures should be conditional.

The default value is false.

pub fn allow_empty_glob(&self) -> bool[src]

Returns the current value for the empty glob setting.

pub fn set_snapshot_suffix<I: Into<String>>(&mut self, suffix: I)[src]

Sets the snapshot suffix.

The snapshot suffix is added to all snapshot names with an @ sign between. For instance if the snapshot suffix is set to "foo" and the snapshot would be named "snapshot" it turns into "snapshot@foo". This is useful to separate snapshots if you want to use test parameterization.

pub fn remove_snapshot_suffix(&mut self)[src]

Removes the snapshot suffix.

pub fn snapshot_suffix(&self) -> Option<&str>[src]

Returns the current snapshot suffix.

pub fn set_input_file<P: AsRef<Path>>(&mut self, p: P)[src]

Sets the input file reference.

This value is completely unused by the snapshot testing system but it lets you store some meta data with a snapshot that refers you back to the input file. The path stored here is made relative to the workspace root before storing with the snapshot.

pub fn remove_input_file(&mut self)[src]

Removes the input file reference.

pub fn input_file(&self) -> Option<&Path>[src]

Returns the current input file reference.

pub fn add_redaction<R: Into<Redaction>>(
    &mut self,
    selector: &str,
    replacement: R

Registers redactions that should be applied.

This can be useful if redactions must be shared across multiple snapshots.

Note that this only applies to snapshots that undergo serialization (eg: does not work for assert_debug_snapshot!.)

pub fn add_dynamic_redaction<I, F>(&mut self, selector: &str, func: F) where
    I: Into<Content>,
    F: Fn(Content, ContentPath<'_>) -> I + Send + Sync + 'static, 

Registers a replacement callback.

This works similar to a redaction but instead of changing the value it asserts the value at a certain place. This function is internally supposed to call things like assert_eq!.

This is a shortcut to add_redaction(dynamic_redaction(...));

pub fn set_redactions<R: Into<Redactions>>(&mut self, redactions: R)[src]

Replaces the currently set redactions.

The default set is empty.

pub fn clear_redactions(&mut self)[src]

Removes all redactions.

pub fn set_snapshot_path<P: AsRef<Path>>(&mut self, path: P)[src]

Sets the snapshot path.

If not absolute it’s relative to where the test is in.

Defaults to snapshots.

pub fn snapshot_path(&self) -> &Path[src]

Returns the snapshot path.

pub fn bind<F: FnOnce()>(&self, f: F)[src]

Runs a function with the current settings bound to the thread.

pub fn bind_async<F: Future<Output = T>, T>(
    future: F
) -> impl Future<Output = T>

Like bind but for futures.

This lets you bind settings for the duration of a future like this:

let settings = Settings::new();
settings.bind_async(async {
    // do assertions here

pub fn bind_to_thread(&self)[src]

Binds the settings to the current thread permanently.

Trait Implementations

impl Clone for Settings[src]

impl Default for Settings[src]

Auto Trait Implementations

impl !RefUnwindSafe for Settings

impl Send for Settings

impl Sync for Settings

impl Unpin for Settings

impl !UnwindSafe for Settings

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

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

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

impl<T> From<T> for T[src]

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

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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.