Version: 1.5.5
Date: November 2025
Author: Regan Maharjan
- Executive Summary
- Getting Started
- Core Features
- Developer Guide
- Collaboration Guide
- Architecture Reference
- Contributing
Rails Accessibility Testing is the "RSpec + RuboCop" of accessibility for Rails. It fills a critical gap in the Rails testing ecosystem by ensuring applications are accessible to everyone, compliant with WCAG 2.1 AA standards.
Unlike manual audits that happen late in development, this tool integrates directly into your test suite and development workflow, catching violations as you code. It provides:
- 11+ Comprehensive Checks: Covering forms, images, headings, contrast, and more.
- Zero Configuration: Smart defaults that work out of the box.
- Precise Feedback: Pinpoints exact files and lines of code.
- Dual Scanning: Both browser-based (system specs) and static analysis (ERB scanning).
- Ruby 3.0+
- Rails 6.0+
- RSpec Rails (recommended) or Minitest
- Chrome/Chromium browser (for system specs)
Add to your Gemfile:
group :development, :test do
gem 'rails_accessibility_testing'
gem 'rspec-rails', '~> 6.0'
gem 'axe-core-capybara'
gem 'capybara'
gem 'selenium-webdriver'
endRun installation:
bundle install
rails generate rails_a11y:installThis creates:
config/initializers/rails_a11y.rbconfig/accessibility.ymlspec/system/all_pages_accessibility_spec.rb
Configure checks in config/accessibility.yml. You can enable/disable specific checks or adjust severity.
wcag_level: AA
checks:
color_contrast: false # Expensive check, disable in dev if needed
heading: trueThe gem runs 11 key checks automatically:
- Form Labels: Inputs must have labels.
- Image Alt Text: Images must have descriptions.
- Interactive Elements: Links/buttons need names.
- Heading Hierarchy: Logical H1-H6 structure.
- Keyboard Accessibility: No keyboard traps.
- ARIA Landmarks: Proper page structure.
- Form Errors: Errors linked to fields.
- Table Structure: Headers required.
- Duplicate IDs: Unique IDs required.
- Skip Links: Navigation bypass links.
- Color Contrast: Text readability.
Scans pages as you browse in development.
Add to Procfile.dev:
a11y: bundle exec a11y_static_scannerScans ERB templates directly without a browser for instant feedback. Run it manually:
bundle exec a11y_static_scannerSemantic HTML is key.
- Use
<button>for actions,<a>for navigation. - Use proper heading levels (
<h1>-><h6>). - Ensure forms have
<label>elements linked viaforattribute.
Example (Good):
<%= form_with model: @user do |f| %>
<%= f.label :email, "Email Address" %>
<%= f.email_field :email %>
<% end %>Example (Bad):
<!-- Missing Label -->
<%= f.email_field :email, placeholder: "Email" %>Recommended way to test. Checks run automatically on page visits.
RSpec.describe 'Home Page', type: :system do
it 'is accessible' do
visit root_path
expect(page).to have_content('Welcome')
# Checks run automatically here!
end
endAccessibility is a team effort.
- Contrast: Ensure text meets 4.5:1 contrast ratio.
- Focus States: Design visible focus indicators for all interactive elements.
- Touch Targets: Minimum 44x44px for mobile.
- Alt Text: Describe the meaning of the image, not just the appearance.
- Bad: "image.jpg"
- Good: "Chart showing Q3 sales growth of 15%"
- Link Text: Avoid "Click here". Use descriptive text like "Read our Privacy Policy".
The gem is built on a modular architecture:
- Rule Engine: Orchestrates checks.
- Violation Collector: Aggregates issues.
- View Detector: Maps URLs back to source files.
- Static Scanner: fast ERB parsing using Nokogiri.
See ARCHITECTURE.md in the repo for deep dive diagrams.
We welcome contributions!
- Fork the repo.
- Create a feature branch.
- Run tests (
bundle exec rspec). - Submit a Pull Request.
Please adhere to the Code of Conduct.
Generated for project documentation purposes.