macro_rules! assert_yaml_snapshot { ($($arg:tt)*) => { ... }; }
yaml
only.Expand description
Asserts a serde::Serialize
snapshot in YAML format.
Feature: yaml
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 comparisons.
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 }
or match .. { 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.