Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix require_full_match #485

Merged
merged 6 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ impl PendingInlineSnapshot {
pub struct MetaData {
/// The source file (relative to workspace root).
pub(crate) source: Option<String>,
/// The source line if available.
/// The source line, if available. This is used by pending snapshots, but trimmed
/// before writing to the final `.snap` files in [`MetaData::trim_for_persistence`].
pub(crate) assertion_line: Option<u32>,
/// Optional human readable (non formatted) snapshot description.
pub(crate) description: Option<String>,
Expand Down Expand Up @@ -246,7 +247,8 @@ impl MetaData {
Content::Struct("MetaData", fields)
}

/// Trims the metadata for persistence.
/// Trims the metadata of fields that we don't save to `.snap` files; we
/// only use for display while reviewing
fn trim_for_persistence(&self) -> Cow<'_, MetaData> {
if self.assertion_line.is_some() {
let mut rv = self.clone();
Expand Down Expand Up @@ -422,7 +424,8 @@ impl Snapshot {

/// Snapshot contents _and_ metadata match another snapshot's.
pub fn matches_fully(&self, other: &Snapshot) -> bool {
self.matches(other) && self.metadata == other.metadata
self.matches(other)
&& self.metadata.trim_for_persistence() == other.metadata.trim_for_persistence()
}

/// The snapshot contents as a &str
Expand Down
Loading