From 66193af4e53799299c04ecf8715e44693f1bff8a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 24 Apr 2016 06:36:32 -0400 Subject: 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. --- src/tests.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3