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

refactor: use insta for tests snapshots #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aljazerzen
Copy link
Contributor

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.

@mrjackwills
Copy link
Owner

Still need to get my head around this, will have a play around with it all

@aljazerzen
Copy link
Contributor Author

I have converted only a few of the tests, to see if you want to go ahead with it first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants