Skip to content

Commit

Permalink
Add test for force-updating legacy snapshots (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Oct 10, 2024
1 parent ce2b3fd commit c3d6f16
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions cargo-insta/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,16 +861,40 @@ fn test_old_yaml_format() {
)
.create_project();

// Run the test with --force-update-snapshots and --accept
let output = test_project
// Check it passes
assert!(test_project
.insta_cmd()
.args(["test", "--accept", "--", "--nocapture"])
.args(["test", "--", "--nocapture"])
.output()
.unwrap();
.unwrap()
.status
.success());
// shouldn't be any changes
assert_snapshot!(test_project.diff("src/lib.rs"), @"");

assert!(&output.status.success());
// Also check that running with `--force-update-snapshots` updates the snapshot
assert!(test_project
.insta_cmd()
.args(["test", "--force-update-snapshots", "--", "--nocapture"])
.output()
.unwrap()
.status
.success());

assert_snapshot!(test_project.diff("src/lib.rs"), @"");
assert_snapshot!(test_project.diff("src/lib.rs"), @r#####"
--- Original: src/lib.rs
+++ Updated: src/lib.rs
@@ -1,8 +1,5 @@
#[test]
fn test_old_yaml_format() {
- insta::assert_yaml_snapshot!("foo", @r####"
- ---
- foo
-"####);
+ insta::assert_yaml_snapshot!("foo", @"foo");
}
"#####);
}

#[test]
Expand Down

0 comments on commit c3d6f16

Please sign in to comment.