aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2016-04-22 02:28:45 -0400
committerTeddy Wing2016-04-22 02:28:45 -0400
commitbf3b4fa20746f074ebbdbe1b0d45a24da69837f5 (patch)
treed2e8a6764fa5b058b211a04006e1b10bc0ad852d /src
parente008a5b8340ebf2a9965f3ce953a954997e0bb54 (diff)
downloadmutt-alias-auto-add-bf3b4fa20746f074ebbdbe1b0d45a24da69837f5.tar.bz2
Make `update_alias_id` tests more DRY
Eliminate some of the repeated setup code in our tests for this method. Instead of doing this work inside the test functions, move them to a new constant binding and function respectively. A `const` seemed like a good fit because our alias identifier is just a string. For the `Alias`, we have a new function that returns a test object for us, making it possible to get two mutable copies of it (one for each of our test functions). Tests still pass, I guess it worked.
Diffstat (limited to 'src')
-rw-r--r--src/tests.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/tests.rs b/src/tests.rs
index f877408..b3a172c 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -90,27 +90,27 @@ fn find_alias_in_file_finds_a_match() {
}
-#[test]
-fn update_alias_id_does_nothing_given_an_empty_vector() {
- let alias_identifier = "hooves-derpy";
- let mut alias = Alias {
- alias: alias_identifier.to_owned(),
+const update_alias_id_alias_identifier: &'static str = "hooves-derpy";
+
+fn update_alias_id_sample_alias() -> Alias {
+ Alias {
+ alias: update_alias_id_alias_identifier.to_owned(),
name: "Derpy Hooves".to_owned(),
email: "derpyhooves@postmaster.pv".to_owned()
- };
+ }
+}
+
+#[test]
+fn update_alias_id_does_nothing_given_an_empty_vector() {
+ let mut alias = update_alias_id_sample_alias();
alias.update_alias_id(vec![]);
- assert_eq!(alias_identifier, &alias.alias);
+ assert_eq!(update_alias_id_alias_identifier, &alias.alias);
}
#[test]
fn update_alias_id_increments_alias() {
- let alias_identifier = "hooves-derpy";
- let mut alias = Alias {
- alias: alias_identifier.to_owned(),
- name: "Derpy Hooves".to_owned(),
- email: "derpyhooves@postmaster.pv".to_owned()
- };
+ let mut alias = update_alias_id_sample_alias();
alias.update_alias_id(vec![
"hooves-derpy".to_owned(),
"hooves-derpy-2".to_owned(),