|
| 1 | +/// Ruby SDK Generator Module |
| 2 | +/// |
| 3 | +/// This module implements the SDK generator for Ruby. |
| 4 | +mod generator; |
| 5 | + |
| 6 | +pub use generator::Ruby; |
| 7 | + |
| 8 | +#[cfg(test)] |
| 9 | +mod tests { |
| 10 | + use crate::ruby::generator::Ruby; |
| 11 | + use std::fs; |
| 12 | + use std::path::Path; |
| 13 | + use tempfile::Builder; |
| 14 | + use xdk_lib::Result; |
| 15 | + use xdk_lib::generator::generate; |
| 16 | + use xdk_openapi::{OpenApiContextGuard, parse_json_file}; |
| 17 | + |
| 18 | + fn create_output_dir() -> std::path::PathBuf { |
| 19 | + let temp_dir = Builder::new() |
| 20 | + .prefix("test_output_ruby") |
| 21 | + .tempdir() |
| 22 | + .expect("Failed to create temporary directory"); |
| 23 | + temp_dir.path().to_path_buf() |
| 24 | + } |
| 25 | + |
| 26 | + fn verify_sdk_structure(output_dir: &Path) { |
| 27 | + let lib_dir = output_dir.join("lib").join("xdk"); |
| 28 | + assert!(lib_dir.exists(), "lib/xdk directory should exist"); |
| 29 | + assert!( |
| 30 | + lib_dir.join("client.rb").exists(), |
| 31 | + "lib/xdk/client.rb should exist" |
| 32 | + ); |
| 33 | + assert!( |
| 34 | + lib_dir.join("version.rb").exists(), |
| 35 | + "lib/xdk/version.rb should exist" |
| 36 | + ); |
| 37 | + assert!( |
| 38 | + output_dir.join("xdk.gemspec").exists(), |
| 39 | + "xdk.gemspec should exist" |
| 40 | + ); |
| 41 | + assert!( |
| 42 | + output_dir.join("README.md").exists(), |
| 43 | + "README.md should exist" |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + #[test] |
| 48 | + fn test_simple_openapi() { |
| 49 | + let output_dir = create_output_dir(); |
| 50 | + let _guard = OpenApiContextGuard::new(); |
| 51 | + let openapi = parse_json_file("../tests/openapi/simple.json").unwrap(); |
| 52 | + let result = generate(Ruby, &openapi, &output_dir, "0.0.1-test"); |
| 53 | + assert!(result.is_ok(), "Failed to generate SDK: {:?}", result); |
| 54 | + verify_sdk_structure(&output_dir); |
| 55 | + } |
| 56 | + |
| 57 | + #[test] |
| 58 | + fn test_version_in_generated_files() { |
| 59 | + let output_dir = create_output_dir(); |
| 60 | + let _guard = OpenApiContextGuard::new(); |
| 61 | + let openapi = parse_json_file("../tests/openapi/simple.json").unwrap(); |
| 62 | + |
| 63 | + let test_version = "1.2.3-test"; |
| 64 | + let result = generate(Ruby, &openapi, &output_dir, test_version); |
| 65 | + assert!(result.is_ok(), "Failed to generate SDK: {:?}", result); |
| 66 | + |
| 67 | + let version_content = fs::read_to_string(output_dir.join("lib/xdk/version.rb")) |
| 68 | + .expect("Failed to read version.rb"); |
| 69 | + assert!( |
| 70 | + version_content.contains("1.2.3-test"), |
| 71 | + "version.rb should contain the test version" |
| 72 | + ); |
| 73 | + } |
| 74 | +} |
0 commit comments