spec_scout 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.
- checksums.yaml +7 -0
- data/.idea/.gitignore +10 -0
- data/.idea/Projects.iml +41 -0
- data/.idea/copilot.data.migration.ask2agent.xml +6 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec_status +236 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +72 -0
- data/LICENSE +21 -0
- data/README.md +433 -0
- data/Rakefile +12 -0
- data/examples/README.md +321 -0
- data/examples/best_practices.md +401 -0
- data/examples/configurations/basic_config.rb +24 -0
- data/examples/configurations/ci_config.rb +35 -0
- data/examples/configurations/conservative_config.rb +32 -0
- data/examples/configurations/development_config.rb +37 -0
- data/examples/configurations/performance_focused_config.rb +38 -0
- data/examples/output_formatter_demo.rb +67 -0
- data/examples/sample_outputs/console_output_high_confidence.txt +27 -0
- data/examples/sample_outputs/console_output_medium_confidence.txt +27 -0
- data/examples/sample_outputs/console_output_no_action.txt +27 -0
- data/examples/sample_outputs/console_output_risk_detected.txt +27 -0
- data/examples/sample_outputs/json_output_high_confidence.json +108 -0
- data/examples/sample_outputs/json_output_no_action.json +108 -0
- data/examples/workflows/basic_workflow.md +159 -0
- data/examples/workflows/ci_integration.md +372 -0
- data/exe/spec_scout +7 -0
- data/lib/spec_scout/agent_result.rb +44 -0
- data/lib/spec_scout/agents/database_agent.rb +113 -0
- data/lib/spec_scout/agents/factory_agent.rb +179 -0
- data/lib/spec_scout/agents/intent_agent.rb +223 -0
- data/lib/spec_scout/agents/risk_agent.rb +290 -0
- data/lib/spec_scout/base_agent.rb +72 -0
- data/lib/spec_scout/cli.rb +158 -0
- data/lib/spec_scout/configuration.rb +162 -0
- data/lib/spec_scout/consensus_engine.rb +535 -0
- data/lib/spec_scout/enforcement_handler.rb +182 -0
- data/lib/spec_scout/output_formatter.rb +307 -0
- data/lib/spec_scout/profile_data.rb +37 -0
- data/lib/spec_scout/profile_normalizer.rb +238 -0
- data/lib/spec_scout/recommendation.rb +62 -0
- data/lib/spec_scout/safety_validator.rb +127 -0
- data/lib/spec_scout/spec_scout.rb +519 -0
- data/lib/spec_scout/testprof_integration.rb +206 -0
- data/lib/spec_scout/version.rb +5 -0
- data/lib/spec_scout.rb +43 -0
- metadata +166 -0
data/examples/README.md
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# SpecScout Examples
|
|
2
|
+
|
|
3
|
+
This directory contains comprehensive examples and documentation for using SpecScout effectively in your Ruby on Rails projects.
|
|
4
|
+
|
|
5
|
+
## Directory Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
examples/
|
|
9
|
+
├── configurations/ # Sample configuration files
|
|
10
|
+
├── sample_outputs/ # Example SpecScout outputs
|
|
11
|
+
├── workflows/ # Workflow documentation
|
|
12
|
+
├── best_practices.md # Comprehensive best practices guide
|
|
13
|
+
└── README.md # This file
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
1. **Choose a Configuration**
|
|
19
|
+
- [`basic_config.rb`](configurations/basic_config.rb) - Standard Rails application
|
|
20
|
+
- [`ci_config.rb`](configurations/ci_config.rb) - CI/CD integration
|
|
21
|
+
- [`conservative_config.rb`](configurations/conservative_config.rb) - Safety-focused
|
|
22
|
+
- [`development_config.rb`](configurations/development_config.rb) - Local development
|
|
23
|
+
- [`performance_focused_config.rb`](configurations/performance_focused_config.rb) - Maximum optimization
|
|
24
|
+
|
|
25
|
+
2. **Review Sample Outputs**
|
|
26
|
+
- [High Confidence Console Output](sample_outputs/console_output_high_confidence.txt)
|
|
27
|
+
- [Medium Confidence Console Output](sample_outputs/console_output_medium_confidence.txt)
|
|
28
|
+
- [No Action Console Output](sample_outputs/console_output_no_action.txt)
|
|
29
|
+
- [Risk Detected Console Output](sample_outputs/console_output_risk_detected.txt)
|
|
30
|
+
- [High Confidence JSON Output](sample_outputs/json_output_high_confidence.json)
|
|
31
|
+
- [No Action JSON Output](sample_outputs/json_output_no_action.json)
|
|
32
|
+
|
|
33
|
+
3. **Follow a Workflow**
|
|
34
|
+
- [Basic Workflow](workflows/basic_workflow.md) - Standard development process
|
|
35
|
+
- [CI Integration](workflows/ci_integration.md) - Continuous integration setup
|
|
36
|
+
|
|
37
|
+
4. **Apply Best Practices**
|
|
38
|
+
- [Best Practices Guide](best_practices.md) - Comprehensive usage guidelines
|
|
39
|
+
|
|
40
|
+
## Configuration Examples
|
|
41
|
+
|
|
42
|
+
### Basic Configuration
|
|
43
|
+
```ruby
|
|
44
|
+
# spec/spec_helper.rb
|
|
45
|
+
require 'spec_scout'
|
|
46
|
+
|
|
47
|
+
SpecScout.configure do |config|
|
|
48
|
+
config.enable = true
|
|
49
|
+
config.use_test_prof = true
|
|
50
|
+
config.enabled_agents = [:database, :factory, :intent, :risk]
|
|
51
|
+
config.output_format = :console
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### CI Configuration
|
|
56
|
+
```ruby
|
|
57
|
+
# For CI environments
|
|
58
|
+
SpecScout.configure do |config|
|
|
59
|
+
config.enable = true
|
|
60
|
+
config.use_test_prof = true
|
|
61
|
+
config.enforcement_mode = true
|
|
62
|
+
config.fail_on_high_confidence = true
|
|
63
|
+
config.enabled_agents = [:database, :factory]
|
|
64
|
+
config.output_format = :json
|
|
65
|
+
end
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage Examples
|
|
69
|
+
|
|
70
|
+
### Command Line
|
|
71
|
+
```bash
|
|
72
|
+
# Basic analysis
|
|
73
|
+
spec_scout
|
|
74
|
+
|
|
75
|
+
# Specific spec file
|
|
76
|
+
spec_scout spec/models/user_spec.rb
|
|
77
|
+
|
|
78
|
+
# JSON output for CI
|
|
79
|
+
spec_scout --output json
|
|
80
|
+
|
|
81
|
+
# Enforcement mode
|
|
82
|
+
spec_scout --enforce --fail-on-high-confidence
|
|
83
|
+
|
|
84
|
+
# Disable specific agents
|
|
85
|
+
spec_scout --disable-agent risk
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Programmatic Usage
|
|
89
|
+
```ruby
|
|
90
|
+
# Create SpecScout instance
|
|
91
|
+
scout = SpecScout::SpecScout.new
|
|
92
|
+
|
|
93
|
+
# Analyze specific spec
|
|
94
|
+
result = scout.analyze('spec/models/user_spec.rb')
|
|
95
|
+
|
|
96
|
+
# Process results
|
|
97
|
+
if result[:recommendation]
|
|
98
|
+
puts "Action: #{result[:recommendation].action}"
|
|
99
|
+
puts "Confidence: #{result[:recommendation].confidence}"
|
|
100
|
+
puts "Explanation: #{result[:recommendation].explanation.join(', ')}"
|
|
101
|
+
end
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Sample Outputs Explained
|
|
105
|
+
|
|
106
|
+
### High Confidence Recommendation
|
|
107
|
+
When SpecScout finds a clear optimization opportunity:
|
|
108
|
+
- Multiple agents agree on the recommendation
|
|
109
|
+
- No risk factors detected
|
|
110
|
+
- Clear performance benefit available
|
|
111
|
+
- Safe to apply immediately
|
|
112
|
+
|
|
113
|
+
### Medium Confidence Recommendation
|
|
114
|
+
When SpecScout finds a potential optimization:
|
|
115
|
+
- Mixed signals from agents
|
|
116
|
+
- Some uncertainty in analysis
|
|
117
|
+
- Requires careful testing
|
|
118
|
+
- Manual review recommended
|
|
119
|
+
|
|
120
|
+
### No Action Recommendation
|
|
121
|
+
When SpecScout determines current implementation is optimal:
|
|
122
|
+
- Test requires current approach
|
|
123
|
+
- No performance benefit available
|
|
124
|
+
- Optimization would break functionality
|
|
125
|
+
- Current strategy is appropriate
|
|
126
|
+
|
|
127
|
+
### Risk Detected
|
|
128
|
+
When SpecScout identifies potential issues:
|
|
129
|
+
- Callbacks or side effects detected
|
|
130
|
+
- Optimization could break functionality
|
|
131
|
+
- Manual investigation required
|
|
132
|
+
- Conservative approach recommended
|
|
133
|
+
|
|
134
|
+
## Agent Behavior Examples
|
|
135
|
+
|
|
136
|
+
### Database Agent
|
|
137
|
+
```ruby
|
|
138
|
+
# Recommends build_stubbed when:
|
|
139
|
+
let(:user) { create(:user) } # Creates DB record unnecessarily
|
|
140
|
+
|
|
141
|
+
it "validates email format" do
|
|
142
|
+
user.email = "invalid"
|
|
143
|
+
expect(user).not_to be_valid # Only needs validation, not persistence
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Recommends keeping create when:
|
|
147
|
+
let(:user) { create(:user) }
|
|
148
|
+
|
|
149
|
+
it "can be found by email" do
|
|
150
|
+
expect(User.find_by(email: user.email)).to eq(user) # Requires DB persistence
|
|
151
|
+
end
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Factory Agent
|
|
155
|
+
```ruby
|
|
156
|
+
# Recommends strategy change when:
|
|
157
|
+
let(:user) { create(:user, posts: create_list(:post, 3)) } # Unnecessary persistence
|
|
158
|
+
|
|
159
|
+
# Recommends keeping create when:
|
|
160
|
+
let(:user) { create(:user) }
|
|
161
|
+
|
|
162
|
+
after { user.posts.reload } # Requires DB persistence for reload
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Intent Agent
|
|
166
|
+
```ruby
|
|
167
|
+
# Identifies unit test behavior:
|
|
168
|
+
# spec/models/user_spec.rb
|
|
169
|
+
describe User do
|
|
170
|
+
it "validates presence of email" do # Pure model validation
|
|
171
|
+
user = build(:user, email: nil)
|
|
172
|
+
expect(user).not_to be_valid
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Identifies integration test behavior:
|
|
177
|
+
# spec/controllers/users_controller_spec.rb
|
|
178
|
+
describe UsersController do
|
|
179
|
+
it "creates user and sends email" do # Multiple system interactions
|
|
180
|
+
post :create, params: { user: attributes }
|
|
181
|
+
expect(ActionMailer::Base.deliveries).not_to be_empty
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Risk Agent
|
|
187
|
+
```ruby
|
|
188
|
+
# Flags risk when callbacks are present:
|
|
189
|
+
class User < ApplicationRecord
|
|
190
|
+
after_commit :send_welcome_email, on: :create
|
|
191
|
+
after_create :update_statistics
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Safe optimization:
|
|
195
|
+
class User < ApplicationRecord
|
|
196
|
+
validates :email, presence: true # No callbacks, safe to use build_stubbed
|
|
197
|
+
end
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Integration Examples
|
|
201
|
+
|
|
202
|
+
### RSpec Integration
|
|
203
|
+
```ruby
|
|
204
|
+
# spec/spec_helper.rb
|
|
205
|
+
RSpec.configure do |config|
|
|
206
|
+
config.after(:suite) do
|
|
207
|
+
if ENV['SPEC_SCOUT_ANALYZE']
|
|
208
|
+
scout = SpecScout::SpecScout.new
|
|
209
|
+
results = scout.analyze
|
|
210
|
+
|
|
211
|
+
if results[:recommendation]&.confidence == :high
|
|
212
|
+
puts "\n🚀 SpecScout found high-confidence optimizations!"
|
|
213
|
+
puts "Run 'bundle exec spec_scout' for details."
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Rails Integration
|
|
221
|
+
```ruby
|
|
222
|
+
# config/environments/test.rb
|
|
223
|
+
Rails.application.configure do
|
|
224
|
+
# SpecScout configuration for test environment
|
|
225
|
+
config.after_initialize do
|
|
226
|
+
SpecScout.configure do |scout_config|
|
|
227
|
+
scout_config.enable = true
|
|
228
|
+
scout_config.use_test_prof = true
|
|
229
|
+
scout_config.enabled_agents = [:database, :factory]
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Rake Task Integration
|
|
236
|
+
```ruby
|
|
237
|
+
# lib/tasks/spec_scout.rake
|
|
238
|
+
namespace :spec_scout do
|
|
239
|
+
desc "Analyze test suite with SpecScout"
|
|
240
|
+
task analyze: :environment do
|
|
241
|
+
require 'spec_scout'
|
|
242
|
+
|
|
243
|
+
scout = SpecScout::SpecScout.new
|
|
244
|
+
result = scout.analyze
|
|
245
|
+
|
|
246
|
+
if result[:recommendation]
|
|
247
|
+
puts "SpecScout Analysis Complete"
|
|
248
|
+
puts "Confidence: #{result[:recommendation].confidence}"
|
|
249
|
+
puts "Action: #{result[:recommendation].action}"
|
|
250
|
+
else
|
|
251
|
+
puts "No recommendations found"
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
desc "Generate SpecScout report"
|
|
256
|
+
task report: :environment do
|
|
257
|
+
require 'spec_scout'
|
|
258
|
+
|
|
259
|
+
SpecScout.configure { |c| c.output_format = :json }
|
|
260
|
+
scout = SpecScout::SpecScout.new
|
|
261
|
+
result = scout.analyze
|
|
262
|
+
|
|
263
|
+
File.write('spec_scout_report.json', JSON.pretty_generate(result))
|
|
264
|
+
puts "Report saved to spec_scout_report.json"
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Troubleshooting Examples
|
|
270
|
+
|
|
271
|
+
### Debug Configuration
|
|
272
|
+
```ruby
|
|
273
|
+
# Enable debug mode
|
|
274
|
+
ENV['SPEC_SCOUT_DEBUG'] = '1'
|
|
275
|
+
|
|
276
|
+
SpecScout.configure do |config|
|
|
277
|
+
config.enable = true
|
|
278
|
+
config.use_test_prof = true
|
|
279
|
+
|
|
280
|
+
# Log configuration for debugging
|
|
281
|
+
puts "SpecScout Configuration: #{config.to_h}"
|
|
282
|
+
end
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### TestProf Integration Issues
|
|
286
|
+
```bash
|
|
287
|
+
# Test TestProf directly
|
|
288
|
+
bundle exec rspec --profile
|
|
289
|
+
|
|
290
|
+
# Test SpecScout with minimal config
|
|
291
|
+
SPEC_SCOUT_DEBUG=1 bundle exec spec_scout --no-testprof
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Performance Debugging
|
|
295
|
+
```ruby
|
|
296
|
+
# Measure SpecScout overhead
|
|
297
|
+
start_time = Time.now
|
|
298
|
+
scout = SpecScout::SpecScout.new
|
|
299
|
+
result = scout.analyze('spec/models/user_spec.rb')
|
|
300
|
+
end_time = Time.now
|
|
301
|
+
|
|
302
|
+
puts "SpecScout analysis took: #{(end_time - start_time) * 1000}ms"
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Contributing Examples
|
|
306
|
+
|
|
307
|
+
When contributing to SpecScout, please include:
|
|
308
|
+
|
|
309
|
+
1. **Configuration examples** for new features
|
|
310
|
+
2. **Sample outputs** showing new behavior
|
|
311
|
+
3. **Workflow documentation** for new use cases
|
|
312
|
+
4. **Best practices** for new functionality
|
|
313
|
+
|
|
314
|
+
See the main [Contributing Guide](../README.md#contributing) for more details.
|
|
315
|
+
|
|
316
|
+
## Additional Resources
|
|
317
|
+
|
|
318
|
+
- [Main README](../README.md) - Complete SpecScout documentation
|
|
319
|
+
- [TestProf Documentation](https://test-prof.evilmartians.io/) - Underlying profiling tool
|
|
320
|
+
- [FactoryBot Documentation](https://github.com/thoughtbot/factory_bot) - Factory optimization context
|
|
321
|
+
- [RSpec Documentation](https://rspec.info/) - Testing framework integration
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
# SpecScout Best Practices
|
|
2
|
+
|
|
3
|
+
This document outlines best practices for using SpecScout effectively in your Ruby on Rails projects.
|
|
4
|
+
|
|
5
|
+
## Configuration Best Practices
|
|
6
|
+
|
|
7
|
+
### 1. Environment-Specific Configuration
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
# config/spec_scout.rb
|
|
11
|
+
SpecScout.configure do |config|
|
|
12
|
+
config.enable = true
|
|
13
|
+
config.use_test_prof = true
|
|
14
|
+
|
|
15
|
+
case Rails.env
|
|
16
|
+
when 'development'
|
|
17
|
+
# Comprehensive analysis for development
|
|
18
|
+
config.enabled_agents = [:database, :factory, :intent, :risk]
|
|
19
|
+
config.output_format = :console
|
|
20
|
+
config.enforcement_mode = false
|
|
21
|
+
|
|
22
|
+
when 'test'
|
|
23
|
+
# Focus on performance in test environment
|
|
24
|
+
config.enabled_agents = [:database, :factory]
|
|
25
|
+
config.output_format = :json
|
|
26
|
+
config.enforcement_mode = false
|
|
27
|
+
|
|
28
|
+
when 'ci', 'production'
|
|
29
|
+
# Conservative approach for CI/production
|
|
30
|
+
config.enabled_agents = [:database, :factory, :risk]
|
|
31
|
+
config.output_format = :json
|
|
32
|
+
config.enforcement_mode = ENV['SPEC_SCOUT_ENFORCE'] == 'true'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. Agent Selection Guidelines
|
|
38
|
+
|
|
39
|
+
**All Agents (Development)**
|
|
40
|
+
- Use for comprehensive analysis
|
|
41
|
+
- Good for learning and exploration
|
|
42
|
+
- Provides maximum insight
|
|
43
|
+
|
|
44
|
+
**Database + Factory (Performance Focus)**
|
|
45
|
+
- Best for CI environments
|
|
46
|
+
- Focuses on high-impact optimizations
|
|
47
|
+
- Reduces analysis time
|
|
48
|
+
|
|
49
|
+
**Database + Factory + Risk (Conservative)**
|
|
50
|
+
- Good for production-critical applications
|
|
51
|
+
- Balances performance with safety
|
|
52
|
+
- Recommended for teams new to SpecScout
|
|
53
|
+
|
|
54
|
+
**Custom Combinations**
|
|
55
|
+
```ruby
|
|
56
|
+
# For legacy applications with complex callbacks
|
|
57
|
+
config.enabled_agents = [:database, :risk]
|
|
58
|
+
|
|
59
|
+
# For new applications with clean architecture
|
|
60
|
+
config.enabled_agents = [:database, :factory, :intent]
|
|
61
|
+
|
|
62
|
+
# For performance-critical applications
|
|
63
|
+
config.enabled_agents = [:database, :factory]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Applying Recommendations
|
|
67
|
+
|
|
68
|
+
### Confidence Level Guidelines
|
|
69
|
+
|
|
70
|
+
#### High Confidence (✔)
|
|
71
|
+
- **Action**: Apply immediately
|
|
72
|
+
- **Verification**: Run affected tests
|
|
73
|
+
- **Risk**: Very low
|
|
74
|
+
- **Example**: Unit tests with unnecessary database persistence
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
# Safe to change immediately
|
|
78
|
+
# Before
|
|
79
|
+
let(:user) { create(:user) }
|
|
80
|
+
|
|
81
|
+
# After
|
|
82
|
+
let(:user) { build_stubbed(:user) }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### Medium Confidence (⚠)
|
|
86
|
+
- **Action**: Apply with testing
|
|
87
|
+
- **Verification**: Run full test suite
|
|
88
|
+
- **Risk**: Low to medium
|
|
89
|
+
- **Example**: Controller tests with mixed signals
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
# Test thoroughly after change
|
|
93
|
+
# Before
|
|
94
|
+
let(:user) { create(:user) }
|
|
95
|
+
|
|
96
|
+
# After (test carefully)
|
|
97
|
+
let(:user) { build_stubbed(:user) }
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Low Confidence (?)
|
|
101
|
+
- **Action**: Manual investigation required
|
|
102
|
+
- **Verification**: Deep analysis needed
|
|
103
|
+
- **Risk**: Medium to high
|
|
104
|
+
- **Example**: Complex integration tests with callbacks
|
|
105
|
+
|
|
106
|
+
### Batch Application Strategy
|
|
107
|
+
|
|
108
|
+
1. **Start Small**
|
|
109
|
+
```bash
|
|
110
|
+
# Apply to one spec file at a time
|
|
111
|
+
bundle exec spec_scout spec/models/user_spec.rb
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
2. **Group by Confidence**
|
|
115
|
+
```bash
|
|
116
|
+
# Apply all high confidence recommendations first
|
|
117
|
+
# Then medium confidence
|
|
118
|
+
# Finally low confidence (with caution)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
3. **Verify Incrementally**
|
|
122
|
+
```bash
|
|
123
|
+
# After each change
|
|
124
|
+
bundle exec rspec spec/models/user_spec.rb
|
|
125
|
+
|
|
126
|
+
# After batch of changes
|
|
127
|
+
bundle exec rspec
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Performance Optimization Workflow
|
|
131
|
+
|
|
132
|
+
### 1. Baseline Measurement
|
|
133
|
+
```bash
|
|
134
|
+
# Measure current performance
|
|
135
|
+
bundle exec rspec --profile > baseline_performance.txt
|
|
136
|
+
|
|
137
|
+
# Run SpecScout analysis
|
|
138
|
+
bundle exec spec_scout --output json > baseline_analysis.json
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 2. Apply Optimizations
|
|
142
|
+
```bash
|
|
143
|
+
# Apply high confidence recommendations
|
|
144
|
+
# Document changes in commit messages
|
|
145
|
+
git commit -m "Apply SpecScout recommendations: replace create with build_stubbed in user specs"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 3. Measure Improvements
|
|
149
|
+
```bash
|
|
150
|
+
# Measure new performance
|
|
151
|
+
bundle exec rspec --profile > optimized_performance.txt
|
|
152
|
+
|
|
153
|
+
# Compare results
|
|
154
|
+
diff baseline_performance.txt optimized_performance.txt
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 4. Track Over Time
|
|
158
|
+
```ruby
|
|
159
|
+
# Create performance tracking script
|
|
160
|
+
# scripts/track_performance.rb
|
|
161
|
+
|
|
162
|
+
require 'json'
|
|
163
|
+
require 'time'
|
|
164
|
+
|
|
165
|
+
results = {
|
|
166
|
+
timestamp: Time.now.iso8601,
|
|
167
|
+
test_count: `bundle exec rspec --dry-run | grep examples`.split.first.to_i,
|
|
168
|
+
total_time: `bundle exec rspec --profile | grep "Finished in"`.match(/[\d.]+/).to_s.to_f,
|
|
169
|
+
spec_scout_recommendations: JSON.parse(File.read('spec_scout_results.json'))
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
File.write("performance_history/#{Date.today}.json", JSON.pretty_generate(results))
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Common Patterns and Solutions
|
|
176
|
+
|
|
177
|
+
### 1. Factory Strategy Optimization
|
|
178
|
+
|
|
179
|
+
**Pattern**: Unnecessary `create` usage in unit tests
|
|
180
|
+
```ruby
|
|
181
|
+
# Before (slow)
|
|
182
|
+
describe User do
|
|
183
|
+
let(:user) { create(:user) }
|
|
184
|
+
|
|
185
|
+
it "validates email format" do
|
|
186
|
+
user.email = "invalid"
|
|
187
|
+
expect(user).not_to be_valid
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# After (fast)
|
|
192
|
+
describe User do
|
|
193
|
+
let(:user) { build_stubbed(:user) }
|
|
194
|
+
|
|
195
|
+
it "validates email format" do
|
|
196
|
+
user.email = "invalid"
|
|
197
|
+
expect(user).not_to be_valid
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 2. Association Handling
|
|
203
|
+
|
|
204
|
+
**Pattern**: Unnecessary association persistence
|
|
205
|
+
```ruby
|
|
206
|
+
# Before (creates both user and organization in DB)
|
|
207
|
+
let(:user) { create(:user, organization: create(:organization)) }
|
|
208
|
+
|
|
209
|
+
# After (only creates user in DB)
|
|
210
|
+
let(:user) { create(:user, organization: build_stubbed(:organization)) }
|
|
211
|
+
|
|
212
|
+
# Or even better for unit tests
|
|
213
|
+
let(:user) { build_stubbed(:user, organization: build_stubbed(:organization)) }
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### 3. Callback-Safe Optimization
|
|
217
|
+
|
|
218
|
+
**Pattern**: Tests with after_commit callbacks
|
|
219
|
+
```ruby
|
|
220
|
+
# When SpecScout detects risk, investigate callbacks
|
|
221
|
+
class User < ApplicationRecord
|
|
222
|
+
after_commit :send_welcome_email, on: :create
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Option 1: Test callback separately
|
|
226
|
+
describe User do
|
|
227
|
+
let(:user) { build_stubbed(:user) } # Safe for validation tests
|
|
228
|
+
|
|
229
|
+
it "validates email" do
|
|
230
|
+
user.email = "invalid"
|
|
231
|
+
expect(user).not_to be_valid
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
describe "User callbacks" do
|
|
236
|
+
it "sends welcome email after creation" do
|
|
237
|
+
expect { create(:user) }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Option 2: Stub callbacks when not testing them
|
|
242
|
+
before { allow_any_instance_of(User).to receive(:send_welcome_email) }
|
|
243
|
+
let(:user) { create(:user) } # Now safe to optimize
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### 4. Integration Test Boundaries
|
|
247
|
+
|
|
248
|
+
**Pattern**: Controller tests that cross boundaries
|
|
249
|
+
```ruby
|
|
250
|
+
# Before (integration-style controller test)
|
|
251
|
+
describe UsersController do
|
|
252
|
+
let(:user) { create(:user) }
|
|
253
|
+
|
|
254
|
+
it "shows user profile" do
|
|
255
|
+
get :show, params: { id: user.id }
|
|
256
|
+
expect(response).to be_successful
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# After (true unit-style controller test)
|
|
261
|
+
describe UsersController do
|
|
262
|
+
let(:user) { build_stubbed(:user) }
|
|
263
|
+
|
|
264
|
+
before { allow(User).to receive(:find).and_return(user) }
|
|
265
|
+
|
|
266
|
+
it "shows user profile" do
|
|
267
|
+
get :show, params: { id: user.id }
|
|
268
|
+
expect(response).to be_successful
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Team Adoption Strategies
|
|
274
|
+
|
|
275
|
+
### 1. Gradual Introduction
|
|
276
|
+
|
|
277
|
+
**Week 1-2**: Analysis only
|
|
278
|
+
- Run SpecScout on existing test suite
|
|
279
|
+
- Share results with team
|
|
280
|
+
- Identify high-impact opportunities
|
|
281
|
+
|
|
282
|
+
**Week 3-4**: High confidence changes
|
|
283
|
+
- Apply only high confidence recommendations
|
|
284
|
+
- Measure performance improvements
|
|
285
|
+
- Build team confidence
|
|
286
|
+
|
|
287
|
+
**Week 5-6**: Medium confidence changes
|
|
288
|
+
- Apply medium confidence recommendations carefully
|
|
289
|
+
- Develop team expertise in evaluation
|
|
290
|
+
- Document lessons learned
|
|
291
|
+
|
|
292
|
+
**Week 7+**: Full adoption
|
|
293
|
+
- Integrate into CI pipeline
|
|
294
|
+
- Enable enforcement mode gradually
|
|
295
|
+
- Establish team practices
|
|
296
|
+
|
|
297
|
+
### 2. Training and Documentation
|
|
298
|
+
|
|
299
|
+
**Team Training Session**
|
|
300
|
+
1. SpecScout overview and benefits
|
|
301
|
+
2. Understanding agent recommendations
|
|
302
|
+
3. Hands-on practice with sample specs
|
|
303
|
+
4. Q&A and troubleshooting
|
|
304
|
+
|
|
305
|
+
**Documentation**
|
|
306
|
+
- Internal wiki with team-specific guidelines
|
|
307
|
+
- Examples from your codebase
|
|
308
|
+
- Common patterns and solutions
|
|
309
|
+
- Troubleshooting guide
|
|
310
|
+
|
|
311
|
+
### 3. Code Review Integration
|
|
312
|
+
|
|
313
|
+
**Pull Request Template**
|
|
314
|
+
```markdown
|
|
315
|
+
## SpecScout Analysis
|
|
316
|
+
|
|
317
|
+
- [ ] Ran SpecScout on affected spec files
|
|
318
|
+
- [ ] Applied high confidence recommendations
|
|
319
|
+
- [ ] Verified all tests still pass
|
|
320
|
+
- [ ] Documented any skipped recommendations and reasons
|
|
321
|
+
|
|
322
|
+
**SpecScout Results:**
|
|
323
|
+
<!-- Paste relevant SpecScout output here -->
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Monitoring and Maintenance
|
|
327
|
+
|
|
328
|
+
### 1. Performance Metrics
|
|
329
|
+
|
|
330
|
+
Track these metrics over time:
|
|
331
|
+
- Total test suite runtime
|
|
332
|
+
- Number of database queries in tests
|
|
333
|
+
- Factory usage patterns
|
|
334
|
+
- SpecScout recommendation acceptance rate
|
|
335
|
+
|
|
336
|
+
### 2. Regular Reviews
|
|
337
|
+
|
|
338
|
+
**Monthly Reviews**
|
|
339
|
+
- Analyze performance trends
|
|
340
|
+
- Review skipped recommendations
|
|
341
|
+
- Update configuration as needed
|
|
342
|
+
- Share success stories with team
|
|
343
|
+
|
|
344
|
+
**Quarterly Reviews**
|
|
345
|
+
- Evaluate SpecScout effectiveness
|
|
346
|
+
- Consider new agent configurations
|
|
347
|
+
- Update team practices
|
|
348
|
+
- Plan further optimizations
|
|
349
|
+
|
|
350
|
+
### 3. Continuous Improvement
|
|
351
|
+
|
|
352
|
+
**Feedback Loop**
|
|
353
|
+
1. Apply recommendations
|
|
354
|
+
2. Measure impact
|
|
355
|
+
3. Document results
|
|
356
|
+
4. Refine approach
|
|
357
|
+
5. Share learnings
|
|
358
|
+
|
|
359
|
+
**Configuration Tuning**
|
|
360
|
+
- Adjust agent selection based on results
|
|
361
|
+
- Fine-tune confidence thresholds
|
|
362
|
+
- Customize for project-specific patterns
|
|
363
|
+
- Update as codebase evolves
|
|
364
|
+
|
|
365
|
+
## Troubleshooting Common Issues
|
|
366
|
+
|
|
367
|
+
### 1. False Positives
|
|
368
|
+
|
|
369
|
+
**Problem**: SpecScout recommends changes that break tests
|
|
370
|
+
**Solution**:
|
|
371
|
+
- Enable Risk Agent
|
|
372
|
+
- Review test intent carefully
|
|
373
|
+
- Consider callback dependencies
|
|
374
|
+
- Use conservative configuration
|
|
375
|
+
|
|
376
|
+
### 2. Performance Regression
|
|
377
|
+
|
|
378
|
+
**Problem**: Optimizations make tests slower
|
|
379
|
+
**Solution**:
|
|
380
|
+
- Verify database setup in tests
|
|
381
|
+
- Check for missing test data
|
|
382
|
+
- Review factory definitions
|
|
383
|
+
- Consider test isolation issues
|
|
384
|
+
|
|
385
|
+
### 3. Team Resistance
|
|
386
|
+
|
|
387
|
+
**Problem**: Team reluctant to adopt SpecScout
|
|
388
|
+
**Solution**:
|
|
389
|
+
- Start with voluntary adoption
|
|
390
|
+
- Share success metrics
|
|
391
|
+
- Provide training and support
|
|
392
|
+
- Address concerns directly
|
|
393
|
+
|
|
394
|
+
### 4. CI Integration Issues
|
|
395
|
+
|
|
396
|
+
**Problem**: SpecScout fails in CI but works locally
|
|
397
|
+
**Solution**:
|
|
398
|
+
- Check CI environment configuration
|
|
399
|
+
- Verify TestProf setup in CI
|
|
400
|
+
- Review database setup
|
|
401
|
+
- Enable debug mode for troubleshooting
|