There are some settings that can be changed on a per-thread (and thus per-test) basis. These are documented in detail in the API docs of the Settings object.

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.

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.

Configuration Basics

All available settings are documented as part of the main API documentation. They can be reconfigured by setter (set_SETTING_NAME) on the settings object or by field name (SETTING_NAME) when you use the with_settings! macro.

Configuration Macro

One rather convenient way to change the settings is to use the with_settings! macro. It lets you reconfigure any setting for the duration of a block:

insta::with_settings!({sort_maps => true}, {
    // the tests here will force maps to sort

Temporarily Rebinding

let mut settings = insta::Settings::clone_current();
settings.bind(|| {
    // the tests here will force maps to sort

Settings as Building Blocks

While settings can be used to influence how Insta operates, they also act as a building block for more complex test setups. For instance the glob macro internally is implemented by changing the settings on the file to provide additional contextual information in the form of the current input file.

Found an issue? You can edit this page on GitHub.