From 793687806e50d5adbd6e2942059f9e2d3b73cefc Mon Sep 17 00:00:00 2001 From: Spenser Black Date: Mon, 13 Nov 2023 21:20:15 +0000 Subject: [PATCH] Convert author tests to snapshot tests --- src/info/author.rs | 22 +++++-------------- ...fo_value_alignment_with_three_authors.snap | 7 ++++++ ...st__author_info_value_with_one_author.snap | 5 +++++ ...t__author_info_value_with_two_authors.snap | 6 +++++ 4 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 src/info/snapshots/onefetch__info__author__test__author_info_value_alignment_with_three_authors.snap create mode 100644 src/info/snapshots/onefetch__info__author__test__author_info_value_with_one_author.snap create mode 100644 src/info/snapshots/onefetch__info__author__test__author_info_value_with_two_authors.snap diff --git a/src/info/author.rs b/src/info/author.rs index ff8b9c906..9a2e45b2e 100644 --- a/src/info/author.rs +++ b/src/info/author.rs @@ -126,6 +126,7 @@ impl InfoField for AuthorsInfo { #[cfg(test)] mod test { use super::*; + use insta::assert_snapshot; #[test] fn test_display_author() { @@ -189,6 +190,7 @@ mod test { assert_eq!(authors_info.title(), "Authors"); } + // TODO Move these snapshot tests to a more appropriate module so that the title and value are tested together #[test] fn test_author_info_value_with_one_author() { let author = Author::new( @@ -203,10 +205,7 @@ mod test { authors: vec![author], }; - assert_eq!( - authors_info.value(), - "75% John Doe 1500".to_string() - ); + assert_snapshot!(authors_info.value()); } #[test] @@ -235,9 +234,7 @@ mod test { .value() .contains(&"75% John Doe 1500".to_string())); - assert!(authors_info - .value() - .contains(&"80% Roberto Berto 240".to_string())); + assert_snapshot!(authors_info.value()); } #[test] fn test_author_info_value_alignment_with_three_authors() { @@ -263,15 +260,6 @@ mod test { authors: vec![author, author_2, author_3], }; - assert!(authors_info - .value() - .contains(&"75% John Doe 1500".to_string())); - - assert!(authors_info - .value() - .contains(&"80% Roberto Berto 240".to_string())); - - // Note the extra leading space to right-align the percentages - assert!(authors_info.value().contains(&" 1% Jane Doe 1".to_string())); + assert_snapshot!(authors_info.value()); } } diff --git a/src/info/snapshots/onefetch__info__author__test__author_info_value_alignment_with_three_authors.snap b/src/info/snapshots/onefetch__info__author__test__author_info_value_alignment_with_three_authors.snap new file mode 100644 index 000000000..97c2a3337 --- /dev/null +++ b/src/info/snapshots/onefetch__info__author__test__author_info_value_alignment_with_three_authors.snap @@ -0,0 +1,7 @@ +--- +source: src/info/author.rs +expression: authors_info.value() +--- +75% John Doe 1500 + 80% Roberto Berto 240 + 1% Jane Doe 1 diff --git a/src/info/snapshots/onefetch__info__author__test__author_info_value_with_one_author.snap b/src/info/snapshots/onefetch__info__author__test__author_info_value_with_one_author.snap new file mode 100644 index 000000000..35f0eb349 --- /dev/null +++ b/src/info/snapshots/onefetch__info__author__test__author_info_value_with_one_author.snap @@ -0,0 +1,5 @@ +--- +source: src/info/author.rs +expression: authors_info.value() +--- +75% John Doe 1500 diff --git a/src/info/snapshots/onefetch__info__author__test__author_info_value_with_two_authors.snap b/src/info/snapshots/onefetch__info__author__test__author_info_value_with_two_authors.snap new file mode 100644 index 000000000..6e26cfdb6 --- /dev/null +++ b/src/info/snapshots/onefetch__info__author__test__author_info_value_with_two_authors.snap @@ -0,0 +1,6 @@ +--- +source: src/info/author.rs +expression: authors_info.value() +--- +75% John Doe 1500 + 80% Roberto Berto 240