42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/generators/tng/install_generator.rb', line 42
def ruby_configuration_template
framework_config = generate_framework_config(@test_framework)
if @authentication_library && @authentication_library != "none"
auth_enabled = "config.authentication_enabled = true"
= " (detected: #{@authentication_library})"
auth_lib = "config.authentication_library = \"#{@authentication_library}\""
else
auth_enabled = "config.authentication_enabled = true"
= ""
auth_lib = "config.authentication_library = nil"
end
if @authz_library && @authz_library != "none"
authz_lib = "config.authorization_library = \"#{@authz_library}\""
= " (detected: #{@authz_library})"
else
authz_lib = "config.authorization_library = nil"
= ""
end
factory_lib = "config.factory_library = \"#{@factory_library}\""
framework_specific = generate_framework_specific_config(@test_framework, framework_config)
test_examples_config = @test_examples.any? ? @test_examples.inspect : "[]"
[
"# frozen_string_literal: true",
"",
"return unless Rails.env.development?",
"",
"Tng.configure do |config|",
" config.api_key = nil",
" # You dont need to change this url, unless you will instructed by the CLI.",
" config.base_url = \"https://app.tng.sh/\"",
"",
" # Testing Framework",
" config.testing_framework = \"#{@test_framework}\" # Options: minitest, rspec",
framework_specific,
" config.mock_library = \"#{framework_config["mock_library"]}\" # Options: mocha, minitest/mock, rspec-mocks, nil",
" config.http_mock_library = \"#{framework_config["http_mock_library"]}\" # Options: webmock, vcr, httparty, nil",
" #{factory_lib} # Options: factory_bot, factory_girl, fabrication, fabricator, fixtures, active_record",
"",
" # Test Examples",
" # Example test files for LLM to learn patterns and reduce hallucinations",
" # Format: [{{\"name\" => \"test_name\", \"path\" => \"spec/models/user_spec.rb\"}}]",
" # Leave empty [] to auto-detect from project",
" config.test_examples = #{test_examples_config}",
"",
" # Source Code Reading Configuration",
" # When enabled (true), TNG will only read the file where the method is located",
" # and will not analyze other files in the project. This may increase the accuracy of the tests,",
" # but it may also increase the time it takes to generate the tests.",
" config.read_file_source_code = false # Options: true, false",
"",
" # Authentication#{auth_comment}",
" #{auth_enabled} # Options: true, false",
" #{auth_lib} # Options: devise, clearance, sorcery, nil",
"",
"",
" # ⚠️ IMPORTANT: AUTHENTICATION CONFIGURATION REQUIRED ⚠️",
" # You MUST configure your authentication methods below for TNG to work properly.",
" # Uncomment and modify the authentication_methods configuration:",
"",
" # Authentication Methods (multiple methods supported)",
" # Supported authentication types: session, devise, jwt, token_auth, basic_auth, oauth, headers, custom, nil",
" # EXAMPLE: Uncomment and modify these examples to match your app's authentication:",
"",
" # config.authentication_methods = [",
" # {",
" # method: \"authenticate_user_via_session!\",",
" # file_location: \"app/controllers/application_controller.rb\",",
" # auth_type: \"session\"",
" # },",
" # {",
" # method: \"authenticate_user_via_api_key!\",",
" # file_location: \"app/controllers/application_controller.rb\",",
" # auth_type: \"headers\"",
" # }",
" # ]",
" # ⚠️ Remember to configure your authentication methods above! ⚠️",
"",
" # Authorization#{authz_comment}",
" #{authz_lib} # Options: cancancan, pundit, rolify, nil",
"end"
].join("\n") + "\n"
end
|