-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Current Situation
The test file packages/shakacode_demo_common/spec/lib/generators/shakacode_demo_common/install/install_generator_spec.rb
currently tests the gitignore_contains_our_content?
logic by replicating the implementation within the test file itself. This requires maintaining duplicate constants and logic:
# In the spec file:
GITIGNORE_MARKERS = ['# Lefthook', '# Testing', '# Playwright'].freeze
def gitignore_contains_our_content?
return false unless File.exist?('.gitignore')
content = File.read('.gitignore')
GITIGNORE_MARKERS.all? { |marker| content.include?(marker) }
end
This duplicates the logic from InstallGenerator#gitignore_contains_our_content?
.
Problem
- Maintenance burden: Changes to the generator logic require updating both the implementation and test helper
- Risk of drift: The test logic could accidentally diverge from the actual implementation
- Not testing the actual method: We're testing a replica, not the real implementation
Suggested Solutions
Option A: Integration test approach
Set up proper Rails generator testing infrastructure to test the actual generator methods
Option B: Extract to testable module
Extract the gitignore logic to a separate module/class that can be easily tested and included in the generator
Option C: Keep current approach
Accept the duplication as reasonable for this simple use case (current state)
Priority
Low - Current tests are comprehensive and passing. This is a code organization improvement, not a bug fix.
Related
- PR Code quality improvements (#16) #33 (Code quality improvements for issue Code quality improvements: Extract constants, simplify validation, optimize Rails generators #16)
- File:
packages/shakacode_demo_common/spec/lib/generators/shakacode_demo_common/install/install_generator_spec.rb