@@ -301,11 +301,20 @@ mod tests {
301301 ) ) )
302302 }
303303
304- #[ test]
305- fn it_should_create_context_with_production_dependencies ( ) {
304+ /// Test helper to create a test context with temporary directory
305+ ///
306+ /// Returns a tuple of (`TempDir`, `PathBuf`, `Arc<Mutex<UserOutput>>`)
307+ /// The `TempDir` must be kept alive for the duration of the test.
308+ fn create_test_setup ( ) -> ( TempDir , PathBuf , Arc < std:: sync:: Mutex < UserOutput > > ) {
306309 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
307310 let working_dir = temp_dir. path ( ) . to_path_buf ( ) ;
308311 let user_output = create_test_user_output ( ) ;
312+ ( temp_dir, working_dir, user_output)
313+ }
314+
315+ #[ test]
316+ fn it_should_create_context_with_production_dependencies ( ) {
317+ let ( _temp_dir, working_dir, user_output) = create_test_setup ( ) ;
309318
310319 let ctx = CommandContext :: new ( working_dir, user_output) ;
311320
@@ -316,9 +325,7 @@ mod tests {
316325
317326 #[ test]
318327 fn it_should_provide_access_to_repository ( ) {
319- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
320- let working_dir = temp_dir. path ( ) . to_path_buf ( ) ;
321- let user_output = create_test_user_output ( ) ;
328+ let ( _temp_dir, working_dir, user_output) = create_test_setup ( ) ;
322329
323330 let ctx = CommandContext :: new ( working_dir, user_output) ;
324331
@@ -328,9 +335,7 @@ mod tests {
328335
329336 #[ test]
330337 fn it_should_provide_access_to_clock ( ) {
331- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
332- let working_dir = temp_dir. path ( ) . to_path_buf ( ) ;
333- let user_output = create_test_user_output ( ) ;
338+ let ( _temp_dir, working_dir, user_output) = create_test_setup ( ) ;
334339
335340 let ctx = CommandContext :: new ( working_dir, user_output) ;
336341
@@ -340,9 +345,7 @@ mod tests {
340345
341346 #[ test]
342347 fn it_should_provide_access_to_user_output ( ) {
343- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
344- let working_dir = temp_dir. path ( ) . to_path_buf ( ) ;
345- let user_output = create_test_user_output ( ) ;
348+ let ( _temp_dir, working_dir, user_output) = create_test_setup ( ) ;
346349
347350 let ctx = CommandContext :: new ( working_dir, user_output) ;
348351
@@ -354,9 +357,7 @@ mod tests {
354357
355358 #[ test]
356359 fn it_should_create_context_with_factory ( ) {
357- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
358- let working_dir = temp_dir. path ( ) . to_path_buf ( ) ;
359- let user_output = create_test_user_output ( ) ;
360+ let ( _temp_dir, working_dir, user_output) = create_test_setup ( ) ;
360361
361362 let repository_factory = RepositoryFactory :: new ( DEFAULT_LOCK_TIMEOUT ) ;
362363 let ctx = CommandContext :: new_with_factory ( & repository_factory, working_dir, user_output) ;
@@ -389,9 +390,7 @@ mod tests {
389390
390391 #[ test]
391392 fn it_should_allow_accessing_output_multiple_times ( ) {
392- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
393- let working_dir = temp_dir. path ( ) . to_path_buf ( ) ;
394- let user_output = create_test_user_output ( ) ;
393+ let ( _temp_dir, working_dir, user_output) = create_test_setup ( ) ;
395394
396395 let ctx = CommandContext :: new ( working_dir, user_output) ;
397396
@@ -404,9 +403,7 @@ mod tests {
404403
405404 #[ test]
406405 fn it_should_use_default_constants ( ) {
407- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
408- let working_dir = temp_dir. path ( ) . to_path_buf ( ) ;
409- let user_output = create_test_user_output ( ) ;
406+ let ( _temp_dir, working_dir, user_output) = create_test_setup ( ) ;
410407
411408 // Creating context should use DEFAULT_LOCK_TIMEOUT
412409 let _ctx = CommandContext :: new ( working_dir, user_output) ;
0 commit comments