Macro insta::with_settings

source ·
macro_rules! with_settings {
    ({$($k:ident => $v:expr),*$(,)?}, $body:block) => { ... };
Expand description

Settings configuration macro.

This macro lets you bind some Settings temporarily. The first argument takes key value pairs that should be set, the second is the block to execute. All settings can be set (sort_maps => value maps to set_sort_maps(value)). The exception are redactions which can only be set to a vector this way.

This example:

insta::with_settings!({sort_maps => true}, {
    // run snapshot test here

Is equivalent to the following:

let mut settings = Settings::clone_current();
settings.bind(|| {
    // run snapshot test here

Note: before insta 0.17 this macro used Settings::new which meant that original settings were always reset rather than extended.