Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Sep 2, 2024
1 parent 41cb4c0 commit d37797b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
17 changes: 8 additions & 9 deletions insta/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<'a> SnapshotAssertionContext<'a> {
elog!(
"{}",
style(
"error: cannot update inline snapshots in-place \
"error: cannot update inline snapshots in-place. Please use `cargo-insta` \
(https://github.com/mitsuhiko/insta/issues/272)"
)
.red()
Expand All @@ -403,14 +403,13 @@ impl<'a> SnapshotAssertionContext<'a> {
SnapshotUpdateBehavior::NewFile => {
if let Some(ref snapshot_file) = self.snapshot_file {
// File snapshot
if let Some(new_path) = new_snapshot.save_new(snapshot_file)? {
if should_print {
elog!(
"{} {}",
style("stored new snapshot").green(),
style(new_path.display()).cyan().underlined(),
);
}
let new_path = new_snapshot.save_new(snapshot_file)?;
if should_print {
elog!(
"{} {}",
style("stored new snapshot").green(),
style(new_path.display()).cyan().underlined(),
);
}
} else if self.is_doctest {
if should_print {
Expand Down
7 changes: 3 additions & 4 deletions insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,11 @@ impl Snapshot {
/// Same as `save` but instead of writing a normal snapshot file this will write
/// a `.snap.new` file with additional information.
///
/// If the existing snapshot matches the new file, then `None` is returned, otherwise
/// the name of the new snapshot file.
pub(crate) fn save_new(&self, path: &Path) -> Result<Option<PathBuf>, Box<dyn Error>> {
/// The name of the new snapshot file is returned.
pub(crate) fn save_new(&self, path: &Path) -> Result<PathBuf, Box<dyn Error>> {
let new_path = path.to_path_buf().with_extension("snap.new");
self.save_with_metadata(&new_path, &self.metadata)?;
Ok(Some(new_path))
Ok(new_path)
}
}

Expand Down

0 comments on commit d37797b

Please sign in to comment.