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

Inline snapshot overwriting for snapbox #221

Closed
not-my-profile opened this issue Aug 13, 2023 · 5 comments
Closed

Inline snapshot overwriting for snapbox #221

not-my-profile opened this issue Aug 13, 2023 · 5 comments
Labels
A-snapbox Area: snapbox package enhancement Improve the expected

Comments

@not-my-profile
Copy link

Snapbox currently only appears to support SNAPSHOTS=overwrite for assert_eq_path and assert_matches_path but not for inline snapshot assertions like assert_eq or assert_matches.

The popular cargo-insta tool does support the updating of inline snapshots. So I think the current lack of support should certainly be documented.

If supporting inline snapshots is out of the scope of snapbox, I think a reference to Insta in the documentation would be nice.

If it is within scope of snapbox, reliably parsing Rust code would require a dependency on syn, which however could be feature-gated and disabled by default. The inline::FilePatcher implementation of cargo-insta looks quite brief, which would suggest that supporting this feature wouldn't take much additional code here.

@epage
Copy link
Contributor

epage commented Aug 14, 2023

expect-test is also pretty minimal.

The biggest problem is getting the path to the file. At the moment, only heuristics work or people have to opt-in to a hacky solution. rust-lang/cargo#3946 would unblock that which is what I've been waiting on.

@epage epage added enhancement Improve the expected A-snapbox labels Aug 14, 2023
@not-my-profile
Copy link
Author

I see, thanks for elaborating :)

(link to the issue you mentioned: rust-lang/cargo#3946)

@epage
Copy link
Contributor

epage commented Aug 14, 2023

Thanks; its too easy to overlook crossing repo boundaries when linking

@epage
Copy link
Contributor

epage commented Aug 19, 2023

As mentioned in #225, the new API I expect for this would be something like assert_eq(data!("..."), ...) which would also allow assert_eq(Data::from_path("..."), ...), allowing the code to be unified between the snapshot being in-source vs external.

In fact, that API refactor can happen before the requisite cargo features are available.

@epage
Copy link
Contributor

epage commented Feb 14, 2024

Oops, we had #135 for this. Closing in favor of that. #251 will close it.

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-snapbox Area: snapbox package enhancement Improve the expected
Projects
None yet
Development

No branches or pull requests

2 participants