aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-04-24 06:36:32 -0400
committerTeddy Wing2016-04-24 06:36:32 -0400
commit66193af4e53799299c04ecf8715e44693f1bff8a (patch)
tree33696e3319e10e1d483c1c13993dacf6ef8593e0
parent15759804bd3be99fc6374ee993038440267fdfb5 (diff)
downloadmutt-alias-auto-add-66193af4e53799299c04ecf8715e44693f1bff8a.tar.bz2
Extract `alias_write_to_file` test function contents to helper
Create a new helper function that does the work of `alias_write_to_file_must_write_given_alias_to_file`. We want to be able to add another test of the `write_to_file` method that does the same thing but for non-preexisting aliases. Making a helper method will allow us to avoid duplicating work.
-rw-r--r--src/tests.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/tests.rs b/src/tests.rs
index 708121e..e4ec254 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -122,10 +122,7 @@ fn update_alias_id_increments_alias() {
}
-#[test]
-fn alias_write_to_file_must_write_given_alias_to_file() {
- let mut alias = update_alias_id_sample_alias();
-
+fn alias_write_to_file_helper(alias: &mut Alias) -> String {
// Create a new test file
let test_file = "./testdata/write_to_file";
fs::copy("./testdata/aliases", test_file).expect("Alias file copy failed");
@@ -148,5 +145,13 @@ fn alias_write_to_file_must_write_given_alias_to_file() {
let file_contents: Vec<&str> = file_contents.split('\n').collect();
fs::remove_file(test_file).expect("Failed to delete test file");
- assert_eq!(alias.to_string(), file_contents[file_contents.len() - 2]);
+ file_contents[file_contents.len() - 2].to_string()
+}
+
+#[test]
+fn alias_write_to_file_must_write_given_alias_to_file() {
+ let mut alias = update_alias_id_sample_alias();
+ let alias_line = alias_write_to_file_helper(&mut alias);
+
+ assert_eq!(alias.to_string(), alias_line);
}