oxker
oxker copied to clipboard
refactor: use insta for tests snapshots
When changing the interface, tests had to be updated using following error messages to find the mismatch:
---- ui::draw_blocks::tests::test_draw_blocks_whole_layout_long_name stdout ----
thread 'ui::draw_blocks::tests::test_draw_blocks_whole_layout_long_name' panicked at src/ui/draw_blocks.rs:3192:17:
assertion `left == right` failed
left: "n"
right: " "
I've now added insta, that defines tests like this:
assert_snapshot!(
text, @r#"
╭──────────╮
│▶ pause │
│ restart │
│ stop │
│ remove │
╰──────────╯
"#
);
... and produces error messages like this:
---- ui::draw_blocks::tests::test_draw_blocks_commands_panel_selected_color stdout ----
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot: draw_blocks_commands_panel_selected_color
Source: src/ui/draw_blocks.rs:1274
─────────────────────────────────────────────────────────────────────────────────────────────────────
Expression: text
─────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬────────────────────────────────────────────────────────────────────────────────────────
0 0 │ ╭──────────╮
1 1 │ │▶ pause │
2 2 │ │ restart │
3 3 │ │ stop │
4 │-│ remove │
4 │+│ delete │
5 5 │ ╰──────────╯
────────────┴────────────────────────────────────────────────────────────────────────────────────────
To update snapshots run `cargo insta review`
Stopped on the first failure. Run `cargo insta test` to run all snapshots.