Skip to content

Commit 7be49ce

Browse files
Update: Generator templates with production-tested best practices
- Set accessibility_enabled default to false for CI/CD safety - Add production safety guard in initializer - Set auto_run_checks to false by default - Change RSpec type to :accessibility - Improve error formatting in spec template - Update generator to create spec/accessibility/ directory - Update documentation URLs to GitHub Pages - Add Best Practices guide - Update CI guide with best practices Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 546a92f commit 7be49ce

10 files changed

Lines changed: 272 additions & 77 deletions

BOSS_MESSAGE_1.6.0.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Subject: Rails Accessibility Testing v1.6.0 Release - Fixed False Positives
2+
3+
Hi [Boss Name],
4+
5+
I've just released version 1.6.0 of the Rails Accessibility Testing gem, which addresses critical false positive issues that were affecting accuracy.
6+
7+
**Main Problem Solved:**
8+
The static file scanner was incorrectly flagging checkbox and radio button groups with dynamic IDs (common in Rails ERB templates) as missing labels or duplicate IDs, even when they were correctly implemented.
9+
10+
**Key Improvements:**
11+
✅ Fixed false positives for dynamic form elements (checkbox/radio groups in loops)
12+
✅ Enhanced ERB template processing to accurately handle Rails patterns
13+
✅ Improved label matching for dynamically generated form inputs
14+
✅ Better duplicate ID detection that excludes dynamic IDs
15+
✅ Fixed link accessibility detection to avoid false positives
16+
17+
**Impact:**
18+
This release significantly improves the scanner's accuracy for real-world Rails applications, reducing noise in reports and making the tool more reliable for teams. The changes ensure that correctly implemented accessibility features aren't flagged as errors.
19+
20+
The release is now available on RubyGems and has been tagged in GitHub.
21+
22+
Best regards,
23+
[Your Name]
24+
25+

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
- **Generator Templates Updated**: Improved default configuration based on production best practices
12+
- `accessibility.yml`: Changed `accessibility_enabled` default from `true` to `false` with detailed CI/CD documentation
13+
- `rails_a11y.rb`: Added production safety guard (`if defined?(RailsAccessibilityTesting)`) and set `auto_run_checks = false` by default
14+
- `all_pages_accessibility_spec.rb`: Changed RSpec type from `:system` to `:accessibility` and improved error formatting with unified helper method
15+
- Updated documentation URLs to correct GitHub Pages link
16+
- **Best Practices Guide**: Added comprehensive [Best Practices guide](GUIDES/best_practices.md) documenting production-tested configuration patterns
17+
18+
### Added
19+
- **[Best Practices Guide](GUIDES/best_practices.md)**: New guide documenting recommended configuration patterns based on real-world production usage, including CI/CD safety, production guards, and improved error formatting
20+
821
## [1.6.0] - 2024-12-XX
922

1023
### Added

GUIDES/continuous_integration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ Upload reports to:
280280
3. **Fail on violations** - Don't allow merging with issues
281281
4. **Report results** - Make status visible to team
282282
5. **Track trends** - Monitor violation counts over time
283+
6. **Disable by default** - Set `accessibility_enabled: false` in `config/accessibility.yml` to prevent accessibility tests from blocking other RSpec tests in CI. Enable manually when needed: `rspec spec/accessibility/all_pages_accessibility_spec.rb`
283284

284285
## Troubleshooting
285286

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ Complete documentation site with all guides, examples, and API reference. The do
447447
### Guides
448448

449449
- **[System Specs for Accessibility](GUIDES/system_specs_for_accessibility.md)** - ⭐ **Recommended approach** - Using system specs for reliable accessibility testing
450+
- **[Best Practices](GUIDES/best_practices.md)** - ⭐ **Configuration recommendations** - Production-tested configuration patterns
450451
- **[Getting Started](GUIDES/getting_started.md)** - Quick start guide
451452
- **[Continuous Integration](GUIDES/continuous_integration.md)** - CI/CD setup
452453
- **[Writing Accessible Views](GUIDES/writing_accessible_views_in_rails.md)** - Best practices

RELEASE_NOTES_1.6.0.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Release Notes for Version 1.6.0
2+
3+
## Summary
4+
5+
Version 1.6.0 addresses critical false positive issues in the static file scanner, particularly for Rails applications using ERB templates with dynamic form elements. This release significantly improves accuracy and reduces noise in accessibility testing reports.
6+
7+
## Key Improvements
8+
9+
### 🐛 **Fixed False Positives for Dynamic Form Elements**
10+
- **Problem Solved**: The scanner was incorrectly flagging checkbox and radio button groups with ERB-generated IDs (e.g., `collection_answers_<%= question.id %>_<%= option.id %>_`) as missing labels or duplicate IDs.
11+
- **Solution**: Enhanced ERB template processing to preserve dynamic ID structure instead of collapsing them, allowing accurate label-to-input matching.
12+
- **Impact**: Eliminates false positives for common Rails patterns like checkbox groups in loops, making the scanner more reliable for real-world applications.
13+
14+
### 🔍 **Enhanced ERB Template Handling**
15+
- Improved static analysis of ERB templates to correctly handle:
16+
- Dynamic IDs in form inputs
17+
- String interpolation in `label_tag` helpers
18+
- Raw HTML elements with ERB expressions in attributes
19+
- The scanner now preserves the structure of dynamic IDs (using `ERB_CONTENT` placeholders) rather than collapsing them, enabling accurate accessibility checks.
20+
21+
### **Improved Accessibility Rule Accuracy**
22+
- **Form Labels Check**: Now correctly matches labels to inputs with dynamic IDs from ERB templates
23+
- **Duplicate ID Detection**: Intelligently excludes dynamic IDs from duplicate checking (prevents false positives for checkbox/radio groups)
24+
- **Interactive Elements Check**: Fixed detection for links with `href="#"` - now only flags links that truly lack accessible names, avoiding false positives for valid anchor links
25+
26+
### 📝 **Better Test Integration**
27+
- Refactored RSpec test file to properly assert on errors (tests now fail when accessibility errors are found)
28+
- Extracted formatting logic into reusable helpers
29+
- Warnings are displayed but don't fail tests (only errors cause failures)
30+
31+
### 📚 **Documentation Updates**
32+
- Added comprehensive documentation on ERB template handling
33+
- Updated architecture docs with details on dynamic ID processing
34+
- Added examples for common Rails patterns
35+
36+
## Technical Details
37+
38+
The core improvement is in the `ErbExtractor` class, which now processes raw HTML elements with ERB in attributes before removing ERB tags. This preserves the structure of dynamic IDs like `collection_answers_ERB_CONTENT_ERB_CONTENT_` instead of collapsing them to just `collection_answers`, enabling accurate matching between inputs and labels.
39+
40+
## Impact
41+
42+
This release makes the static file scanner significantly more reliable for Rails applications, reducing false positives by correctly handling common ERB patterns. Teams can now trust the scanner results more, leading to faster development cycles and more accurate accessibility compliance reporting.
43+
44+

TEMPLATE_UPDATES_SUMMARY.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Generator Template Updates Summary
2+
3+
This document summarizes the updates made to the Rails Accessibility Testing generator templates based on production best practices from Margarita Barvinok's implementation.
4+
5+
## Overview
6+
7+
The generator templates have been updated to incorporate production-tested best practices that improve CI/CD safety, production deployment safety, and developer experience.
8+
9+
## Files Updated
10+
11+
### 1. `lib/generators/rails_a11y/install/templates/accessibility.yml.erb`
12+
13+
**Changes:**
14+
- ✅ Changed `accessibility_enabled` default from `true``false`
15+
- ✅ Added comprehensive documentation explaining CI/CD behavior
16+
- ✅ Updated documentation URL to correct GitHub Pages link
17+
- ✅ Added detailed comments explaining when to enable/disable
18+
19+
**Impact:**
20+
- Prevents accessibility test failures from blocking CI/CD pipelines
21+
- Allows other RSpec tests to pass even if accessibility tests fail
22+
- Gives developers explicit control over when to run accessibility checks
23+
24+
### 2. `lib/generators/rails_a11y/install/templates/initializer.rb.erb`
25+
26+
**Changes:**
27+
- ✅ Added production safety guard: `if defined?(RailsAccessibilityTesting)`
28+
- ✅ Changed `auto_run_checks` default from `true``false`
29+
- ✅ Updated documentation URL to correct GitHub Pages link
30+
- ✅ Added `@see` tag for better documentation
31+
32+
**Impact:**
33+
- Prevents errors if gem is not available in production
34+
- Allows gem to be excluded from production bundle
35+
- Gives developers explicit control over automatic checks
36+
- Safe deployment even if gem configuration is present
37+
38+
### 3. `lib/generators/rails_a11y/install/templates/all_pages_accessibility_spec.rb.erb`
39+
40+
**Changes:**
41+
- ✅ Changed RSpec type from `type: :system``type: :accessibility`
42+
- ✅ Improved error formatting with unified `format_issues_by_file` helper method
43+
- ✅ Changed test assertion to use `expect(errors).to be_empty` with formatted message
44+
- ✅ Better success message formatting
45+
46+
**Impact:**
47+
- Proper RSpec integration with accessibility helpers
48+
- Better test organization and filtering
49+
- Cleaner test output
50+
- Improved error messages with better structure
51+
52+
## New Documentation
53+
54+
### `GUIDES/best_practices.md`
55+
56+
Created comprehensive best practices guide covering:
57+
- Configuration best practices
58+
- CI/CD integration patterns
59+
- Development workflow recommendations
60+
- Production deployment safety
61+
- Real-world usage examples
62+
63+
### Updated Documentation
64+
65+
-`README.md` - Added link to Best Practices guide
66+
-`GUIDES/continuous_integration.md` - Added best practice about disabling by default
67+
-`CHANGELOG.md` - Documented template updates
68+
69+
## Key Improvements
70+
71+
### 1. CI/CD Safety
72+
- Accessibility tests disabled by default
73+
- Won't block other RSpec tests in CI
74+
- Manual invocation when needed
75+
76+
### 2. Production Safety
77+
- Conditional configuration prevents errors
78+
- Safe deployment even without gem
79+
- No production dependencies
80+
81+
### 3. Developer Control
82+
- Explicit control over automatic checks
83+
- Manual testing when needed
84+
- Better error formatting
85+
86+
### 4. Better UX
87+
- Improved error messages
88+
- Proper RSpec integration
89+
- Cleaner test output
90+
91+
## Migration Notes
92+
93+
For existing installations:
94+
95+
1. **Update `config/accessibility.yml`:**
96+
```yaml
97+
accessibility_enabled: false # Add this if not present
98+
```
99+
100+
2. **Update `config/initializers/rails_a11y.rb`:**
101+
```ruby
102+
if defined?(RailsAccessibilityTesting)
103+
RailsAccessibilityTesting.configure do |config|
104+
config.auto_run_checks = false # Change from true if needed
105+
end
106+
end
107+
```
108+
109+
3. **Update `spec/accessibility/all_pages_accessibility_spec.rb`:**
110+
- Change `type: :system` to `type: :accessibility`
111+
- Update error formatting to use unified helper method
112+
113+
## Credits
114+
115+
These improvements are based on production-tested configurations from:
116+
- **Margarita Barvinok** - Production configuration improvements
117+
- Real-world usage in Rails applications
118+
- Community feedback and testing
119+
120+
## Next Steps
121+
122+
1. Test generator with `rails generate rails_a11y:install`
123+
2. Verify templates generate correct configuration
124+
3. Update existing projects using migration notes above
125+
4. Share feedback and improvements
126+
127+
---
128+
129+
**Date:** February 2026
130+
**Version:** Unreleased (will be in next release)

lib/generators/rails_a11y/install/install_generator.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ def add_to_rails_helper
4343
end
4444

4545
def create_all_pages_spec
46-
spec_path = 'spec/system/all_pages_accessibility_spec.rb'
46+
# Create spec/accessibility directory if it doesn't exist
47+
spec_dir = 'spec/accessibility'
48+
FileUtils.mkdir_p(spec_dir) unless File.directory?(spec_dir)
49+
50+
spec_path = 'spec/accessibility/all_pages_accessibility_spec.rb'
4751

4852
if File.exist?(spec_path)
4953
say "⚠️ #{spec_path} already exists. Skipping creation.", :yellow
@@ -113,7 +117,7 @@ def show_instructions
113117
say "\n📋 Next Steps:", :yellow
114118
say ""
115119
say " 1. Run the accessibility tests:", :cyan
116-
say " bundle exec rspec spec/system/all_pages_accessibility_spec.rb"
120+
say " bundle exec rspec spec/accessibility/all_pages_accessibility_spec.rb"
117121
say ""
118122
say " 2. For static file scanning during development:", :cyan
119123
say " bin/dev # Starts web server + static accessibility scanner"

lib/generators/rails_a11y/install/templates/accessibility.yml.erb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Rails A11y Configuration
22
#
33
# This file configures accessibility checks for your Rails application.
4-
# See https://github.com/your-org/rails-a11y for full documentation.
4+
# See https://rayraycodes.github.io/rails-accessibility-testing/ for full documentation.
55

66
# Global enable/disable flag for all accessibility checks
77
# Set to false to completely disable all accessibility checks (manual and automatic)
88
# When false, check_comprehensive_accessibility and automatic checks will be skipped
9-
# Default: true
10-
accessibility_enabled: true
9+
# Default: false
10+
# (Set to false to allow other RSpec tests to pass in GitHub Actions CI even if accessibility tests fail.
11+
# When true, any failing accessibility tests will cause the entire CI pipeline to fail.)
12+
# Set to true to run accessibility checks manually: rspec spec/accessibility/all_pages_accessibility_spec.rb
13+
accessibility_enabled: false
1114

1215
# WCAG compliance level (A, AA, AAA)
1316
wcag_level: AA

0 commit comments

Comments
 (0)