[−][src]Struct insta::Settings
Configures how insta operates at test time.
Settings are always bound to a thread and some default settings are always available. Settings can be either temporarily bound of permanently.
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.
Settings can also be configured with the with_settings!
macro.
Example:
use insta; let mut settings = insta::Settings::new(); settings.set_sort_maps(true); settings.bind(|| { insta::assert_snapshot!(...); });
Methods
impl Settings
[src]
pub fn new() -> Settings
[src]
Returns the default 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 add_redaction<R: Into<Redaction>>(
&mut self,
selector: &str,
replacement: R
)
[src]
&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,
[src]
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_to_thread(&self)
[src]
Binds the settings to the current thread permanently.
Trait Implementations
Auto Trait Implementations
impl Send for Settings
impl Sync for Settings
impl Unpin for Settings
impl !UnwindSafe for Settings
impl !RefUnwindSafe for Settings
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,