Skip to content

Commit e2efe88

Browse files
committed
test: [#246] Fix doctests creating schema.json artifacts in root
- Updated two doctests in CreateSchemaCommandHandler to use TempDir - Follows resource management guidelines from docs/contributing/testing/resource-management.md - Prevents schema.json file from being left in project root after tests - Both doctests now clean up automatically via TempDir drop
1 parent 50c0243 commit e2efe88

File tree

1 file changed

+10
-4
lines changed
  • src/application/command_handlers/create/schema

1 file changed

+10
-4
lines changed

src/application/command_handlers/create/schema/handler.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ use super::errors::CreateSchemaCommandHandlerError;
2626
/// ```rust
2727
/// use torrust_tracker_deployer_lib::application::command_handlers::create::schema::CreateSchemaCommandHandler;
2828
/// use std::path::PathBuf;
29+
/// use tempfile::TempDir;
2930
///
3031
/// // Generate to stdout
3132
/// let schema = CreateSchemaCommandHandler::execute(None)?;
3233
/// println!("{}", schema);
3334
///
34-
/// // Generate to file
35-
/// CreateSchemaCommandHandler::execute(Some(PathBuf::from("schema.json")))?;
35+
/// // Generate to file (use temp directory to avoid leaving artifacts)
36+
/// let temp_dir = TempDir::new()?;
37+
/// let schema_path = temp_dir.path().join("schema.json");
38+
/// CreateSchemaCommandHandler::execute(Some(schema_path))?;
3639
/// # Ok::<(), Box<dyn std::error::Error>>(())
3740
/// ```
3841
pub struct CreateSchemaCommandHandler;
@@ -62,13 +65,16 @@ impl CreateSchemaCommandHandler {
6265
/// ```rust
6366
/// use torrust_tracker_deployer_lib::application::command_handlers::create::schema::CreateSchemaCommandHandler;
6467
/// use std::path::PathBuf;
68+
/// use tempfile::TempDir;
6569
///
6670
/// // Output to stdout (caller prints the returned string)
6771
/// let schema = CreateSchemaCommandHandler::execute(None)?;
6872
/// println!("{}", schema);
6973
///
70-
/// // Output to file
71-
/// let schema = CreateSchemaCommandHandler::execute(Some(PathBuf::from("./schema.json")))?;
74+
/// // Output to file (use temp directory to avoid leaving artifacts)
75+
/// let temp_dir = TempDir::new()?;
76+
/// let schema_path = temp_dir.path().join("schema.json");
77+
/// let schema = CreateSchemaCommandHandler::execute(Some(schema_path))?;
7278
/// // File is written, schema string also returned for confirmation
7379
/// # Ok::<(), Box<dyn std::error::Error>>(())
7480
/// ```

0 commit comments

Comments
 (0)