rails_accessibility_testing 1.3.0 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 916b677bef5f630731d65df12bdd430949d70876ec0c5a9c047e15353084ae7b
4
- data.tar.gz: 4960a239874be87bc96a74ba7804cfc3213ae0ea62a4b9a367d437fed337e0d0
3
+ metadata.gz: 5ed11e69796995b294eeaa17e2627e46b3122356d7383e2e1ad3b213c8f2ac78
4
+ data.tar.gz: 410f9e2c88b5e27e0a6319fb62bb854d832f8e74a25d7b3970aaf9b3f07a0fe5
5
5
  SHA512:
6
- metadata.gz: f0d0e645d4d2929da2b0d2461459510759dab172192e7564be8dd2e57f2771ff86144f4fb8ece7fcbd04351ba2cc0ee08964ea7a0e07d65485171718e7608a5c
7
- data.tar.gz: d8678b98bd3978104dd2158ff04f3494ff291d690b75ecee4bc29121eb76d283fd378a1cb6f763f14904060a1e8cc9e39288dcc4ca7f8ab8420253fcbc1273e1
6
+ metadata.gz: b3c309bbcc50838e5a981cf997c74051e10a79ce0b03d67450ad3e0dac8486d6ed79cfad4cd201e2cd25abf432370d80799a67ca9f136e11e2c055724e5f9dee
7
+ data.tar.gz: d8f2aaaad2e708e83dc4c9f7fd283ec815904557549f33c2f4b491fdeeed6c196b55c759b79effe7074bfda21cb4e3d07ccdefedcf07e065cdf4302f4395b74d
data/CHANGELOG.md CHANGED
@@ -5,7 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [1.3.0] - 2024-12-XX
8
+ ## [1.4.0] - 2025-11-18
9
+
10
+ ### Changed
11
+ - Updated documentation examples to use clearer language ("runs accessibility checks" instead of "passes accessibility checks")
12
+ - Improved test descriptions to accurately reflect that tests will fail if accessibility issues are found
13
+ - Enhanced comments in examples to clarify when success messages appear
14
+
15
+ ### Improved
16
+ - Better clarity in documentation about when accessibility checks pass vs fail
17
+ - More accurate test descriptions that don't imply tests will pass when they may fail
18
+ - Improved user understanding of accessibility check behavior
19
+
20
+ ## [1.3.0] - 2025-11-18
9
21
 
10
22
  ### Added
11
23
  - CLI reports now use ErrorMessageBuilder for detailed, formatted error messages
@@ -54,7 +54,7 @@ Let's see it in action. Create a simple system spec:
54
54
 
55
55
  ```ruby
56
56
  # spec/system/home_spec.rb
57
- RSpec.describe "Home Page" do
57
+ RSpec.describe "Home Page", type: :system do
58
58
  it "displays the welcome message" do
59
59
  visit root_path
60
60
  expect(page).to have_content("Welcome")
@@ -63,6 +63,41 @@ RSpec.describe "Home Page" do
63
63
  end
64
64
  ```
65
65
 
66
+ ## Running Comprehensive Checks Explicitly
67
+
68
+ While checks run automatically after each `visit`, you can also run comprehensive checks explicitly at any point in your test:
69
+
70
+ ```ruby
71
+ # spec/system/home_page_accessibility_spec.rb
72
+ require 'rails_helper'
73
+
74
+ RSpec.describe 'Home Page Accessibility', type: :system do
75
+ it 'loads the page and runs comprehensive accessibility checks' do
76
+ visit root_path
77
+ expect(page).to have_content('Welcome')
78
+
79
+ # Run comprehensive accessibility checks explicitly
80
+ # This will fail the test if any accessibility issues are found
81
+ check_comprehensive_accessibility
82
+ # āœ… This runs all 11 comprehensive checks:
83
+ # - Form labels, Image alt text, Interactive elements
84
+ # - Heading hierarchy, Keyboard accessibility, ARIA landmarks
85
+ # - Form errors, Table structure, Duplicate IDs
86
+ # - Skip links, Color contrast (if enabled)
87
+ # If all checks pass, you'll see: "All comprehensive accessibility checks passed! (11 checks)"
88
+ end
89
+ end
90
+ ```
91
+
92
+ **When to use explicit checks:**
93
+ - When you want to run checks at a specific point in your test (e.g., after filling a form)
94
+ - When you want to ensure checks run even if the test might fail before the automatic check
95
+ - When you want to test multiple pages in one spec and check each one explicitly
96
+
97
+ **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).
98
+
99
+ ### Example: Comprehensive Check Output
100
+
66
101
  If there are accessibility issues, you'll see detailed error messages like:
67
102
 
68
103
  ```
@@ -96,19 +131,33 @@ If there are accessibility issues, you'll see detailed error messages like:
96
131
 
97
132
  ## Understanding the Checks
98
133
 
99
- Rails A11y runs 11 comprehensive checks:
134
+ Rails A11y runs **11 comprehensive checks** automatically. These checks are WCAG 2.1 AA aligned:
100
135
 
101
- 1. **Form Labels** - All inputs have associated labels
102
- 2. **Image Alt Text** - All images have alt attributes
103
- 3. **Interactive Elements** - Buttons and links have accessible names
104
- 4. **Heading Hierarchy** - Proper h1-h6 structure
136
+ 1. **Form Labels** - All form inputs have associated labels
137
+ 2. **Image Alt Text** - All images have descriptive alt attributes (including empty alt="" detection)
138
+ 3. **Interactive Elements** - Buttons, links, and other interactive elements have accessible names
139
+ 4. **Heading Hierarchy** - Proper h1-h6 structure without skipping levels
105
140
  5. **Keyboard Accessibility** - All interactive elements are keyboard accessible
106
- 6. **ARIA Landmarks** - Proper use of ARIA landmark roles
107
- 7. **Form Error Associations** - Errors linked to form fields
108
- 8. **Table Structure** - Tables have proper headers
109
- 9. **Duplicate IDs** - No duplicate ID attributes
110
- 10. **Skip Links** - Skip navigation links present
111
- 11. **Color Contrast** - Text meets contrast requirements (optional)
141
+ 6. **ARIA Landmarks** - Proper use of ARIA landmark roles for page structure
142
+ 7. **Form Error Associations** - Form errors are properly linked to their form fields
143
+ 8. **Table Structure** - Tables have proper headers and structure
144
+ 9. **Duplicate IDs** - No duplicate ID attributes on the page
145
+ 10. **Skip Links** - Skip navigation links are present for keyboard users
146
+ 11. **Color Contrast** - Text meets WCAG contrast requirements (optional, disabled by default for performance)
147
+
148
+ ### What `check_comprehensive_accessibility` Does
149
+
150
+ When you call `check_comprehensive_accessibility`, it runs all 11 checks above and provides detailed error messages for any violations found. Each error includes:
151
+
152
+ - **File location hints** - Know exactly which view file to fix
153
+ - **Element details** - Tag, ID, classes, and visible text
154
+ - **Actionable fix instructions** - Code examples showing how to fix the issue
155
+ - **WCAG references** - Links to relevant WCAG guidelines
156
+
157
+ If all checks pass, you'll see:
158
+ ```
159
+ āœ… All comprehensive accessibility checks passed! (11 checks)
160
+ ```
112
161
 
113
162
  ## Configuration
114
163
 
@@ -171,6 +220,7 @@ end
171
220
 
172
221
  ## Next Steps
173
222
 
223
+ - **⭐ Read the [System Specs Guide](system_specs_for_accessibility.md)** - Recommended approach for reliable accessibility testing
174
224
  - **Read the [CI Integration Guide](continuous_integration.md)** to set up automated checks
175
225
  - **Check out [Writing Accessible Views](writing_accessible_views_in_rails.md)** for best practices
176
226
  - **See [Working with Designers](working_with_designers_and_content_authors.md)** for team collaboration
@@ -0,0 +1,248 @@
1
+ # Using System Specs for Accessibility Testing
2
+
3
+ System specs are the **recommended and most reliable** way to run accessibility checks in your Rails application. This guide shows you how to set up continuous accessibility testing using RSpec system specs.
4
+
5
+ ## Why System Specs?
6
+
7
+ āœ… **More Reliable** - Runs in the same test environment as your other specs
8
+ āœ… **Faster** - No need to wait for external server processes
9
+ āœ… **Better Integration** - Works seamlessly with your existing test suite
10
+ āœ… **Automatic** - Checks run automatically after each `visit` in system specs
11
+ āœ… **Clear Feedback** - Detailed error messages with file locations and fix instructions
12
+
13
+ ## Quick Setup
14
+
15
+ ### 1. Create System Specs
16
+
17
+ Create system specs for the pages you want to test. Name them with `_accessibility_spec.rb` suffix for clarity:
18
+
19
+ ```ruby
20
+ # spec/system/home_page_accessibility_spec.rb
21
+ require 'rails_helper'
22
+
23
+ RSpec.describe 'Home Page Accessibility', type: :system do
24
+ it 'loads the page and runs comprehensive accessibility checks' do
25
+ visit root_path
26
+ expect(page).to have_content('Biorepository').or have_content('Welcome')
27
+
28
+ # Run comprehensive accessibility checks
29
+ # This will fail the test if any accessibility issues are found
30
+ check_comprehensive_accessibility
31
+ # āœ… If all checks pass, you'll see: "All comprehensive accessibility checks passed! (11 checks)"
32
+ end
33
+ end
34
+ ```
35
+
36
+ ### 2. Automatic Checks
37
+
38
+ The gem automatically runs comprehensive accessibility checks after each `visit` in system specs. You don't need to call `check_comprehensive_accessibility` manually unless you want to run checks at a specific point in your test.
39
+
40
+ ### 3. Add to Procfile.dev (Optional)
41
+
42
+ For continuous testing during development, add to your `Procfile.dev`:
43
+
44
+ ```ruby
45
+ web: $(bundle show rails_accessibility_testing)/exe/rails_server_safe
46
+ css: bin/rails dartsass:watch
47
+ a11y: while true; do bundle exec rspec spec/system/*_accessibility_spec.rb; sleep 30; done
48
+ ```
49
+
50
+ This will run your accessibility specs every 30 seconds while you develop.
51
+
52
+ ## Example Specs
53
+
54
+ ### Basic Page Check
55
+
56
+ ```ruby
57
+ # spec/system/home_page_accessibility_spec.rb
58
+ require 'rails_helper'
59
+
60
+ RSpec.describe 'Home Page Accessibility', type: :system do
61
+ it 'runs accessibility checks on the home page' do
62
+ visit root_path
63
+ # āœ… Comprehensive accessibility checks run automatically after this test!
64
+ # The test will fail if any accessibility issues are found
65
+ end
66
+ end
67
+ ```
68
+
69
+ ### Multiple Pages
70
+
71
+ ```ruby
72
+ # spec/system/pages_accessibility_spec.rb
73
+ require 'rails_helper'
74
+
75
+ RSpec.describe 'Pages Accessibility', type: :system do
76
+ it 'runs accessibility checks on home page' do
77
+ visit root_path
78
+ # Checks run automatically - test fails if issues found
79
+ end
80
+
81
+ it 'runs accessibility checks on about page' do
82
+ visit about_path
83
+ # Checks run automatically - test fails if issues found
84
+ end
85
+
86
+ it 'runs accessibility checks on contact page' do
87
+ visit contact_path
88
+ # Checks run automatically - test fails if issues found
89
+ end
90
+ end
91
+ ```
92
+
93
+ ### With User Authentication
94
+
95
+ ```ruby
96
+ # spec/system/dashboard_accessibility_spec.rb
97
+ require 'rails_helper'
98
+
99
+ RSpec.describe 'Dashboard Accessibility', type: :system do
100
+ before do
101
+ user = FactoryBot.create(:user)
102
+ sign_in user
103
+ end
104
+
105
+ it 'runs accessibility checks on dashboard' do
106
+ visit dashboard_path
107
+ # āœ… Comprehensive accessibility checks run automatically after authentication!
108
+ # The test will fail if any accessibility issues are found
109
+ end
110
+ end
111
+ ```
112
+
113
+ ### Skip Checks for Specific Tests
114
+
115
+ ```ruby
116
+ it 'does something without accessibility checks', skip_a11y: true do
117
+ visit some_path
118
+ # Accessibility checks won't run for this test
119
+ end
120
+ ```
121
+
122
+ ## What Gets Checked
123
+
124
+ The gem automatically runs **11 comprehensive accessibility checks**:
125
+
126
+ 1. āœ… **Form Labels** - All form inputs have associated labels
127
+ 2. āœ… **Image Alt Text** - All images have descriptive alt attributes
128
+ 3. āœ… **Interactive Elements** - Buttons, links have accessible names
129
+ 4. āœ… **Heading Hierarchy** - Proper h1-h6 structure
130
+ 5. āœ… **Keyboard Accessibility** - All interactive elements keyboard accessible
131
+ 6. āœ… **ARIA Landmarks** - Proper use of ARIA landmark roles
132
+ 7. āœ… **Form Error Associations** - Errors linked to form fields
133
+ 8. āœ… **Table Structure** - Tables have proper headers
134
+ 9. āœ… **Duplicate IDs** - No duplicate ID attributes
135
+ 10. āœ… **Skip Links** - Skip navigation links present
136
+ 11. āœ… **Color Contrast** - Text meets contrast requirements (optional, disabled by default)
137
+
138
+ ## Success Messages
139
+
140
+ When all checks pass, you'll see:
141
+
142
+ ```
143
+ āœ… All comprehensive accessibility checks passed! (11 checks)
144
+ ```
145
+
146
+ ## Error Messages
147
+
148
+ When issues are found, you get detailed, actionable errors:
149
+
150
+ ```
151
+ ======================================================================
152
+ āŒ ACCESSIBILITY ERROR: Page missing H1 heading
153
+ ======================================================================
154
+
155
+ šŸ“„ Page Being Tested:
156
+ URL: http://127.0.0.1:54384/
157
+ Path: /
158
+ šŸ“ Likely View File: app/views/home/about.html.erb
159
+
160
+ šŸ“ Element Details:
161
+ Tag: <page>
162
+ ID: (none)
163
+ Classes: (none)
164
+ Visible text: Page has no H1 heading
165
+
166
+ šŸ”§ HOW TO FIX:
167
+ Add an <h1> heading to your page:
168
+
169
+ <h1>Main Page Title</h1>
170
+
171
+ Or in Rails ERB:
172
+ <h1><%= @page_title || 'Default Title' %></h1>
173
+
174
+ šŸ’” Best Practice: Every page should have exactly one <h1>.
175
+ It should describe the main purpose of the page.
176
+
177
+ šŸ“– WCAG Reference: https://www.w3.org/WAI/WCAG21/Understanding/
178
+ ======================================================================
179
+ ```
180
+
181
+ ## Running Specs
182
+
183
+ ### Run All Accessibility Specs
184
+
185
+ ```bash
186
+ bundle exec rspec spec/system/*_accessibility_spec.rb
187
+ ```
188
+
189
+ ### Run Specific Spec
190
+
191
+ ```bash
192
+ bundle exec rspec spec/system/home_page_accessibility_spec.rb
193
+ ```
194
+
195
+ ### Run with Documentation Format
196
+
197
+ ```bash
198
+ bundle exec rspec spec/system/*_accessibility_spec.rb --format documentation
199
+ ```
200
+
201
+ ## Continuous Integration
202
+
203
+ Add to your CI configuration:
204
+
205
+ ```yaml
206
+ # .github/workflows/ci.yml
207
+ - name: Run Accessibility Tests
208
+ run: bundle exec rspec spec/system/*_accessibility_spec.rb
209
+ ```
210
+
211
+ ## Best Practices
212
+
213
+ 1. **Name your specs clearly** - Use `_accessibility_spec.rb` suffix
214
+ 2. **Test critical paths** - Focus on user-facing pages
215
+ 3. **Keep specs simple** - One page per spec is often enough
216
+ 4. **Use Procfile.dev** - For continuous testing during development
217
+ 5. **Run in CI** - Catch issues before they reach production
218
+
219
+ ## Troubleshooting
220
+
221
+ ### Checks Not Running
222
+
223
+ Make sure:
224
+ - Your spec has `type: :system`
225
+ - You call `visit` in your test
226
+ - The gem is properly configured in `spec/rails_helper.rb`
227
+
228
+ ### Success Message Not Showing
229
+
230
+ The success message appears when all checks pass. If you don't see it, there may be silent failures. Check your RSpec output for any exceptions.
231
+
232
+ ### Slow Tests
233
+
234
+ Disable color contrast checking in development:
235
+
236
+ ```yaml
237
+ # config/accessibility.yml
238
+ development:
239
+ checks:
240
+ color_contrast: false
241
+ ```
242
+
243
+ ## Next Steps
244
+
245
+ - See [Getting Started Guide](getting_started.md) for initial setup
246
+ - See [Continuous Integration Guide](continuous_integration.md) for CI/CD setup
247
+ - See [Writing Accessible Views](writing_accessible_views_in_rails.md) for best practices
248
+
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  **The RSpec + RuboCop of accessibility for Rails. Catch WCAG violations before they reach production.**
9
9
 
10
- **Current Version:** 1.2.0
10
+ **Current Version:** 1.4.0
11
11
 
12
12
  šŸ“– **[šŸ“š Full Documentation](https://rayraycodes.github.io/rails-accessibility-testing/)** | [šŸ’» GitHub](https://github.com/rayraycodes/rails-accessibility-testing) | [šŸ’Ž RubyGems](https://rubygems.org/gems/rails_accessibility_testing)
13
13
 
@@ -84,13 +84,45 @@ RailsAccessibilityTesting::Integration::MinitestIntegration.setup!
84
84
 
85
85
  ## šŸ“– Usage
86
86
 
87
+ ### System Specs (Recommended)
88
+
89
+ **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.
90
+
91
+ Create system specs for your pages:
92
+
93
+ ```ruby
94
+ # spec/system/home_page_accessibility_spec.rb
95
+ require 'rails_helper'
96
+
97
+ RSpec.describe 'Home Page Accessibility', type: :system do
98
+ it 'loads successfully and passes comprehensive accessibility checks' do
99
+ visit root_path
100
+ expect(page).to have_content('Biorepository').or have_content('Welcome')
101
+
102
+ # Run comprehensive accessibility checks
103
+ check_comprehensive_accessibility
104
+ # āœ… Comprehensive accessibility checks (11 checks) also run automatically after this test!
105
+ end
106
+ end
107
+ ```
108
+
109
+ **Accessibility checks run automatically after each `visit` in system specs!**
110
+
111
+ For continuous testing during development, add to your `Procfile.dev`:
112
+
113
+ ```ruby
114
+ a11y: while true; do bundle exec rspec spec/system/*_accessibility_spec.rb; sleep 30; done
115
+ ```
116
+
117
+ šŸ“– **[See the full System Specs Guide](GUIDES/system_specs_for_accessibility.md)** for detailed examples and best practices.
118
+
87
119
  ### Automatic Checks
88
120
 
89
121
  Just write your specs normally - checks run automatically:
90
122
 
91
123
  ```ruby
92
124
  # spec/system/home_page_spec.rb
93
- RSpec.describe "Home Page" do
125
+ RSpec.describe "Home Page", type: :system do
94
126
  it "displays welcome message" do
95
127
  visit root_path
96
128
  expect(page).to have_content("Welcome")
@@ -270,6 +302,7 @@ Complete documentation site with all guides, examples, and API reference. The do
270
302
 
271
303
  ### Guides
272
304
 
305
+ - **[System Specs for Accessibility](GUIDES/system_specs_for_accessibility.md)** - ⭐ **Recommended approach** - Using system specs for reliable accessibility testing
273
306
  - **[Getting Started](GUIDES/getting_started.md)** - Quick start guide
274
307
  - **[Continuous Integration](GUIDES/continuous_integration.md)** - CI/CD setup
275
308
  - **[Writing Accessible Views](GUIDES/writing_accessible_views_in_rails.md)** - Best practices
@@ -106,6 +106,9 @@ module RailsAccessibilityTesting
106
106
  end
107
107
 
108
108
  def run_checks(options, config)
109
+ # Reset wait attempts counter for each run
110
+ @wait_attempts = 0
111
+
109
112
  require 'capybara'
110
113
  require 'capybara/dsl'
111
114
  require 'selenium-webdriver'
@@ -160,7 +163,12 @@ module RailsAccessibilityTesting
160
163
  # If still not ready, skip this check and try next time
161
164
  unless server_ready
162
165
  # Server still starting - this is normal, will retry automatically
163
- $stderr.puts "Waiting for server to start... (will retry automatically)"
166
+ # Only show message occasionally to avoid spam (every 3rd attempt)
167
+ @wait_attempts ||= 0
168
+ @wait_attempts += 1
169
+ if @wait_attempts % 3 == 1
170
+ $stderr.puts "Waiting for server to start... (will retry automatically)"
171
+ end
164
172
  next
165
173
  end
166
174
  end
@@ -49,12 +49,13 @@ module RailsAccessibilityTesting
49
49
  instance = example.example_group_instance
50
50
  instance.check_comprehensive_accessibility
51
51
 
52
- # Show success message if checks passed (no exception was raised)
53
- unless example.exception
54
- $stdout.puts "\nāœ… All comprehensive accessibility checks passed! (11 checks)"
55
- $stdout.flush
56
- end
52
+ # If we get here without an exception, all checks passed
53
+ # Note: check_comprehensive_accessibility will raise if there are errors,
54
+ # so if we reach this point, checks passed successfully
55
+ $stdout.puts "\nāœ… All comprehensive accessibility checks passed! (11 checks)"
56
+ $stdout.flush
57
57
  rescue StandardError => e
58
+ # Accessibility check failed - set the exception so test fails
58
59
  example.set_exception(e)
59
60
  end
60
61
  end
@@ -1,4 +1,4 @@
1
1
  module RailsAccessibilityTesting
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
4
4
 
@@ -5,7 +5,7 @@
5
5
  # Automatically configures accessibility testing for Rails system specs with
6
6
  # comprehensive checks and detailed error messages.
7
7
  #
8
- # @version 1.1.0
8
+ # @version 1.4.0
9
9
  # @author Regan Maharjan
10
10
  #
11
11
  # @example Basic usage
@@ -38,7 +38,7 @@ begin
38
38
  require_relative 'rails_accessibility_testing/version'
39
39
  rescue LoadError
40
40
  module RailsAccessibilityTesting
41
- VERSION = '1.3.0'
41
+ VERSION = '1.4.0'
42
42
  end
43
43
  end
44
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_accessibility_testing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Regan Maharjan
@@ -84,6 +84,7 @@ files:
84
84
  - CONTRIBUTING.md
85
85
  - GUIDES/continuous_integration.md
86
86
  - GUIDES/getting_started.md
87
+ - GUIDES/system_specs_for_accessibility.md
87
88
  - GUIDES/working_with_designers_and_content_authors.md
88
89
  - GUIDES/writing_accessible_views_in_rails.md
89
90
  - LICENSE