Macro insta::assert_yaml_snapshot[][src]

macro_rules! assert_yaml_snapshot {
    ($value:expr, @$snapshot:literal) => { ... };
    ($value:expr, {$($k:expr => $v:expr),*$(,)?}, @$snapshot:literal) => { ... };
    ($value:expr, {$($k:expr => $v:expr),*$(,)?}) => { ... };
    ($name:expr, $value:expr) => { ... };
    ($name:expr, $value:expr, {$($k:expr => $v:expr),*$(,)?}) => { ... };
    ($value:expr) => { ... };
}

Asserts a Serialize snapshot in YAML format.

The value needs to implement the serde::Serialize trait and the snapshot will be serialized in YAML format. This does mean that unlike the debug snapshot variant the type of the value does not appear in the output. You can however use the assert_ron_snapshot! macro to dump out the value in RON format which retains some type information for more accurate comparisions.

Example:

assert_yaml_snapshot!(vec![1, 2, 3]);

Unlike the assert_debug_snapshot! macro, this one has a secondary mode where redactions can be defined.

The third argument to the macro can be an object expression for redaction. It’s in the form { selector => replacement }. For more information about redactions refer to the redactions feature in the guide.

Example:

assert_yaml_snapshot!(value, {
   ".key.to.redact" => "[replacement value]",
   ".another.key.*.to.redact" => 42
});

The replacement value can be a string, integer or any other primitive value.

For inline usage the format is (expression, @reference_value) where the reference value must be a string literal. If you make the initial snapshot just use an empty string (@"").

The snapshot name is optional but can be provided as first argument.