Rails Accessibility Testing
The RSpec + RuboCop of accessibility for Rails. Catch WCAG violations before they reach production.
Version: 1.5.5
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.
π― Positioning
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.
β¨ Features
Core Capabilities
- π Zero Configuration - Works out of the box with smart defaults
- π― 11+ Comprehensive Checks - WCAG 2.1 AA aligned
- π Precise File Location - Know exactly which view file or partial to fix
- π§ Actionable Error Messages - Code examples showing how to fix issues
- π¨ Beautiful CLI - Human-readable and JSON reports
- π Rails Generator - One command setup
- π§ͺ RSpec & Minitest - Works with both test frameworks
- βοΈ YAML Configuration - Profile-based config (dev/test/CI)
π Version 1.5.0+ Highlights
π Static File Scanner (NEW)
- Fast file-based scanning: Scans ERB templates directly without browser rendering
- Smart change detection: Only scans files that have changed since last scan
- Precise error reporting: Shows exact file locations and line numbers
- Continuous monitoring: Watches for file changes and re-scans automatically
- YAML configuration: Fully configurable via
config/accessibility.yml - Reuses existing checks: Leverages all 11 accessibility checks via RuleEngine
π― Live Accessibility Scanner
- Real-time scanning: Automatically scans pages as you browse during development
- Smart cancellation: Cancels scans when you navigate to new pages, focusing on current page
- Integrated workflow: Works seamlessly with
bin/devvia Procfile.dev - Detailed reporting: Shows exactly whatβs being scanned with page URLs and view files
π Enhanced Error Reporting
- View file priority: Rails view files shown prominently instead of URLs
- Comprehensive summaries: Overall test report showing all pages tested with statistics
- Accurate error counting: Properly tracks and displays error/warning counts
- Persistent output: Errors stay visible in terminal (no clearing)
π Quick Start
Installation
Add to your Gemfile:
group :development, :test do
gem 'rails_accessibility_testing'
gem 'rspec-rails', '~> 8.0' # Required for system specs
gem 'axe-core-capybara', '~> 4.0'
gem 'capybara', '~> 3.40'
gem 'selenium-webdriver', '~> 4.0'
gem 'webdrivers', '~> 5.0' # Optional but recommended
gem 'csv' # Required for Ruby 3.3+ (CSV removed from standard library in Ruby 3.4)
end
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.
Then run:
bundle install
Setup (Option 1: Generator - Recommended)
rails generate rails_a11y:install
This creates:
config/initializers/rails_a11y.rb- Configurationconfig/accessibility.yml- Check settingsspec/system/all_pages_accessibility_spec.rb- Comprehensive spec that dynamically tests all GET routes- Updates
spec/rails_helper.rb(if using RSpec) - Updates
Procfile.devwith static accessibility scanner (a11y_static_scanner)
π Usage
System Specs (Recommended)
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.
Create system specs for your pages:
# spec/system/home_page_accessibility_spec.rb
require 'rails_helper'
RSpec.describe 'Home Page Accessibility', type: :system do
it 'loads successfully and passes comprehensive accessibility checks' do
visit root_path
expect(page).to have_content('Welcome')
# Run comprehensive accessibility checks
check_comprehensive_accessibility
# β
Comprehensive accessibility checks (11 checks) also run automatically after this test!
end
end
Accessibility checks run automatically after each visit in system specs!
Continuous Development Testing
The generator automatically adds a static accessibility scanner to your Procfile.dev:
web: bin/rails server
css: bin/rails dartsass:watch
a11y: bundle exec a11y_static_scanner
Then run:
bin/dev
This will:
- Start your Rails server
- Watch for CSS changes
- Continuously scan view files for accessibility issues - Only scans files that have changed since last scan
- Shows errors with exact file locations and line numbers
π― What Gets Checked
The gem automatically runs 11 comprehensive accessibility checks:
- β Form Labels - All form inputs have associated labels
- β Image Alt Text - All images have descriptive alt attributes
- β Interactive Elements - Buttons, links have accessible names (including links with images that have alt text)
- β Heading Hierarchy - Proper h1-h6 structure (detects missing h1, multiple h1s, skipped levels, and h2+ without h1)
- β Keyboard Accessibility - All interactive elements keyboard accessible
- β ARIA Landmarks - Proper use of ARIA landmark roles
- β Form Error Associations - Errors linked to form fields
- β Table Structure - Tables have proper headers
- β Duplicate IDs - No duplicate ID attributes
- β Skip Links - Skip navigation links present (detects various patterns)
- β Color Contrast - Text meets contrast requirements (optional)
π Documentation
- Getting Started - Quick start guide
- Architecture - Visual diagrams and internal architecture
- Configuration - Configuration options
- CI Integration - CI/CD setup
- Contributing - How to contribute
Additional Guides
- System Specs for Accessibility - β Recommended approach
- Writing Accessible Views - Best practices
- Working with Designers - Team collaboration
π Support
- Issues: GitHub Issues
- Email: imregan@umich.edu
- Documentation: See GUIDES directory
Made with β€οΈ for accessible Rails applications
Rails Accessibility Testing helps teams build accessible applications from day one, not as an afterthought.