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.
@@ -19,13 +19,11 @@ group :development, :test do
19
19
  gem 'axe-core-capybara', '~> 4.0'
20
20
  gem 'capybara', '~> 3.40'
21
21
  gem 'selenium-webdriver', '~> 4.0'
22
- gem 'webdrivers', '~> 5.0' # Optional but recommended for automatic driver management
22
+ gem 'webdrivers', '~> 5.0' # Optional but recommended
23
23
  end
24
24
  ```
25
25
 
26
- **Important:**
27
- - You must explicitly add `selenium-webdriver` to your Gemfile. It's not automatically included as a dependency.
28
- - **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.
26
+ **Important:** You must explicitly add `selenium-webdriver` to your Gemfile. It's not automatically included as a dependency.
29
27
 
30
28
  Then run:
31
29
 
@@ -44,25 +42,13 @@ rails generate rails_a11y:install
44
42
  This creates:
45
43
  - `config/initializers/rails_a11y.rb` - Configuration
46
44
  - `config/accessibility.yml` - Check settings
47
- - `spec/system/all_pages_accessibility_spec.rb` - Comprehensive spec that tests all GET routes with smart change detection
45
+ - `spec/system/all_pages_accessibility_spec.rb` - Comprehensive spec that tests all GET routes
48
46
  - Updates `spec/rails_helper.rb` (if using RSpec)
49
- - Updates `Procfile.dev` - Adds accessibility watch command (optional)
50
-
51
- **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 [FAQ section](#troubleshooting) below.
47
+ - Updates `Procfile.dev` - Adds static accessibility scanner
52
48
 
53
49
  ### Step 3: Run Your Tests
54
50
 
55
- You can run accessibility checks in several ways:
56
-
57
- #### Option A: Run Tests Manually
58
-
59
- ```bash
60
- bundle exec rspec spec/system/
61
- ```
62
-
63
- Accessibility checks run automatically on every system test that visits a page.
64
-
65
- #### Option B: Static File Scanner (Recommended for Development)
51
+ #### Option A: Static File Scanner (Recommended for Development)
66
52
 
67
53
  The generator automatically adds a static accessibility scanner to your `Procfile.dev`:
68
54
 
@@ -85,53 +71,39 @@ This will:
85
71
  - Shows errors with exact file locations and line numbers
86
72
 
87
73
  **How it works:**
88
- - **First run**: Scans all view files to establish baseline
89
- - **Subsequent runs**: Only scans files that have been modified
90
- - **Continuous monitoring**: Watches for file changes and re-scans automatically
91
- - **Smart change detection**: Uses file modification times to track changes
92
- - **Fast feedback**: No browser needed - scans ERB templates directly
74
+ - Scans all files on startup
75
+ - Only re-scans files that have been modified
76
+ - Watches for file changes and re-scans automatically
77
+ - No browser needed - scans ERB templates directly
93
78
 
94
79
  **Configuration** (in `config/accessibility.yml`):
95
80
 
96
81
  ```yaml
97
82
  static_scanner:
98
- # Only scan files that have changed since last scan (true/false)
99
- scan_changed_only: true
100
-
101
- # Check interval in seconds when running continuously
102
- check_interval: 3
103
-
104
- # Force full scan on startup (true/false)
105
- full_scan_on_startup: true
83
+ scan_changed_only: true # Only scan changed files
84
+ check_interval: 3 # Seconds between file checks
85
+ full_scan_on_startup: true # Full scan on startup
106
86
  ```
107
87
 
108
- The static scanner provides fast, continuous feedback as you develop, catching accessibility issues before you even run your tests!
88
+ #### Option B: Run Tests Manually
109
89
 
110
- #### Option C: All Pages Spec with Smart Change Detection
90
+ ```bash
91
+ bundle exec rspec spec/system/
92
+ ```
111
93
 
112
- The generator creates `spec/system/all_pages_accessibility_spec.rb` which automatically tests all GET routes in your application. This spec includes **smart change detection**:
94
+ Accessibility checks run automatically on every system test that visits a page.
113
95
 
114
- - **Only tests pages when their related files change** - Views, controllers, or helpers
115
- - **Detects changes via Git** - Uncommitted changes in monitored directories (`app/views`, `app/controllers`, `app/helpers`)
116
- - **File modification tracking** - Files changed in the last 5 minutes
117
- - **Layout/helper changes** - Automatically tests all pages when layouts or helpers change (they affect everything)
118
- - **First run** - Tests all pages on first run (when no changes detected)
119
- - **Manual override** - Set `TEST_ALL_PAGES=true` to force testing all pages regardless of changes
96
+ #### Option C: All Pages Spec
120
97
 
121
- This makes your test suite faster and more focused, only running checks when relevant code changes. The spec automatically:
122
- - Skips routes that require authentication
123
- - Handles routes with parameters
124
- - Filters out API routes and Rails internal routes
125
- - Provides clear skip messages when pages aren't affected by changes
98
+ Run the comprehensive spec that tests all GET routes:
126
99
 
127
- Run it manually:
128
100
  ```bash
129
101
  bundle exec rspec spec/system/all_pages_accessibility_spec.rb
130
102
  ```
131
103
 
132
104
  ## Your First Accessibility Check
133
105
 
134
- Let's see it in action. Create a simple system spec:
106
+ Create a simple system spec:
135
107
 
136
108
  ```ruby
137
109
  # spec/system/home_spec.rb
@@ -146,7 +118,7 @@ end
146
118
 
147
119
  ## Running Comprehensive Checks Explicitly
148
120
 
149
- While checks run automatically after each `visit`, you can also run comprehensive checks explicitly at any point in your test:
121
+ While checks run automatically after each `visit`, you can also run comprehensive checks explicitly:
150
122
 
151
123
  ```ruby
152
124
  # spec/system/my_page_accessibility_spec.rb
@@ -155,94 +127,29 @@ require 'rails_helper'
155
127
  RSpec.describe 'My Page Accessibility', type: :system do
156
128
  it 'loads the page and runs comprehensive accessibility checks' do
157
129
  visit root_path
158
-
159
- # Run comprehensive accessibility checks explicitly
160
- # This will fail the test if any accessibility issues are found
161
- check_comprehensive_accessibility
162
- # ✅ This runs all 11 comprehensive checks:
163
- # - Form labels, Image alt text, Interactive elements
164
- # - Heading hierarchy, Keyboard accessibility, ARIA landmarks
165
- # - Form errors, Table structure, Duplicate IDs
166
- # - Skip links, Color contrast (if enabled)
167
- # If all checks pass, you'll see: "All comprehensive accessibility checks passed! (11 checks)"
130
+ check_comprehensive_accessibility # All 11 checks
168
131
  end
169
132
  end
170
133
  ```
171
134
 
172
- **When to use explicit checks:**
173
- - When you want to run checks at a specific point in your test (e.g., after filling a form)
174
- - When you want to ensure checks run even if the test might fail before the automatic check
175
- - When you want to test multiple pages in one spec and check each one explicitly
176
-
177
- **Note:** Even if you call `check_comprehensive_accessibility` explicitly, the automatic checks will still run after the test completes (unless the test fails before reaching the explicit check).
178
-
179
- ### Example: Comprehensive Check Output
180
-
181
- If there are accessibility issues, you'll see detailed error messages like:
182
-
183
- ```
184
- ======================================================================
185
- ❌ ACCESSIBILITY ERROR: Image missing alt attribute
186
- ======================================================================
187
-
188
- 📄 Page Being Tested:
189
- URL: http://localhost:3000/
190
- Path: /
191
- 📝 Likely View File: app/views/pages/home.html.erb
192
-
193
- 📍 Element Details:
194
- Tag: <img>
195
- ID: (none)
196
- Classes: logo
197
- Src: /assets/logo.png
198
-
199
- 🔧 HOW TO FIX:
200
- Choose ONE of these solutions:
201
-
202
- 1. Add alt text for informative images:
203
- <img src="/assets/logo.png" alt="Company Logo">
204
-
205
- 2. Use Rails image_tag helper:
206
- <%= image_tag 'logo.png', alt: 'Company Logo' %>
207
-
208
- 💡 Best Practice: All images must have alt attribute.
209
- Use empty alt="" only for purely decorative images.
210
- ```
211
-
212
135
  ## Understanding the Checks
213
136
 
214
137
  Rails A11y runs **11 comprehensive checks** automatically. These checks are WCAG 2.1 AA aligned:
215
138
 
216
139
  1. **Form Labels** - All form inputs have associated labels
217
- 2. **Image Alt Text** - All images have descriptive alt attributes (including empty alt="" detection)
218
- 3. **Interactive Elements** - Buttons, links, and other interactive elements have accessible names (including links with images that have alt text)
219
- 4. **Heading Hierarchy** - Proper h1-h6 structure without skipping levels (detects missing h1, skipped levels, and h2+ without h1)
140
+ 2. **Image Alt Text** - All images have descriptive alt attributes
141
+ 3. **Interactive Elements** - Buttons, links have accessible names
142
+ 4. **Heading Hierarchy** - Proper h1-h6 structure without skipping levels
220
143
  5. **Keyboard Accessibility** - All interactive elements are keyboard accessible
221
- 6. **ARIA Landmarks** - Proper use of ARIA landmark roles for page structure
222
- 7. **Form Error Associations** - Form errors are properly linked to their form fields
223
- 8. **Table Structure** - Tables have proper headers and structure
224
- 9. **Duplicate IDs** - No duplicate ID attributes on the page
225
- 10. **Skip Links** - Skip navigation links are present for keyboard users (detects various patterns: `skip-link`, `skiplink`, `href="#main"`, `href="#maincontent"`, etc.)
226
- 11. **Color Contrast** - Text meets WCAG contrast requirements (optional, disabled by default for performance)
227
-
228
- ### What `check_comprehensive_accessibility` Does
229
-
230
- When you call `check_comprehensive_accessibility`, it runs all 11 checks above and provides detailed error messages for any violations found. Each error includes:
231
-
232
- - **File location hints** - Know exactly which view file to fix
233
- - **Element details** - Tag, ID, classes, and visible text
234
- - **Actionable fix instructions** - Code examples showing how to fix the issue
235
- - **WCAG references** - Links to relevant WCAG guidelines
236
-
237
- If all checks pass, you'll see:
238
- ```
239
- ✅ All comprehensive accessibility checks passed! (11 checks)
240
- ```
144
+ 6. **ARIA Landmarks** - Proper use of ARIA landmark roles
145
+ 7. **Form Error Associations** - Form errors are properly linked to form fields
146
+ 8. **Table Structure** - Tables have proper headers
147
+ 9. **Duplicate IDs** - No duplicate ID attributes
148
+ 10. **Skip Links** - Skip navigation links present
149
+ 11. **Color Contrast** - Text meets WCAG contrast requirements (optional, disabled by default)
241
150
 
242
151
  ## Configuration
243
152
 
244
- ### Basic Configuration
245
-
246
153
  Edit `config/accessibility.yml`:
247
154
 
248
155
  ```yaml
@@ -259,19 +166,24 @@ summary:
259
166
  static_scanner:
260
167
  scan_changed_only: true # Only scan changed files
261
168
  check_interval: 3 # Seconds between file checks
262
- full_scan_on_startup: true # Full scan on first run
169
+ full_scan_on_startup: true # Full scan on startup
263
170
 
264
171
  checks:
265
172
  form_labels: true
266
173
  image_alt_text: true
267
- # ... other checks
174
+ interactive_elements: true
175
+ heading_hierarchy: true
176
+ keyboard_accessibility: true
177
+ aria_landmarks: true
178
+ form_errors: true
179
+ table_structure: true
180
+ duplicate_ids: true
181
+ skip_links: true
268
182
  color_contrast: false # Disabled by default (expensive)
269
183
  ```
270
184
 
271
185
  ### Profile-Specific Configuration
272
186
 
273
- Different settings for different environments:
274
-
275
187
  ```yaml
276
188
  development:
277
189
  checks:
@@ -284,8 +196,6 @@ ci:
284
196
 
285
197
  ### Ignoring Rules Temporarily
286
198
 
287
- Sometimes you need to temporarily ignore a rule while fixing issues:
288
-
289
199
  ```yaml
290
200
  ignored_rules:
291
201
  - rule: form_labels
@@ -293,12 +203,8 @@ ignored_rules:
293
203
  comment: "Will be fixed in PR #123"
294
204
  ```
295
205
 
296
- **Important:** Always include a reason and plan to fix. This is for temporary exceptions, not permanent workarounds.
297
-
298
206
  ## Skipping Checks in Tests
299
207
 
300
- Sometimes you need to skip accessibility checks for specific tests:
301
-
302
208
  ```ruby
303
209
  # RSpec
304
210
  it "does something", skip_a11y: true do
@@ -322,7 +228,7 @@ end
322
228
 
323
229
  ### How do I configure Capybara for system tests?
324
230
 
325
- If you don't already have system tests configured, you need to set up Capybara with a Selenium driver. Create `spec/support/driver.rb`:
231
+ Create `spec/support/driver.rb`:
326
232
 
327
233
  ```ruby
328
234
  # spec/support/driver.rb
@@ -344,9 +250,6 @@ Capybara.register_driver :selenium_chrome_headless do |app|
344
250
  )
345
251
  end
346
252
 
347
- # Set as default JavaScript driver
348
- Capybara.javascript_driver = :selenium_chrome_headless
349
-
350
253
  # Configure RSpec to use the driver for system tests
351
254
  RSpec.configure do |config|
352
255
  config.before(:each, type: :system) do
@@ -355,25 +258,17 @@ RSpec.configure do |config|
355
258
  end
356
259
  ```
357
260
 
358
- **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).
359
-
360
261
  ### How do I install Chrome/Chromium?
361
262
 
362
- System tests require Chrome or Chromium to be installed on your system:
363
-
364
263
  **macOS:**
365
264
  ```bash
366
265
  brew install --cask google-chrome
367
- # or for Chromium:
368
- brew install --cask chromium
369
266
  ```
370
267
 
371
268
  **Linux (Ubuntu/Debian):**
372
269
  ```bash
373
270
  sudo apt-get update
374
271
  sudo apt-get install -y google-chrome-stable
375
- # or for Chromium:
376
- sudo apt-get install -y chromium-browser
377
272
  ```
378
273
 
379
274
  **Windows:**
@@ -383,45 +278,27 @@ The `webdrivers` gem will automatically download and manage the ChromeDriver bin
383
278
 
384
279
  ### Error: `uninitialized constant Selenium::WebDriver::DriverFinder`
385
280
 
386
- This error typically occurs when:
387
- 1. **Missing selenium-webdriver gem** - Make sure you've added `gem 'selenium-webdriver', '~> 4.0'` to your Gemfile
388
- 2. **Version incompatibility** - Ensure you're using compatible versions:
389
- - `selenium-webdriver` ~> 4.0 (4.6.0+ recommended for Rails 8)
390
- - `webdrivers` ~> 5.0 (if using webdrivers)
391
- - `capybara` ~> 3.40
392
-
393
- **Solution:**
394
- ```bash
395
- # Update your Gemfile
396
- gem 'selenium-webdriver', '~> 4.10'
397
- gem 'webdrivers', '~> 5.3'
398
- gem 'capybara', '~> 3.40'
399
-
400
- # Then run
401
- bundle update selenium-webdriver webdrivers capybara
402
- ```
281
+ Make sure you've added `gem 'selenium-webdriver', '~> 4.0'` to your Gemfile and run `bundle install`.
403
282
 
404
283
  ### Error: Chrome/ChromeDriver not found
405
284
 
406
- **Solution:**
407
- 1. Make sure Chrome is installed (see Step 3 above)
285
+ 1. Make sure Chrome is installed
408
286
  2. If using `webdrivers` gem, it should auto-download ChromeDriver. If not:
409
287
  ```bash
410
288
  bundle exec webdrivers chrome
411
289
  ```
412
- 3. For manual installation, download from [ChromeDriver downloads](https://chromedriver.chromium.org/downloads)
413
290
 
414
291
  ### System tests not running
415
292
 
416
293
  **Check:**
417
294
  1. Your spec has `type: :system` metadata
418
295
  2. `spec/support/driver.rb` exists and is properly configured
419
- 3. `spec/rails_helper.rb` loads support files (should be automatic)
420
- 4. Chrome is installed and accessible
296
+ 3. Chrome is installed and accessible
421
297
 
422
298
  ### Tests are slow
423
299
 
424
300
  Disable expensive checks in development:
301
+
425
302
  ```yaml
426
303
  # config/accessibility.yml
427
304
  development:
@@ -431,22 +308,15 @@ development:
431
308
 
432
309
  ## Version Compatibility
433
310
 
434
- For best results, use these compatible versions:
435
-
436
311
  | Component | Recommended Version | Minimum Version | Required |
437
312
  |-----------|-------------------|-----------------|----------|
438
313
  | Ruby | 3.1+ | 3.0+ | Yes |
439
314
  | Rails | 7.1+ / 8.0+ | 6.0+ | Yes |
440
- | **RSpec Rails** | **8.0+** | **6.0+** | **Yes (for system specs)** |
315
+ | RSpec Rails | 8.0+ | 6.0+ | Yes (for system specs) |
441
316
  | Capybara | ~> 3.40 | 3.0+ | Yes |
442
317
  | selenium-webdriver | ~> 4.10 | 4.0+ | Yes |
443
318
  | webdrivers | ~> 5.3 | 5.0+ | Optional |
444
319
 
445
- **Rails 8 Notes:**
446
- - Rails 8 requires `selenium-webdriver` 4.6.0+ for `DriverFinder` support
447
- - Make sure your `driven_by` configuration is in `spec/support/driver.rb`
448
- - Rails 8 system tests use `driven_by` instead of direct Capybara configuration
449
-
450
320
  ## Common Questions
451
321
 
452
322
  ### Q: Do I need to change my existing tests?
@@ -474,4 +344,3 @@ For best results, use these compatible versions:
474
344
  ---
475
345
 
476
346
  **Ready to make your Rails app accessible?** Run your tests and start fixing issues! 🚀
477
-
data/README.md CHANGED
@@ -427,6 +427,10 @@ Prevents duplicate scans of the same page during a test run:
427
427
 
428
428
  Complete documentation site with all guides, examples, and API reference. The documentation is automatically deployed from this repository.
429
429
 
430
+ ### 📄 Offline Manual
431
+
432
+ **[PROJECT_DOCUMENTATION.md](PROJECT_DOCUMENTATION.md)** - A comprehensive, single-file manual containing all guides, architecture details, and best practices. Perfect for offline reading or sharing as a PDF/DOCX.
433
+
430
434
  > **Note:**
431
435
  > - **Documentation URL:** `https://rayraycodes.github.io/rails-accessibility-testing/`
432
436
  > - If the link doesn't work, GitHub Pages may need to be enabled. See [ENABLE_GITHUB_PAGES.md](ENABLE_GITHUB_PAGES.md) for setup instructions.
@@ -23,6 +23,9 @@ kramdown:
23
23
  syntax_highlighter_opts:
24
24
  disable: false
25
25
  input: GFM
26
+ hard_wrap: false
27
+ auto_ids: true
28
+ footnote_nr: 1
26
29
 
27
30
  # Navigation
28
31
  navigation: