Skip to content

Refactor install_generator_spec.rb test organization #34

@justin808

Description

@justin808

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions