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

CSV with iterable of elements creates only 2 lines (header+content) #156

Closed
woshilapin opened this issue Jan 18, 2021 · 3 comments · Fixed by #160
Closed

CSV with iterable of elements creates only 2 lines (header+content) #156

woshilapin opened this issue Jan 18, 2021 · 3 comments · Fixed by #160

Comments

@woshilapin
Copy link

woshilapin commented Jan 18, 2021

Description

I believe this playground explains the problem. When we .serialize() a Vec of objects that implements Serialize with the Serializer of the csv crate, it doesn't create a line for each object but flatten them together. There might be good reasons to do it in csv but it does make assert_csv_snapshot!() not really useful. I hope I did not miss an obvious solution to what I'm trying to do. And also, I was not sure to report this as a bug or as a feature so please forgive me if that's not the right category.

Additional helpful information:

  • Version of insta: 1.5.2
  • Version of rustc: 1.49.0
  • Operating system and version: Linux Ubuntu 20.10

What did you expect

I would expect to be able to send a Vec or any kind of iterator of objects implementing Serialize, to the macro assert_csv_snapshot!() and be able to have a multiline *.snap instead of a 2-lines (one header line + one content line).

@mitsuhiko
Copy link
Owner

Yep. I also ran into this and I think the current format is not particularly useful. Would accept a PR to modify this behavior but currently relatively low priority for myself to fix this.

@woshilapin
Copy link
Author

I wanted to be sure that it could not be solved at a higher level, but I would say that BurntSushi/rust-csv#221 is a pretty clear answer about it.

I might take a look at how to improve the behavior of assert_csv_snapshot!().

@woshilapin
Copy link
Author

woshilapin commented Feb 7, 2021

Thank you for the feature! That is just perfect!

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 a pull request may close this issue.

2 participants