tng 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,7 +54,8 @@ module Tng
54
54
  def self.extract_method_source(file_path, method_name)
55
55
  return unless file_path && method_name
56
56
 
57
- full_path = Rails.root.join(file_path)
57
+ return unless defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root
58
+ full_path = ::Rails.root.join(file_path)
58
59
  return unless File.exist?(full_path)
59
60
 
60
61
  file_content = File.read(full_path)
@@ -76,7 +77,7 @@ module Tng
76
77
  def self.read_test_file_content(relative_path)
77
78
  return nil unless relative_path
78
79
 
79
- rails_root = defined?(Rails) && Rails.root ? Rails.root.to_s : Dir.pwd
80
+ rails_root = defined?(::Rails) && ::Rails.root ? ::Rails.root.to_s : Dir.pwd
80
81
  full_path = File.join(rails_root, relative_path)
81
82
 
82
83
  return nil unless File.exist?(full_path) && File.readable?(full_path)
@@ -61,6 +61,24 @@ module Tng
61
61
  _cleanup_temp_file(output_path)
62
62
  end
63
63
  end
64
+
65
+ # Returns: "model", "service", "job", "lib", "utility", "other", "back"
66
+ def show_ruby_test_type_menu
67
+ output_path = _create_temp_file("go_ui_ruby_test_type", ".json")
68
+
69
+ begin
70
+ system(@binary_path, "ruby-test-menu", "--output", output_path)
71
+
72
+ return "back" unless File.exist?(output_path) && File.size(output_path) > 0
73
+
74
+ choice = File.read(output_path).strip
75
+ choice.empty? ? "back" : choice
76
+ rescue StandardError
77
+ "back"
78
+ ensure
79
+ _cleanup_temp_file(output_path)
80
+ end
81
+ end
64
82
  # Returns: "1", "2", "all", "back"
65
83
  def show_clone_menu
66
84
  output_path = _create_temp_file("go_ui_clone_menu", ".json")
@@ -240,12 +258,13 @@ module Tng
240
258
  data_json = JSON.generate(audit_result)
241
259
  input_path = _create_temp_file("go_ui_audit", ".json")
242
260
  File.write(input_path, data_json)
261
+ puts "Audit results file: #{input_path}" if ENV["TNG_KEEP_TMP"] == "1"
243
262
 
244
263
  system(@binary_path, command, "--file", input_path)
245
264
  rescue StandardError => e
246
265
  puts "Audit results error: #{e.message}"
247
266
  ensure
248
- _cleanup_temp_file(input_path)
267
+ _cleanup_temp_file(input_path) unless ENV["TNG_KEEP_TMP"] == "1"
249
268
  end
250
269
 
251
270
  # Show symbolic trace results
@@ -22,10 +22,10 @@ class PostInstallBox
22
22
  pastel.public_send(Tng::UI::Theme.color(:warning)).bold("#{Tng::UI::Theme.icon(:config, ascii: true)} SETUP REQUIRED"),
23
23
  "",
24
24
  pastel.public_send(Tng::UI::Theme.color(:primary), "1. Generate configuration:"),
25
- pastel.public_send(Tng::UI::Theme.color(:secondary), " rails g tng:install"),
25
+ pastel.public_send(Tng::UI::Theme.color(:secondary), " bundle exec tng init"),
26
26
  "",
27
27
  pastel.public_send(Tng::UI::Theme.color(:primary), "2. Edit configuration file:"),
28
- pastel.public_send(Tng::UI::Theme.color(:secondary), " config/initializers/tng.rb"),
28
+ pastel.public_send(Tng::UI::Theme.color(:secondary), " config/initializers/tng.rb (Rails) or ./tng.rb (generic Ruby)"),
29
29
  "",
30
30
  pastel.public_send(Tng::UI::Theme.color(:primary), "3. Add your license key:"),
31
31
  pastel.public_send(Tng::UI::Theme.color(:secondary), " config.api_key = 'your-license-key-here'"),
@@ -74,7 +74,7 @@ class PostInstallBox
74
74
  end
75
75
  rescue StandardError
76
76
  "TNG v#{@version} installed successfully!\n" +
77
- "Run 'rails g tng:install' to get started.\n" +
77
+ "Run 'bundle exec tng init' to get started.\n" +
78
78
  "Use 'bundle exec tng --help' for usage information."
79
79
  end
80
80
  end
data/lib/tng/utils.rb CHANGED
@@ -5,6 +5,42 @@ require "prism"
5
5
 
6
6
  module Tng
7
7
  module Utils
8
+ def self.rails_project?(root = Dir.pwd)
9
+ checks = 0
10
+
11
+ app_rb = File.join(root, "config", "application.rb")
12
+ checks += 1 if File.exist?(app_rb)
13
+
14
+ env_rb = File.join(root, "config", "environment.rb")
15
+ checks += 1 if File.exist?(env_rb)
16
+
17
+ gemfile = File.join(root, "Gemfile")
18
+ if File.exist?(gemfile)
19
+ begin
20
+ content = File.read(gemfile)
21
+ checks += 1 if content.match?(/gem ['"]rails['"]/)
22
+ rescue StandardError
23
+ # ignore read errors
24
+ end
25
+ end
26
+
27
+ config_ru = File.join(root, "config.ru")
28
+ if File.exist?(config_ru)
29
+ begin
30
+ content = File.read(config_ru)
31
+ checks += 1 if content.match?(/run\s+Rails\.application|Rails::Application/)
32
+ rescue StandardError
33
+ # ignore read errors
34
+ end
35
+ end
36
+
37
+ checks >= 3
38
+ end
39
+
40
+ def rails_project?(root = Dir.pwd)
41
+ Utils.rails_project?(root)
42
+ end
43
+
8
44
  def clear_screen
9
45
  system("clear") || system("cls")
10
46
  end
@@ -77,8 +113,8 @@ module Tng
77
113
  end
78
114
 
79
115
  def self.project_root
80
- if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
81
- Rails.root.to_s
116
+ if defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root
117
+ ::Rails.root.to_s
82
118
  else
83
119
  Dir.pwd
84
120
  end
@@ -230,7 +266,8 @@ module Tng
230
266
  def self.load_all_fixtures_data
231
267
  fixture_data = {}
232
268
  # TODO: Load proper folder for Rspec. This is only valid for minitest.
233
- fixtures_dir = Rails.root.join("test", "fixtures")
269
+ return fixture_data unless defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root
270
+ fixtures_dir = ::Rails.root.join("test", "fixtures")
234
271
 
235
272
  return fixture_data unless Dir.exist?(fixtures_dir)
236
273
 
@@ -252,7 +289,8 @@ module Tng
252
289
 
253
290
  def self.load_all_fabricator_data
254
291
  fabricator_data = {}
255
- fabricators_dir = Rails.root.join("spec", "fabricators")
292
+ return fabricator_data unless defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root
293
+ fabricators_dir = ::Rails.root.join("spec", "fabricators")
256
294
 
257
295
  return fabricator_data unless Dir.exist?(fabricators_dir)
258
296
 
@@ -272,9 +310,10 @@ module Tng
272
310
 
273
311
  def self.load_all_factory_data
274
312
  factory_data = {}
313
+ return factory_data unless defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root
275
314
  factory_dirs = [
276
- Rails.root.join("spec", "factories"),
277
- Rails.root.join("test", "factories")
315
+ ::Rails.root.join("spec", "factories"),
316
+ ::Rails.root.join("test", "factories")
278
317
  ]
279
318
 
280
319
  factory_dirs.each do |factory_dir|
data/lib/tng/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tng
4
- VERSION = "0.5.4"
4
+ VERSION = "0.5.5"
5
5
  end
data/lib/tng.rb CHANGED
@@ -10,7 +10,7 @@ require_relative "tng/ui/post_install_box"
10
10
  require_relative "tng/ui/go_ui_session"
11
11
  require_relative "tng/services/test_generator"
12
12
 
13
- require_relative "tng/railtie" if defined?(Rails)
13
+ require_relative "tng/railtie" if defined?(::Rails)
14
14
 
15
15
  begin
16
16
  require "rbconfig"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ralucab
@@ -177,8 +177,10 @@ files:
177
177
  - lib/tng/railtie.rb
178
178
  - lib/tng/services/direct_generation.rb
179
179
  - lib/tng/services/extract_methods.rb
180
+ - lib/tng/services/file_discovery.rb
180
181
  - lib/tng/services/file_type_detector.rb
181
182
  - lib/tng/services/fix_orchestrator.rb
183
+ - lib/tng/services/installer.rb
182
184
  - lib/tng/services/repair_service.rb
183
185
  - lib/tng/services/test_generator.rb
184
186
  - lib/tng/services/testng.rb
@@ -199,8 +201,8 @@ metadata:
199
201
  source_code_uri: https://github.com/tng-sh/tng-rails-public
200
202
  license_uri: https://github.com/tng-sh/tng-rails-public/blob/main/LICENSE.md
201
203
  post_install_message: |-
202
- TNG v0.5.4 installed successfully!
203
- Run 'rails g tng:install' to get started.
204
+ TNG v0.5.5 installed successfully!
205
+ Run 'bundle exec tng init' to get started.
204
206
  Use 'bundle exec tng --help' for usage information.
205
207
  rdoc_options: []
206
208
  require_paths: