rails_accessibility_testing 1.5.5 → 1.5.6
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 +4 -4
- data/ARCHITECTURE.md +336 -71
- data/CHANGELOG.md +17 -0
- data/GUIDES/getting_started.md +46 -177
- data/README.md +4 -0
- data/docs_site/_config.yml +3 -0
- data/docs_site/_layouts/default.html +95 -588
- data/docs_site/architecture.md +98 -469
- data/docs_site/ci_integration.md +87 -32
- data/docs_site/configuration.md +119 -51
- data/docs_site/contributing.md +166 -6
- data/docs_site/favicon.svg +31 -0
- data/docs_site/getting_started.md +188 -66
- data/docs_site/index.md +136 -21
- data/lib/generators/rails_a11y/install/templates/accessibility.yml.erb +16 -0
- data/lib/rails_accessibility_testing/accessibility_helper.rb +86 -16
- data/lib/rails_accessibility_testing/checks/base_check.rb +32 -5
- data/lib/rails_accessibility_testing/checks/interactive_elements_check.rb +23 -0
- data/lib/rails_accessibility_testing/config/yaml_loader.rb +9 -0
- data/lib/rails_accessibility_testing/error_message_builder.rb +28 -0
- data/lib/rails_accessibility_testing/rspec_integration.rb +25 -1
- data/lib/rails_accessibility_testing/version.rb +1 -1
- metadata +3 -2
|
@@ -24,13 +24,11 @@ group :development, :test do
|
|
|
24
24
|
gem 'axe-core-capybara', '~> 4.0'
|
|
25
25
|
gem 'capybara', '~> 3.40'
|
|
26
26
|
gem 'selenium-webdriver', '~> 4.0'
|
|
27
|
-
gem 'webdrivers', '~> 5.0' # Optional but recommended
|
|
27
|
+
gem 'webdrivers', '~> 5.0' # Optional but recommended
|
|
28
28
|
end
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
**Important:**
|
|
32
|
-
- You must explicitly add `selenium-webdriver` to your Gemfile. It's not automatically included as a dependency.
|
|
33
|
-
- **RSpec Rails is required** - The generator creates system specs that require `rspec-rails`. If you're using Minitest, you'll need to manually create your accessibility tests.
|
|
31
|
+
**Important:** You must explicitly add `selenium-webdriver` to your Gemfile. It's not automatically included as a dependency.
|
|
34
32
|
|
|
35
33
|
Then run:
|
|
36
34
|
|
|
@@ -51,14 +49,81 @@ This creates:
|
|
|
51
49
|
- `config/accessibility.yml` - Check settings
|
|
52
50
|
- `spec/system/all_pages_accessibility_spec.rb` - Comprehensive spec that tests all GET routes
|
|
53
51
|
- Updates `spec/rails_helper.rb` (if using RSpec)
|
|
54
|
-
|
|
55
|
-
**Note:** If you already have system tests set up in your Rails application, you can skip to Step 3. If you need help configuring Capybara or installing Chrome, see the [Troubleshooting section](#troubleshooting) below.
|
|
52
|
+
- Updates `Procfile.dev` - Adds static accessibility scanner
|
|
56
53
|
|
|
57
54
|
### Step 3: Run Your Tests
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
#### Option A: Static File Scanner (Recommended for Development)
|
|
57
|
+
|
|
58
|
+
The generator automatically adds a static accessibility scanner to your `Procfile.dev`:
|
|
59
|
+
|
|
60
|
+
```procfile
|
|
61
|
+
web: bin/rails server
|
|
62
|
+
css: bin/rails dartsass:watch
|
|
63
|
+
a11y: bundle exec a11y_static_scanner
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Then run:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bin/dev
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This will:
|
|
73
|
+
- Start your Rails server
|
|
74
|
+
- Watch for CSS changes
|
|
75
|
+
- **Continuously scan view files for accessibility issues** - Only scans files that have changed since last scan
|
|
76
|
+
- Shows errors with exact file locations and line numbers
|
|
77
|
+
|
|
78
|
+
**How it works:**
|
|
79
|
+
- Scans all files on startup
|
|
80
|
+
- Only re-scans files that have been modified
|
|
81
|
+
- Watches for file changes and re-scans automatically
|
|
82
|
+
- No browser needed - scans ERB templates directly
|
|
83
|
+
|
|
84
|
+
**Configuration** (in `config/accessibility.yml`):
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
static_scanner:
|
|
88
|
+
scan_changed_only: true # Only scan changed files
|
|
89
|
+
check_interval: 3 # Seconds between file checks
|
|
90
|
+
full_scan_on_startup: true # Full scan on startup
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Option B: Run Tests Manually
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
bundle exec rspec spec/system/
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Accessibility checks run automatically on every system test that visits a page.
|
|
100
|
+
|
|
101
|
+
#### Option C: All Pages Spec
|
|
102
|
+
|
|
103
|
+
Run the comprehensive spec that tests all GET routes:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
bundle exec rspec spec/system/all_pages_accessibility_spec.rb
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Your First Accessibility Check
|
|
110
|
+
|
|
111
|
+
Create a simple system spec:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
# spec/system/home_spec.rb
|
|
115
|
+
RSpec.describe "Home Page", type: :system do
|
|
116
|
+
it "displays the welcome message" do
|
|
117
|
+
visit root_path
|
|
118
|
+
expect(page).to have_content("Welcome")
|
|
119
|
+
# ✅ Accessibility checks run automatically here!
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
```
|
|
60
123
|
|
|
61
|
-
|
|
124
|
+
## Running Comprehensive Checks Explicitly
|
|
125
|
+
|
|
126
|
+
While checks run automatically after each `visit`, you can also run comprehensive checks explicitly:
|
|
62
127
|
|
|
63
128
|
```ruby
|
|
64
129
|
# spec/system/my_page_accessibility_spec.rb
|
|
@@ -67,37 +132,108 @@ require 'rails_helper'
|
|
|
67
132
|
RSpec.describe 'My Page Accessibility', type: :system do
|
|
68
133
|
it 'loads the page and runs comprehensive accessibility checks' do
|
|
69
134
|
visit root_path
|
|
70
|
-
|
|
71
|
-
# Run comprehensive accessibility checks
|
|
72
|
-
# This will fail the test if any accessibility issues are found
|
|
73
|
-
check_comprehensive_accessibility
|
|
74
|
-
# ✅ If all checks pass, you'll see: "All comprehensive accessibility checks passed! (11 checks)"
|
|
135
|
+
check_comprehensive_accessibility # All 11 checks
|
|
75
136
|
end
|
|
76
137
|
end
|
|
77
138
|
```
|
|
78
139
|
|
|
79
|
-
|
|
140
|
+
## Understanding the Checks
|
|
80
141
|
|
|
81
|
-
|
|
142
|
+
Rails Accessibility Testing runs **11 comprehensive checks** automatically. These checks are WCAG 2.1 AA aligned:
|
|
82
143
|
|
|
83
|
-
|
|
144
|
+
1. **Form Labels** - All form inputs have associated labels
|
|
145
|
+
2. **Image Alt Text** - All images have descriptive alt attributes
|
|
146
|
+
3. **Interactive Elements** - Buttons, links have accessible names
|
|
147
|
+
4. **Heading Hierarchy** - Proper h1-h6 structure without skipping levels
|
|
148
|
+
5. **Keyboard Accessibility** - All interactive elements are keyboard accessible
|
|
149
|
+
6. **ARIA Landmarks** - Proper use of ARIA landmark roles
|
|
150
|
+
7. **Form Error Associations** - Form errors are properly linked to form fields
|
|
151
|
+
8. **Table Structure** - Tables have proper headers
|
|
152
|
+
9. **Duplicate IDs** - No duplicate ID attributes
|
|
153
|
+
10. **Skip Links** - Skip navigation links present
|
|
154
|
+
11. **Color Contrast** - Text meets WCAG contrast requirements (optional, disabled by default)
|
|
84
155
|
|
|
85
|
-
|
|
86
|
-
# Run all accessibility specs
|
|
87
|
-
bundle exec rspec spec/system/*_accessibility_spec.rb
|
|
156
|
+
## Configuration
|
|
88
157
|
|
|
89
|
-
|
|
90
|
-
|
|
158
|
+
Edit `config/accessibility.yml`:
|
|
159
|
+
|
|
160
|
+
```yaml
|
|
161
|
+
wcag_level: AA
|
|
162
|
+
|
|
163
|
+
# Summary configuration
|
|
164
|
+
summary:
|
|
165
|
+
show_summary: true
|
|
166
|
+
errors_only: false
|
|
167
|
+
show_fixes: true
|
|
168
|
+
ignore_warnings: false # Set to true to hide warnings, only show errors
|
|
169
|
+
|
|
170
|
+
# Static scanner configuration
|
|
171
|
+
static_scanner:
|
|
172
|
+
scan_changed_only: true # Only scan changed files
|
|
173
|
+
check_interval: 3 # Seconds between file checks
|
|
174
|
+
full_scan_on_startup: true # Full scan on startup
|
|
175
|
+
|
|
176
|
+
checks:
|
|
177
|
+
form_labels: true
|
|
178
|
+
image_alt_text: true
|
|
179
|
+
interactive_elements: true
|
|
180
|
+
heading_hierarchy: true
|
|
181
|
+
keyboard_accessibility: true
|
|
182
|
+
aria_landmarks: true
|
|
183
|
+
form_errors: true
|
|
184
|
+
table_structure: true
|
|
185
|
+
duplicate_ids: true
|
|
186
|
+
skip_links: true
|
|
187
|
+
color_contrast: false # Disabled by default (expensive)
|
|
91
188
|
```
|
|
92
189
|
|
|
93
|
-
|
|
190
|
+
### Profile-Specific Configuration
|
|
191
|
+
|
|
192
|
+
```yaml
|
|
193
|
+
development:
|
|
194
|
+
checks:
|
|
195
|
+
color_contrast: false # Skip in dev for speed
|
|
196
|
+
|
|
197
|
+
ci:
|
|
198
|
+
checks:
|
|
199
|
+
color_contrast: true # Full checks in CI
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Ignoring Rules Temporarily
|
|
203
|
+
|
|
204
|
+
```yaml
|
|
205
|
+
ignored_rules:
|
|
206
|
+
- rule: form_labels
|
|
207
|
+
reason: "Legacy form, scheduled for refactor in Q2"
|
|
208
|
+
comment: "Will be fixed in PR #123"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Skipping Checks in Tests
|
|
212
|
+
|
|
213
|
+
```ruby
|
|
214
|
+
# RSpec
|
|
215
|
+
it "does something", skip_a11y: true do
|
|
216
|
+
# Accessibility checks won't run
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Minitest
|
|
220
|
+
test "does something", skip_a11y: true do
|
|
221
|
+
# Accessibility checks won't run
|
|
222
|
+
end
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Next Steps
|
|
94
226
|
|
|
227
|
+
- **⭐ Read the [System Specs Guide](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/GUIDES/system_specs_for_accessibility.md)** - Recommended approach for reliable accessibility testing
|
|
228
|
+
- **Read the [CI Integration Guide](ci_integration.html)** to set up automated checks
|
|
229
|
+
- **Check out [Writing Accessible Views](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/GUIDES/writing_accessible_views_in_rails.md)** for best practices
|
|
230
|
+
- **See [Working with Designers](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/GUIDES/working_with_designers_and_content_authors.md)** for team collaboration
|
|
95
231
|
|
|
96
232
|
## Troubleshooting
|
|
97
233
|
|
|
98
234
|
### How do I configure Capybara for system tests?
|
|
99
235
|
|
|
100
|
-
|
|
236
|
+
Create `spec/support/driver.rb`:
|
|
101
237
|
|
|
102
238
|
```ruby
|
|
103
239
|
# spec/support/driver.rb
|
|
@@ -119,9 +255,6 @@ Capybara.register_driver :selenium_chrome_headless do |app|
|
|
|
119
255
|
)
|
|
120
256
|
end
|
|
121
257
|
|
|
122
|
-
# Set as default JavaScript driver
|
|
123
|
-
Capybara.javascript_driver = :selenium_chrome_headless
|
|
124
|
-
|
|
125
258
|
# Configure RSpec to use the driver for system tests
|
|
126
259
|
RSpec.configure do |config|
|
|
127
260
|
config.before(:each, type: :system) do
|
|
@@ -130,25 +263,17 @@ RSpec.configure do |config|
|
|
|
130
263
|
end
|
|
131
264
|
```
|
|
132
265
|
|
|
133
|
-
**Note for Rails 8:** Rails 8 uses `driven_by` to configure system tests. Make sure your `spec/support/driver.rb` is loaded by `rails_helper.rb` (it should be automatically loaded if it's in the `spec/support/` directory).
|
|
134
|
-
|
|
135
266
|
### How do I install Chrome/Chromium?
|
|
136
267
|
|
|
137
|
-
System tests require Chrome or Chromium to be installed on your system:
|
|
138
|
-
|
|
139
268
|
**macOS:**
|
|
140
269
|
```bash
|
|
141
270
|
brew install --cask google-chrome
|
|
142
|
-
# or for Chromium:
|
|
143
|
-
brew install --cask chromium
|
|
144
271
|
```
|
|
145
272
|
|
|
146
273
|
**Linux (Ubuntu/Debian):**
|
|
147
274
|
```bash
|
|
148
275
|
sudo apt-get update
|
|
149
276
|
sudo apt-get install -y google-chrome-stable
|
|
150
|
-
# or for Chromium:
|
|
151
|
-
sudo apt-get install -y chromium-browser
|
|
152
277
|
```
|
|
153
278
|
|
|
154
279
|
**Windows:**
|
|
@@ -158,45 +283,27 @@ The `webdrivers` gem will automatically download and manage the ChromeDriver bin
|
|
|
158
283
|
|
|
159
284
|
### Error: `uninitialized constant Selenium::WebDriver::DriverFinder`
|
|
160
285
|
|
|
161
|
-
|
|
162
|
-
1. **Missing selenium-webdriver gem** - Make sure you've added `gem 'selenium-webdriver', '~> 4.0'` to your Gemfile
|
|
163
|
-
2. **Version incompatibility** - Ensure you're using compatible versions:
|
|
164
|
-
- `selenium-webdriver` ~> 4.0 (4.6.0+ recommended for Rails 8)
|
|
165
|
-
- `webdrivers` ~> 5.0 (if using webdrivers)
|
|
166
|
-
- `capybara` ~> 3.40
|
|
167
|
-
|
|
168
|
-
**Solution:**
|
|
169
|
-
```bash
|
|
170
|
-
# Update your Gemfile
|
|
171
|
-
gem 'selenium-webdriver', '~> 4.10'
|
|
172
|
-
gem 'webdrivers', '~> 5.3'
|
|
173
|
-
gem 'capybara', '~> 3.40'
|
|
174
|
-
|
|
175
|
-
# Then run
|
|
176
|
-
bundle update selenium-webdriver webdrivers capybara
|
|
177
|
-
```
|
|
286
|
+
Make sure you've added `gem 'selenium-webdriver', '~> 4.0'` to your Gemfile and run `bundle install`.
|
|
178
287
|
|
|
179
288
|
### Error: Chrome/ChromeDriver not found
|
|
180
289
|
|
|
181
|
-
|
|
182
|
-
1. Make sure Chrome is installed (see Step 2.5 above)
|
|
290
|
+
1. Make sure Chrome is installed
|
|
183
291
|
2. If using `webdrivers` gem, it should auto-download ChromeDriver. If not:
|
|
184
292
|
```bash
|
|
185
293
|
bundle exec webdrivers chrome
|
|
186
294
|
```
|
|
187
|
-
3. For manual installation, download from [ChromeDriver downloads](https://chromedriver.chromium.org/downloads)
|
|
188
295
|
|
|
189
296
|
### System tests not running
|
|
190
297
|
|
|
191
298
|
**Check:**
|
|
192
299
|
1. Your spec has `type: :system` metadata
|
|
193
300
|
2. `spec/support/driver.rb` exists and is properly configured
|
|
194
|
-
3.
|
|
195
|
-
4. Chrome is installed and accessible
|
|
301
|
+
3. Chrome is installed and accessible
|
|
196
302
|
|
|
197
303
|
### Tests are slow
|
|
198
304
|
|
|
199
305
|
Disable expensive checks in development:
|
|
306
|
+
|
|
200
307
|
```yaml
|
|
201
308
|
# config/accessibility.yml
|
|
202
309
|
development:
|
|
@@ -206,24 +313,39 @@ development:
|
|
|
206
313
|
|
|
207
314
|
## Version Compatibility
|
|
208
315
|
|
|
209
|
-
For best results, use these compatible versions:
|
|
210
|
-
|
|
211
316
|
| Component | Recommended Version | Minimum Version | Required |
|
|
212
317
|
|-----------|-------------------|-----------------|----------|
|
|
213
318
|
| Ruby | 3.1+ | 3.0+ | Yes |
|
|
214
319
|
| Rails | 7.1+ / 8.0+ | 6.0+ | Yes |
|
|
215
|
-
|
|
|
320
|
+
| RSpec Rails | 8.0+ | 6.0+ | Yes (for system specs) |
|
|
216
321
|
| Capybara | ~> 3.40 | 3.0+ | Yes |
|
|
217
322
|
| selenium-webdriver | ~> 4.10 | 4.0+ | Yes |
|
|
218
323
|
| webdrivers | ~> 5.3 | 5.0+ | Optional |
|
|
219
324
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
- Rails 8 system tests use `driven_by` instead of direct Capybara configuration
|
|
325
|
+
## Common Questions
|
|
326
|
+
|
|
327
|
+
### Q: Do I need to change my existing tests?
|
|
224
328
|
|
|
225
|
-
|
|
329
|
+
**A:** No! Rails Accessibility Testing works with your existing system tests. Just run them as usual.
|
|
226
330
|
|
|
227
|
-
|
|
228
|
-
|
|
331
|
+
### Q: Will this slow down my tests?
|
|
332
|
+
|
|
333
|
+
**A:** Checks only run when you visit a page in a system test. The checks are fast, and you can disable expensive ones (like color contrast) in development.
|
|
334
|
+
|
|
335
|
+
### Q: Can I use this with Minitest?
|
|
336
|
+
|
|
337
|
+
**A:** Yes! See the Minitest integration in the main README.
|
|
338
|
+
|
|
339
|
+
### Q: What if I disagree with a check?
|
|
340
|
+
|
|
341
|
+
**A:** You can disable specific checks in `config/accessibility.yml` or ignore specific rules with a reason.
|
|
342
|
+
|
|
343
|
+
## Getting Help
|
|
344
|
+
|
|
345
|
+
- **Documentation:** See the main [README](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/README.md)
|
|
346
|
+
- **Issues:** [GitHub Issues](https://github.com/rayraycodes/rails-accessibility-testing/issues)
|
|
347
|
+
- **Email:** imregan@umich.edu
|
|
348
|
+
|
|
349
|
+
---
|
|
229
350
|
|
|
351
|
+
**Ready to make your Rails app accessible?** Run your tests and start fixing issues! 🚀
|
data/docs_site/index.md
CHANGED
|
@@ -9,39 +9,150 @@ title: Home
|
|
|
9
9
|
|
|
10
10
|
**Version:** 1.5.5
|
|
11
11
|
|
|
12
|
-
Rails Accessibility Testing is a comprehensive
|
|
12
|
+
Rails Accessibility Testing is a comprehensive, opinionated but configurable gem that makes accessibility testing as natural as unit testing. It integrates seamlessly into your Rails workflow, catching accessibility issues as you code—not after deployment.
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## 🎯 Positioning
|
|
15
|
+
|
|
16
|
+
Rails Accessibility Testing fills a critical gap in the Rails testing ecosystem. While RSpec ensures code works and RuboCop ensures code style, Rails Accessibility Testing ensures applications are accessible to everyone. Unlike manual accessibility audits that happen late in development, Rails Accessibility Testing integrates directly into your test suite, catching violations as you code. It's opinionated enough to guide teams new to accessibility, yet configurable enough for experienced teams. By making accessibility testing as natural as unit testing, Rails Accessibility Testing helps teams build accessible applications from day one, not as an afterthought.
|
|
17
|
+
|
|
18
|
+
## ✨ Features
|
|
19
|
+
|
|
20
|
+
### Core Capabilities
|
|
21
|
+
- 🚀 **Zero Configuration** - Works out of the box with smart defaults
|
|
22
|
+
- 🎯 **11+ Comprehensive Checks** - WCAG 2.1 AA aligned
|
|
23
|
+
- 📍 **Precise File Location** - Know exactly which view file or partial to fix
|
|
24
|
+
- 🔧 **Actionable Error Messages** - Code examples showing how to fix issues
|
|
25
|
+
- 🎨 **Beautiful CLI** - Human-readable and JSON reports
|
|
26
|
+
- 🔌 **Rails Generator** - One command setup
|
|
27
|
+
- 🧪 **RSpec & Minitest** - Works with both test frameworks
|
|
28
|
+
- ⚙️ **YAML Configuration** - Profile-based config (dev/test/CI)
|
|
29
|
+
|
|
30
|
+
### 🆕 Version 1.5.0+ Highlights
|
|
31
|
+
|
|
32
|
+
#### 🔍 Static File Scanner (NEW)
|
|
33
|
+
- **Fast file-based scanning**: Scans ERB templates directly without browser rendering
|
|
34
|
+
- **Smart change detection**: Only scans files that have changed since last scan
|
|
35
|
+
- **Precise error reporting**: Shows exact file locations and line numbers
|
|
36
|
+
- **Continuous monitoring**: Watches for file changes and re-scans automatically
|
|
37
|
+
- **YAML configuration**: Fully configurable via `config/accessibility.yml`
|
|
38
|
+
- **Reuses existing checks**: Leverages all 11 accessibility checks via RuleEngine
|
|
39
|
+
|
|
40
|
+
#### 🎯 Live Accessibility Scanner
|
|
41
|
+
- **Real-time scanning**: Automatically scans pages as you browse during development
|
|
42
|
+
- **Smart cancellation**: Cancels scans when you navigate to new pages, focusing on current page
|
|
43
|
+
- **Integrated workflow**: Works seamlessly with `bin/dev` via Procfile.dev
|
|
44
|
+
- **Detailed reporting**: Shows exactly what's being scanned with page URLs and view files
|
|
45
|
+
|
|
46
|
+
#### 📝 Enhanced Error Reporting
|
|
47
|
+
- **View file priority**: Rails view files shown prominently instead of URLs
|
|
48
|
+
- **Comprehensive summaries**: Overall test report showing all pages tested with statistics
|
|
49
|
+
- **Accurate error counting**: Properly tracks and displays error/warning counts
|
|
50
|
+
- **Persistent output**: Errors stay visible in terminal (no clearing)
|
|
51
|
+
|
|
52
|
+
## 🚀 Quick Start
|
|
53
|
+
|
|
54
|
+
### Installation
|
|
55
|
+
|
|
56
|
+
Add to your `Gemfile`:
|
|
15
57
|
|
|
16
58
|
```ruby
|
|
17
|
-
# Add to Gemfile
|
|
18
59
|
group :development, :test do
|
|
19
60
|
gem 'rails_accessibility_testing'
|
|
61
|
+
gem 'rspec-rails', '~> 8.0' # Required for system specs
|
|
20
62
|
gem 'axe-core-capybara', '~> 4.0'
|
|
63
|
+
gem 'capybara', '~> 3.40'
|
|
64
|
+
gem 'selenium-webdriver', '~> 4.0'
|
|
65
|
+
gem 'webdrivers', '~> 5.0' # Optional but recommended
|
|
66
|
+
gem 'csv' # Required for Ruby 3.3+ (CSV removed from standard library in Ruby 3.4)
|
|
21
67
|
end
|
|
22
68
|
```
|
|
23
69
|
|
|
70
|
+
**Important:** You must explicitly add `selenium-webdriver` and `csv` (for Ruby 3.3+) to your Gemfile. The gem has minimal dependencies - you control your own driver setup.
|
|
71
|
+
|
|
72
|
+
Then run:
|
|
73
|
+
|
|
24
74
|
```bash
|
|
25
|
-
# Install
|
|
26
75
|
bundle install
|
|
76
|
+
```
|
|
27
77
|
|
|
28
|
-
|
|
78
|
+
### Setup (Option 1: Generator - Recommended)
|
|
79
|
+
|
|
80
|
+
```bash
|
|
29
81
|
rails generate rails_a11y:install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This creates:
|
|
85
|
+
- `config/initializers/rails_a11y.rb` - Configuration
|
|
86
|
+
- `config/accessibility.yml` - Check settings
|
|
87
|
+
- `spec/system/all_pages_accessibility_spec.rb` - Comprehensive spec that dynamically tests all GET routes
|
|
88
|
+
- Updates `spec/rails_helper.rb` (if using RSpec)
|
|
89
|
+
- Updates `Procfile.dev` with static accessibility scanner (`a11y_static_scanner`)
|
|
90
|
+
|
|
91
|
+
## 📖 Usage
|
|
92
|
+
|
|
93
|
+
### System Specs (Recommended)
|
|
30
94
|
|
|
31
|
-
|
|
32
|
-
|
|
95
|
+
**System specs are the recommended and most reliable way to run accessibility checks.** They're faster, more reliable, and integrate seamlessly with your test suite.
|
|
96
|
+
|
|
97
|
+
Create system specs for your pages:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
# spec/system/home_page_accessibility_spec.rb
|
|
101
|
+
require 'rails_helper'
|
|
102
|
+
|
|
103
|
+
RSpec.describe 'Home Page Accessibility', type: :system do
|
|
104
|
+
it 'loads successfully and passes comprehensive accessibility checks' do
|
|
105
|
+
visit root_path
|
|
106
|
+
expect(page).to have_content('Welcome')
|
|
107
|
+
|
|
108
|
+
# Run comprehensive accessibility checks
|
|
109
|
+
check_comprehensive_accessibility
|
|
110
|
+
# ✅ Comprehensive accessibility checks (11 checks) also run automatically after this test!
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Accessibility checks run automatically after each `visit` in system specs!**
|
|
116
|
+
|
|
117
|
+
### Continuous Development Testing
|
|
118
|
+
|
|
119
|
+
The generator automatically adds a static accessibility scanner to your `Procfile.dev`:
|
|
120
|
+
|
|
121
|
+
```procfile
|
|
122
|
+
web: bin/rails server
|
|
123
|
+
css: bin/rails dartsass:watch
|
|
124
|
+
a11y: bundle exec a11y_static_scanner
|
|
33
125
|
```
|
|
34
126
|
|
|
35
|
-
|
|
127
|
+
Then run:
|
|
36
128
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
129
|
+
```bash
|
|
130
|
+
bin/dev
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
This will:
|
|
134
|
+
- Start your Rails server
|
|
135
|
+
- Watch for CSS changes
|
|
136
|
+
- **Continuously scan view files for accessibility issues** - Only scans files that have changed since last scan
|
|
137
|
+
- Shows errors with exact file locations and line numbers
|
|
138
|
+
|
|
139
|
+
## 🎯 What Gets Checked
|
|
140
|
+
|
|
141
|
+
The gem automatically runs **11 comprehensive accessibility checks**:
|
|
43
142
|
|
|
44
|
-
|
|
143
|
+
1. ✅ **Form Labels** - All form inputs have associated labels
|
|
144
|
+
2. ✅ **Image Alt Text** - All images have descriptive alt attributes
|
|
145
|
+
3. ✅ **Interactive Elements** - Buttons, links have accessible names (including links with images that have alt text)
|
|
146
|
+
4. ✅ **Heading Hierarchy** - Proper h1-h6 structure (detects missing h1, multiple h1s, skipped levels, and h2+ without h1)
|
|
147
|
+
5. ✅ **Keyboard Accessibility** - All interactive elements keyboard accessible
|
|
148
|
+
6. ✅ **ARIA Landmarks** - Proper use of ARIA landmark roles
|
|
149
|
+
7. ✅ **Form Error Associations** - Errors linked to form fields
|
|
150
|
+
8. ✅ **Table Structure** - Tables have proper headers
|
|
151
|
+
9. ✅ **Duplicate IDs** - No duplicate ID attributes
|
|
152
|
+
10. ✅ **Skip Links** - Skip navigation links present (detects various patterns)
|
|
153
|
+
11. ✅ **Color Contrast** - Text meets contrast requirements (optional)
|
|
154
|
+
|
|
155
|
+
## 📚 Documentation
|
|
45
156
|
|
|
46
157
|
- [Getting Started]({{ '/getting_started.html' | relative_url }}) - Quick start guide
|
|
47
158
|
- [Architecture]({{ '/architecture.html' | relative_url }}) - Visual diagrams and internal architecture
|
|
@@ -49,16 +160,20 @@ bundle exec rspec spec/system/
|
|
|
49
160
|
- [CI Integration]({{ '/ci_integration.html' | relative_url }}) - CI/CD setup
|
|
50
161
|
- [Contributing]({{ '/contributing.html' | relative_url }}) - How to contribute
|
|
51
162
|
|
|
52
|
-
|
|
163
|
+
### Additional Guides
|
|
53
164
|
|
|
54
165
|
- [System Specs for Accessibility](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/GUIDES/system_specs_for_accessibility.md) - ⭐ Recommended approach
|
|
55
166
|
- [Writing Accessible Views](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/GUIDES/writing_accessible_views_in_rails.md) - Best practices
|
|
56
167
|
- [Working with Designers](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/GUIDES/working_with_designers_and_content_authors.md) - Team collaboration
|
|
57
168
|
|
|
58
|
-
##
|
|
169
|
+
## 📞 Support
|
|
170
|
+
|
|
171
|
+
- **Issues:** [GitHub Issues](https://github.com/rayraycodes/rails-accessibility-testing/issues)
|
|
172
|
+
- **Email:** imregan@umich.edu
|
|
173
|
+
- **Documentation:** See [GUIDES](GUIDES/) directory
|
|
174
|
+
|
|
175
|
+
---
|
|
59
176
|
|
|
60
|
-
|
|
61
|
-
- [RubyGems](https://rubygems.org/gems/rails_accessibility_testing)
|
|
62
|
-
- [Issue Tracker](https://github.com/rayraycodes/rails-accessibility-testing/issues)
|
|
63
|
-
- [Changelog](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/CHANGELOG.md)
|
|
177
|
+
**Made with ❤️ for accessible Rails applications**
|
|
64
178
|
|
|
179
|
+
*Rails Accessibility Testing helps teams build accessible applications from day one, not as an afterthought.*
|
|
@@ -45,6 +45,16 @@ static_scanner:
|
|
|
45
45
|
# When false, only scans changed files from the start
|
|
46
46
|
full_scan_on_startup: true
|
|
47
47
|
|
|
48
|
+
# System specs configuration
|
|
49
|
+
# Controls behavior of accessibility checks in RSpec system specs
|
|
50
|
+
system_specs:
|
|
51
|
+
# Automatically run accessibility checks after each system spec (true/false)
|
|
52
|
+
# When true, checks run automatically after each `visit` in system specs
|
|
53
|
+
# When false, checks only run when explicitly called (e.g., check_comprehensive_accessibility)
|
|
54
|
+
# Default: false (set to true if you want automatic checks)
|
|
55
|
+
# Can be overridden per-profile (see profile sections below)
|
|
56
|
+
auto_run: false
|
|
57
|
+
|
|
48
58
|
# Global check configuration
|
|
49
59
|
# Set to false to disable a check globally
|
|
50
60
|
checks:
|
|
@@ -67,16 +77,22 @@ development:
|
|
|
67
77
|
checks:
|
|
68
78
|
color_contrast: false # Skip in dev for speed
|
|
69
79
|
# Add other dev-specific overrides here
|
|
80
|
+
# system_specs:
|
|
81
|
+
# auto_run: true # Override global system_specs.auto_run for development
|
|
70
82
|
|
|
71
83
|
test:
|
|
72
84
|
checks:
|
|
73
85
|
# Test environment uses global settings by default
|
|
74
86
|
# Add test-specific overrides here
|
|
87
|
+
# system_specs:
|
|
88
|
+
# auto_run: true # Override global system_specs.auto_run for test
|
|
75
89
|
|
|
76
90
|
ci:
|
|
77
91
|
checks:
|
|
78
92
|
color_contrast: true # Full checks in CI
|
|
79
93
|
# Add CI-specific overrides here
|
|
94
|
+
# system_specs:
|
|
95
|
+
# auto_run: true # Override global system_specs.auto_run for CI
|
|
80
96
|
|
|
81
97
|
# Ignored rules with reasons
|
|
82
98
|
# Use this to temporarily ignore specific rules while fixing issues
|