rails_accessibility_testing 1.1.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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/ARCHITECTURE.md +307 -0
  3. data/CHANGELOG.md +81 -0
  4. data/CODE_OF_CONDUCT.md +125 -0
  5. data/CONTRIBUTING.md +225 -0
  6. data/GUIDES/continuous_integration.md +326 -0
  7. data/GUIDES/getting_started.md +205 -0
  8. data/GUIDES/working_with_designers_and_content_authors.md +398 -0
  9. data/GUIDES/writing_accessible_views_in_rails.md +412 -0
  10. data/LICENSE +22 -0
  11. data/README.md +350 -0
  12. data/docs_site/404.html +11 -0
  13. data/docs_site/Gemfile +11 -0
  14. data/docs_site/Makefile +14 -0
  15. data/docs_site/_config.yml +41 -0
  16. data/docs_site/_includes/header.html +13 -0
  17. data/docs_site/_layouts/default.html +130 -0
  18. data/docs_site/assets/main.scss +4 -0
  19. data/docs_site/ci_integration.md +76 -0
  20. data/docs_site/configuration.md +114 -0
  21. data/docs_site/contributing.md +69 -0
  22. data/docs_site/getting_started.md +57 -0
  23. data/docs_site/index.md +57 -0
  24. data/exe/rails_a11y +12 -0
  25. data/exe/rails_server_safe +41 -0
  26. data/lib/generators/rails_a11y/install/generator.rb +51 -0
  27. data/lib/rails_accessibility_testing/accessibility_helper.rb +701 -0
  28. data/lib/rails_accessibility_testing/change_detector.rb +114 -0
  29. data/lib/rails_accessibility_testing/checks/aria_landmarks_check.rb +33 -0
  30. data/lib/rails_accessibility_testing/checks/base_check.rb +156 -0
  31. data/lib/rails_accessibility_testing/checks/color_contrast_check.rb +56 -0
  32. data/lib/rails_accessibility_testing/checks/duplicate_ids_check.rb +49 -0
  33. data/lib/rails_accessibility_testing/checks/form_errors_check.rb +40 -0
  34. data/lib/rails_accessibility_testing/checks/form_labels_check.rb +62 -0
  35. data/lib/rails_accessibility_testing/checks/heading_hierarchy_check.rb +53 -0
  36. data/lib/rails_accessibility_testing/checks/image_alt_text_check.rb +52 -0
  37. data/lib/rails_accessibility_testing/checks/interactive_elements_check.rb +66 -0
  38. data/lib/rails_accessibility_testing/checks/keyboard_accessibility_check.rb +36 -0
  39. data/lib/rails_accessibility_testing/checks/skip_links_check.rb +24 -0
  40. data/lib/rails_accessibility_testing/checks/table_structure_check.rb +36 -0
  41. data/lib/rails_accessibility_testing/cli/command.rb +259 -0
  42. data/lib/rails_accessibility_testing/config/yaml_loader.rb +131 -0
  43. data/lib/rails_accessibility_testing/configuration.rb +30 -0
  44. data/lib/rails_accessibility_testing/engine/rule_engine.rb +97 -0
  45. data/lib/rails_accessibility_testing/engine/violation.rb +58 -0
  46. data/lib/rails_accessibility_testing/engine/violation_collector.rb +59 -0
  47. data/lib/rails_accessibility_testing/error_message_builder.rb +354 -0
  48. data/lib/rails_accessibility_testing/integration/minitest_integration.rb +74 -0
  49. data/lib/rails_accessibility_testing/rspec_integration.rb +58 -0
  50. data/lib/rails_accessibility_testing/shared_examples.rb +93 -0
  51. data/lib/rails_accessibility_testing/version.rb +4 -0
  52. data/lib/rails_accessibility_testing.rb +83 -0
  53. data/lib/tasks/accessibility.rake +28 -0
  54. metadata +218 -0
@@ -0,0 +1,114 @@
1
+ ---
2
+ layout: default
3
+ title: Configuration
4
+ ---
5
+
6
+ # Configuration
7
+
8
+ Rails Accessibility Testing works out of the box with zero configuration, but you can customize it to fit your needs.
9
+
10
+ ## YAML Configuration
11
+
12
+ Create `config/accessibility.yml` in your Rails app:
13
+
14
+ ```yaml
15
+ # WCAG compliance level (A, AA, AAA)
16
+ wcag_level: AA
17
+
18
+ # Global check configuration
19
+ checks:
20
+ form_labels: true
21
+ image_alt_text: true
22
+ interactive_elements: true
23
+ heading_hierarchy: true
24
+ keyboard_accessibility: true
25
+ aria_landmarks: true
26
+ form_errors: true
27
+ table_structure: true
28
+ duplicate_ids: true
29
+ skip_links: true
30
+ color_contrast: false # Disabled by default (expensive)
31
+
32
+ # Profile-specific configurations
33
+ development:
34
+ checks:
35
+ color_contrast: false # Skip in dev for speed
36
+
37
+ test:
38
+ checks:
39
+ # Test environment uses global settings by default
40
+
41
+ ci:
42
+ checks:
43
+ color_contrast: true # Full checks in CI
44
+
45
+ # Ignored rules with reasons
46
+ ignored_rules:
47
+ # - rule: form_labels
48
+ # reason: "Legacy form, scheduled for refactor in Q2"
49
+ # comment: "Will be fixed in PR #123"
50
+ ```
51
+
52
+ ## Ruby Configuration
53
+
54
+ Edit `config/initializers/rails_a11y.rb`:
55
+
56
+ ```ruby
57
+ RailsAccessibilityTesting.configure do |config|
58
+ # Automatically run checks after system specs
59
+ config.auto_run_checks = true
60
+
61
+ # Logger for accessibility check output
62
+ config.logger = Rails.logger
63
+
64
+ # Configuration file path (relative to Rails.root)
65
+ config.config_path = 'config/accessibility.yml'
66
+
67
+ # Default profile to use (development, test, ci)
68
+ config.default_profile = :test
69
+ end
70
+ ```
71
+
72
+ ## Profiles
73
+
74
+ Use different configurations for different environments:
75
+
76
+ - **development**: Faster checks, skip expensive operations
77
+ - **test**: Default settings, balanced checks
78
+ - **ci**: Full checks, strict validation
79
+
80
+ Set the profile via environment variable:
81
+
82
+ ```bash
83
+ RAILS_A11Y_PROFILE=ci bundle exec rspec spec/system/
84
+ ```
85
+
86
+ ## Ignoring Rules
87
+
88
+ Temporarily ignore specific rules while fixing issues:
89
+
90
+ ```yaml
91
+ ignored_rules:
92
+ - rule: form_labels
93
+ reason: "Legacy form, scheduled for refactor in Q2"
94
+ comment: "Will be fixed in PR #123"
95
+ ```
96
+
97
+ **Important:** Always include a reason and plan to fix. This is for temporary exceptions, not permanent workarounds.
98
+
99
+ ## Skipping Checks in Tests
100
+
101
+ Skip accessibility checks for specific tests:
102
+
103
+ ```ruby
104
+ # RSpec
105
+ it "does something", skip_a11y: true do
106
+ # Accessibility checks won't run
107
+ end
108
+
109
+ # Minitest
110
+ test "does something", skip_a11y: true do
111
+ # Accessibility checks won't run
112
+ end
113
+ ```
114
+
@@ -0,0 +1,69 @@
1
+ ---
2
+ layout: default
3
+ title: Contributing
4
+ ---
5
+
6
+ # Contributing to Rails Accessibility Testing
7
+
8
+ Thank you for your interest in contributing to Rails Accessibility Testing! This document provides guidelines and instructions for contributing.
9
+
10
+ ## Getting Started
11
+
12
+ ### Prerequisites
13
+
14
+ - Ruby 3.0+ installed
15
+ - Bundler installed
16
+ - Git installed
17
+ - A GitHub account
18
+
19
+ ### Setting Up Development Environment
20
+
21
+ 1. **Fork the repository**
22
+ 2. **Clone your fork**
23
+ ```bash
24
+ git clone https://github.com/your-username/rails-accessibility-testing.git
25
+ cd rails-accessibility-testing
26
+ ```
27
+
28
+ 3. **Install dependencies**
29
+ ```bash
30
+ bundle install
31
+ ```
32
+
33
+ 4. **Run tests**
34
+ ```bash
35
+ bundle exec rspec
36
+ ```
37
+
38
+ ## Making Changes
39
+
40
+ 1. **Create a branch**
41
+ ```bash
42
+ git checkout -b feature/your-feature-name
43
+ ```
44
+
45
+ 2. **Make your changes**
46
+ - Write code
47
+ - Add tests
48
+ - Update documentation
49
+
50
+ 3. **Test your changes**
51
+ ```bash
52
+ bundle exec rspec
53
+ ```
54
+
55
+ 4. **Commit your changes**
56
+ ```bash
57
+ git add .
58
+ git commit -m "Add: descriptive commit message"
59
+ ```
60
+
61
+ 5. **Push to your fork**
62
+ ```bash
63
+ git push origin feature/your-feature-name
64
+ ```
65
+
66
+ 6. **Open a Pull Request**
67
+
68
+ For complete contributing guidelines, see [CONTRIBUTING.md](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/CONTRIBUTING.md) in the main repository.
69
+
@@ -0,0 +1,57 @@
1
+ ---
2
+ layout: default
3
+ title: Getting Started
4
+ ---
5
+
6
+ # Getting Started with Rails Accessibility Testing
7
+
8
+ Welcome to Rails Accessibility Testing! This guide will help you get up and running with accessibility testing in your Rails application in just a few minutes.
9
+
10
+ ## What is Rails Accessibility Testing?
11
+
12
+ Rails Accessibility Testing is an accessibility testing gem that automatically checks your Rails views for WCAG 2.1 AA compliance. Think of it as RSpec + RuboCop for accessibility—it catches violations as you code, not after deployment.
13
+
14
+ ## Quick Start (5 Minutes)
15
+
16
+ ### Step 1: Install the Gem
17
+
18
+ Add to your `Gemfile`:
19
+
20
+ ```ruby
21
+ group :development, :test do
22
+ gem 'rails_accessibility_testing'
23
+ gem 'axe-core-capybara', '~> 4.0'
24
+ end
25
+ ```
26
+
27
+ Then run:
28
+
29
+ ```bash
30
+ bundle install
31
+ ```
32
+
33
+ ### Step 2: Run the Generator
34
+
35
+ ```bash
36
+ rails generate rails_a11y:install
37
+ ```
38
+
39
+ **Note:** The generator uses the short name `rails_a11y` for convenience. The gem name is `rails_accessibility_testing`.
40
+
41
+ This creates:
42
+ - `config/initializers/rails_a11y.rb` - Configuration
43
+ - `config/accessibility.yml` - Check settings
44
+ - Updates `spec/rails_helper.rb` (if using RSpec)
45
+
46
+ ### Step 3: Run Your Tests
47
+
48
+ That's it! Just run your system specs:
49
+
50
+ ```bash
51
+ bundle exec rspec spec/system/
52
+ ```
53
+
54
+ Accessibility checks run automatically on every system test that visits a page.
55
+
56
+ For complete documentation, see the [Getting Started guide](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/GUIDES/getting_started.md) in the main repository.
57
+
@@ -0,0 +1,57 @@
1
+ ---
2
+ layout: default
3
+ title: Home
4
+ ---
5
+
6
+ # Rails Accessibility Testing
7
+
8
+ **The RSpec + RuboCop of accessibility for Rails. Catch WCAG violations before they reach production.**
9
+
10
+ **Version:** 1.1.0
11
+
12
+ Rails Accessibility Testing is a comprehensive accessibility testing gem that makes accessibility testing as natural as unit testing. It integrates seamlessly into your Rails workflow, catching WCAG 2.1 AA violations as you code—not after deployment.
13
+
14
+ ## Quick Start
15
+
16
+ ```ruby
17
+ # Add to Gemfile
18
+ group :development, :test do
19
+ gem 'rails_accessibility_testing'
20
+ gem 'axe-core-capybara', '~> 4.0'
21
+ end
22
+ ```
23
+
24
+ ```bash
25
+ # Install
26
+ bundle install
27
+
28
+ # Setup
29
+ rails generate rails_a11y:install
30
+
31
+ # Run tests
32
+ bundle exec rspec spec/system/
33
+ ```
34
+
35
+ ## Features
36
+
37
+ - **Zero Configuration** - Works out of the box with smart defaults
38
+ - **11+ Comprehensive Checks** - WCAG 2.1 AA aligned
39
+ - **Actionable Error Messages** - Code examples showing how to fix issues
40
+ - **RSpec & Minitest** - Works with both test frameworks
41
+ - **CLI Tool** - Command-line interface for scanning URLs and routes
42
+ - **YAML Configuration** - Profile-based configuration for different environments
43
+
44
+ ## Documentation
45
+
46
+ - [Getting Started]({{ '/getting_started.html' | relative_url }}) - Quick start guide
47
+ - [Configuration]({{ '/configuration.html' | relative_url }}) - Configuration options
48
+ - [CI Integration]({{ '/ci_integration.html' | relative_url }}) - CI/CD setup
49
+ - [Contributing]({{ '/contributing.html' | relative_url }}) - How to contribute
50
+
51
+ ## Links
52
+
53
+ - [GitHub Repository](https://github.com/rayraycodes/rails-accessibility-testing)
54
+ - [RubyGems](https://rubygems.org/gems/rails_accessibility_testing)
55
+ - [Issue Tracker](https://github.com/rayraycodes/rails-accessibility-testing/issues)
56
+ - [Changelog](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/CHANGELOG.md)
57
+
data/exe/rails_a11y ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Load the gem
5
+ require_relative '../lib/rails_accessibility_testing'
6
+
7
+ # Load CLI command
8
+ require_relative '../lib/rails_accessibility_testing/cli/command'
9
+
10
+ # Run the CLI
11
+ RailsAccessibilityTesting::CLI::Command.run(ARGV)
12
+
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # Safe wrapper for Rails server that doesn't fail if server is already running
4
+ # This prevents Foreman from terminating all processes when server is already up
5
+
6
+ PIDFILE="${PIDFILE:-tmp/pids/server.pid}"
7
+ PORT="${PORT:-3000}"
8
+
9
+ # Check if PID file exists
10
+ if [ -f "$PIDFILE" ]; then
11
+ PID=$(cat "$PIDFILE" 2>/dev/null)
12
+
13
+ # Check if the process is actually running
14
+ if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
15
+ # Check if it's listening on the expected port
16
+ if lsof -ti:$PORT -sTCP:LISTEN | grep -q "^$PID$" 2>/dev/null; then
17
+ echo "Server is already running (pid: $PID, port: $PORT)"
18
+ exit 0
19
+ else
20
+ # PID exists but not listening on port - stale PID file
21
+ echo "Removing stale PID file (pid: $PID not listening on port $PORT)"
22
+ rm -f "$PIDFILE"
23
+ fi
24
+ else
25
+ # PID file exists but process is dead - stale PID file
26
+ echo "Removing stale PID file (process $PID not running)"
27
+ rm -f "$PIDFILE"
28
+ fi
29
+ fi
30
+
31
+ # Check if something else is using the port
32
+ if lsof -ti:$PORT -sTCP:LISTEN >/dev/null 2>&1; then
33
+ EXISTING_PID=$(lsof -ti:$PORT -sTCP:LISTEN | head -1)
34
+ echo "Port $PORT is already in use by process $EXISTING_PID"
35
+ echo "Server may already be running. Exiting gracefully."
36
+ exit 0
37
+ fi
38
+
39
+ # Start the server normally
40
+ exec bin/rails server "$@"
41
+
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ module RailsAccessibilityTesting
6
+ module Generators
7
+ # Generator to install Rails Accessibility Testing
8
+ #
9
+ # Creates initializer and configuration file.
10
+ #
11
+ # @example
12
+ # rails generate rails_a11y:install
13
+ #
14
+ class InstallGenerator < Rails::Generators::Base
15
+ source_root File.expand_path('templates', __dir__)
16
+
17
+ desc "Install Rails A11y: creates initializer and configuration file"
18
+
19
+ def create_initializer
20
+ template 'initializer.rb.erb', 'config/initializers/rails_a11y.rb'
21
+ end
22
+
23
+ def create_config_file
24
+ template 'accessibility.yml.erb', 'config/accessibility.yml'
25
+ end
26
+
27
+ def add_to_rails_helper
28
+ rails_helper_path = 'spec/rails_helper.rb'
29
+
30
+ if File.exist?(rails_helper_path)
31
+ inject_into_file rails_helper_path,
32
+ after: "require 'rspec/rails'\n" do
33
+ "require 'rails_accessibility_testing'\n"
34
+ end
35
+ else
36
+ say "⚠️ spec/rails_helper.rb not found. Please add: require 'rails_accessibility_testing'", :yellow
37
+ end
38
+ end
39
+
40
+ def show_instructions
41
+ say "\n✅ Rails Accessibility Testing installed successfully!", :green
42
+ say "\nNext steps:", :yellow
43
+ say " 1. Run your system specs: bundle exec rspec spec/system/"
44
+ say " 2. Accessibility checks will run automatically"
45
+ say " 3. Configure checks in config/accessibility.yml"
46
+ say "\nFor more information, see: https://github.com/rayraycodes/rails-accessibility-testing"
47
+ end
48
+ end
49
+ end
50
+ end
51
+