conjure_shield 0.1.0

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.
@@ -0,0 +1,3 @@
1
+ module ConjureShield
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ require "conjure_shield/version"
2
+ require "conjure_shield/railtie"
3
+ require "conjure_shield/analyzer"
4
+ require "conjure_shield/test_generator"
5
+
6
+ module ConjureShield
7
+ class << self
8
+ attr_accessor :install_shown
9
+
10
+ def analyze(path)
11
+ ConjureShield::Analyzer.new(path).analyze
12
+ end
13
+
14
+ def generate_tests(code, suggestions)
15
+ TestGenerator.generate(code, suggestions)
16
+ end
17
+
18
+ def generate_integration_tests(controller, model)
19
+ TestGenerator.new(nil, nil).send(:generate_integration_test, {controller: controller, model: model})
20
+ end
21
+
22
+ def generate_api_tests(controller, model)
23
+ TestGenerator.new(nil, nil).send(:generate_api_test, {controller: controller, model: model})
24
+ end
25
+
26
+ def generate_feature_tests(controller, model)
27
+ TestGenerator.new(nil, nil).send(:generate_feature_test, {controller: controller, model: model})
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConjureShield
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+
7
+ def check_ruby_version
8
+ return if RUBY_VERSION >= "3.0.0"
9
+
10
+ say "Error: Ruby 3.0.0+ required. Current: #{RUBY_VERSION}", :red
11
+ exit 1
12
+ end
13
+
14
+ def check_rails_project
15
+ return if File.exist?(File.join(destination_root, "Gemfile"))
16
+
17
+ say "Error: No Gemfile found in #{destination_root}", :red
18
+ exit 1
19
+ end
20
+
21
+ def ensure_test_gems
22
+ gemfile = File.join(destination_root, "Gemfile")
23
+ content = File.read(gemfile)
24
+ needs_bundle = false
25
+
26
+ unless content.include?("rspec-rails")
27
+ say "Adding rspec-rails to Gemfile...", :blue
28
+ if content =~ /^group :development, :test do\b/
29
+ content.gsub!(/^group :development, :test do\b/) do |match|
30
+ match + "\n" + " gem \"rspec-rails\"\n"
31
+ end
32
+ needs_bundle = true
33
+ say " Added gem 'rspec-rails' to group :development, :test", :green
34
+ end
35
+ end
36
+
37
+ unless content.include?("rails-controller-testing")
38
+ say "Adding rails-controller-testing to Gemfile...", :blue
39
+ if content =~ /^group :development, :test do\b/
40
+ content.gsub!(/^group :development, :test do\b/) do |match|
41
+ match + "\n" + " gem \"rails-controller-testing\"\n"
42
+ end
43
+ needs_bundle = true
44
+ say " Added gem 'rails-controller-testing' to group :development, :test", :green
45
+ end
46
+ end
47
+
48
+ unless content.include?("shoulda-matchers")
49
+ say "Adding shoulda-matchers to Gemfile...", :blue
50
+ if content =~ /^group :development, :test do\b/
51
+ content.gsub!(/^group :development, :test do\b/) do |match|
52
+ match + "\n" + " gem \"shoulda-matchers\"\n"
53
+ end
54
+ needs_bundle = true
55
+ say " Added gem 'shoulda-matchers' to group :development, :test", :green
56
+ end
57
+ end
58
+
59
+ unless content.include?("factory_bot_rails")
60
+ say "Adding factory_bot_rails to Gemfile...", :blue
61
+ if content =~ /^group :development, :test do\b/
62
+ content.gsub!(/^group :development, :test do\b/) do |match|
63
+ match + "\n" + " gem \"factory_bot_rails\"\n"
64
+ end
65
+ needs_bundle = true
66
+ say " Added gem 'factory_bot_rails' to group :development, :test", :green
67
+ end
68
+ end
69
+
70
+ unless content.include?("capybara")
71
+ say "Adding capybara to Gemfile...", :blue
72
+ if content =~ /^group :development, :test do\b/
73
+ content.gsub!(/^group :development, :test do\b/) do |match|
74
+ match + "\n" + " gem \"capybara\"\n"
75
+ end
76
+ needs_bundle = true
77
+ say " Added gem 'capybara' to group :development, :test", :green
78
+ end
79
+ end
80
+
81
+ unless content.include?("database_cleaner-active_record")
82
+ say "Adding database_cleaner-active_record to Gemfile...", :blue
83
+ if content =~ /^group :development, :test do\b/
84
+ content.gsub!(/^group :development, :test do\b/) do |match|
85
+ match + "\n" + " gem \"database_cleaner-active_record\"\n"
86
+ end
87
+ needs_bundle = true
88
+ say " Added gem 'database_cleaner-active_record' to group :development, :test", :green
89
+ end
90
+ end
91
+
92
+ if needs_bundle
93
+ File.write(gemfile, content)
94
+ end
95
+ end
96
+
97
+ def run_bundle_install
98
+ say "Running bundle install...", :blue
99
+ Bundler.with_unbundled_env { system("bundle install") }
100
+ Bundler.reset!
101
+ end
102
+
103
+ def run_rspec_install
104
+ say "Running rails generate rspec:install...", :blue
105
+ system("rails generate rspec:install")
106
+ end
107
+
108
+ def configure_shoulda_matchers
109
+ spec_helper = File.join(destination_root, "spec", "rails_helper.rb")
110
+ return unless File.exist?(spec_helper)
111
+
112
+ content = File.read(spec_helper)
113
+ config_block = <<~RUBY
114
+
115
+ Shoulda::Matchers.configure do |config|
116
+ config.integrate do |with|
117
+ with.test_framework :rspec
118
+ with.library :rails
119
+ end
120
+ end
121
+ RUBY
122
+
123
+ unless content.include?("Shoulda::Matchers.configure")
124
+ content.gsub!(/^end\s*\z/, config_block + "\nend")
125
+ File.write(spec_helper, content)
126
+ say " Configured shoulda-matchers in spec/rails_helper.rb", :green
127
+ end
128
+ end
129
+
130
+ def replace_fixtures_with_comments
131
+ fixtures_dir = File.join(destination_root, "test", "fixtures")
132
+ return unless File.directory?(fixtures_dir)
133
+
134
+ Dir.glob(File.join(fixtures_dir, "*.yml")).each do |fixture_file|
135
+ content = File.read(fixture_file)
136
+ next if content.lines.first&.include?("Use FactoryBot")
137
+
138
+ model_name = File.basename(fixture_file, ".yml")
139
+ File.write(fixture_file, <<~YAML)
140
+ # Use FactoryBot instead of fixtures. See spec/factories/#{model_name}.rb
141
+ YAML
142
+ say " Replaced #{fixture_file} with factory comment", :green
143
+ end
144
+ end
145
+
146
+ def configure_database_cleaner
147
+ rspec_support_dir = File.join(destination_root, "spec", "support")
148
+ rspec_cleaner = File.join(rspec_support_dir, "database_cleaner.rb")
149
+
150
+ if File.exist?(File.join(destination_root, "spec", "rails_helper.rb")) && !File.exist?(rspec_cleaner)
151
+ FileUtils.mkdir_p(rspec_support_dir)
152
+ File.write(rspec_cleaner, <<~RUBY)
153
+ # frozen_string_literal: true
154
+
155
+ RSpec.configure do |config|
156
+ config.before(:suite) do
157
+ DatabaseCleaner.strategy = :transaction
158
+ DatabaseCleaner.clean_with(:truncation)
159
+ end
160
+
161
+ config.around(:each) do |example|
162
+ DatabaseCleaner.cleaning do
163
+ example.run
164
+ end
165
+ end
166
+ end
167
+ RUBY
168
+ say " Created spec/support/database_cleaner.rb", :green
169
+ end
170
+
171
+ test_helper = File.join(destination_root, "test", "test_helper.rb")
172
+ if File.exist?(test_helper)
173
+ content = File.read(test_helper)
174
+ cleaner_config = <<~RUBY
175
+
176
+ DatabaseCleaner.strategy = :transaction
177
+ DatabaseCleaner.clean_with(:truncation)
178
+
179
+ class ActiveSupport::TestCase
180
+ setup { DatabaseCleaner.start }
181
+ teardown { DatabaseCleaner.clean }
182
+ end
183
+ RUBY
184
+
185
+ unless content.include?("DatabaseCleaner")
186
+ content.gsub!(/^end\s*\z/, cleaner_config + "\nend")
187
+ File.write(test_helper, content)
188
+ say " Configured DatabaseCleaner in test/test_helper.rb", :green
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conjure_shield
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stéphane Ballet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: prism
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.29.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.29.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.50.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.50.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.20.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.20.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.24.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.24.0
83
+ description: Rails gem that integrates via generators to analyze codebases and generate
84
+ comprehensive test implementations using Prism, RuboCop, and RSpec
85
+ email:
86
+ - plombix@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - lib/conjure_shield.rb
92
+ - lib/conjure_shield/analyzer.rb
93
+ - lib/conjure_shield/railtie.rb
94
+ - lib/conjure_shield/tasks/conjure_shield_tasks.rake
95
+ - lib/conjure_shield/test_generator.rb
96
+ - lib/conjure_shield/version.rb
97
+ - lib/generators/conjure_shield/install_generator.rb
98
+ homepage: https://github.com/plombix-pro/ConjureShield
99
+ licenses:
100
+ - MIT
101
+ metadata:
102
+ homepage_uri: https://github.com/plombix-pro/ConjureShield
103
+ source_code_uri: https://github.com/plombix-pro/ConjureShield
104
+ bug_tracker_uri: https://github.com/plombix-pro/ConjureShield/issues
105
+ rubygems_mfa_required: 'true'
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 3.0.0
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.4.1
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Rails test suggestion and implementation generator
125
+ test_files: []