rails_accessibility_testing 1.4.2 → 1.5.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 +4 -4
- data/ARCHITECTURE.md +212 -53
- data/CHANGELOG.md +135 -0
- data/GUIDES/getting_started.md +171 -9
- data/GUIDES/system_specs_for_accessibility.md +13 -12
- data/README.md +139 -36
- data/docs_site/getting_started.md +142 -18
- data/docs_site/index.md +1 -1
- data/exe/a11y_live_scanner +361 -0
- data/exe/rails_server_safe +18 -1
- data/lib/generators/rails_a11y/install/install_generator.rb +137 -0
- data/lib/rails_accessibility_testing/accessibility_helper.rb +547 -24
- data/lib/rails_accessibility_testing/change_detector.rb +17 -104
- data/lib/rails_accessibility_testing/checks/base_check.rb +56 -7
- data/lib/rails_accessibility_testing/checks/heading_check.rb +138 -0
- data/lib/rails_accessibility_testing/checks/image_alt_text_check.rb +7 -7
- data/lib/rails_accessibility_testing/checks/interactive_elements_check.rb +11 -1
- data/lib/rails_accessibility_testing/cli/command.rb +3 -1
- data/lib/rails_accessibility_testing/config/yaml_loader.rb +1 -1
- data/lib/rails_accessibility_testing/engine/rule_engine.rb +49 -5
- data/lib/rails_accessibility_testing/error_message_builder.rb +63 -7
- data/lib/rails_accessibility_testing/middleware/page_visit_logger.rb +81 -0
- data/lib/rails_accessibility_testing/railtie.rb +22 -0
- data/lib/rails_accessibility_testing/rspec_integration.rb +176 -10
- data/lib/rails_accessibility_testing/version.rb +1 -1
- data/lib/rails_accessibility_testing.rb +8 -3
- metadata +8 -4
- data/lib/generators/rails_a11y/install/generator.rb +0 -51
- data/lib/rails_accessibility_testing/checks/heading_hierarchy_check.rb +0 -53
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators/base'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
|
|
6
|
+
module RailsA11y
|
|
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
|
+
rails_helper_content = File.read(rails_helper_path)
|
|
32
|
+
|
|
33
|
+
# Add rails_accessibility_testing require
|
|
34
|
+
unless rails_helper_content.include?("require 'rails_accessibility_testing'")
|
|
35
|
+
inject_into_file rails_helper_path,
|
|
36
|
+
after: "require 'rspec/rails'\n" do
|
|
37
|
+
"require 'rails_accessibility_testing'\n"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
say "⚠️ spec/rails_helper.rb not found. Please add: require 'rails_accessibility_testing'", :yellow
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def create_all_pages_spec
|
|
46
|
+
spec_path = 'spec/system/all_pages_accessibility_spec.rb'
|
|
47
|
+
|
|
48
|
+
if File.exist?(spec_path)
|
|
49
|
+
say "⚠️ #{spec_path} already exists. Skipping creation.", :yellow
|
|
50
|
+
else
|
|
51
|
+
template 'all_pages_accessibility_spec.rb.erb', spec_path
|
|
52
|
+
say "✅ Created #{spec_path}", :green
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def update_procfile_dev
|
|
57
|
+
procfile_path = 'Procfile.dev'
|
|
58
|
+
|
|
59
|
+
if File.exist?(procfile_path)
|
|
60
|
+
procfile_content = File.read(procfile_path)
|
|
61
|
+
|
|
62
|
+
# Check if a11y line already exists
|
|
63
|
+
unless procfile_content.include?('a11y:')
|
|
64
|
+
# Add live scanner to Procfile.dev
|
|
65
|
+
a11y_line = "a11y: bundle exec a11y_live_scanner\n"
|
|
66
|
+
procfile_content += a11y_line
|
|
67
|
+
File.write(procfile_path, procfile_content)
|
|
68
|
+
say "✅ Added live accessibility scanner to #{procfile_path}", :green
|
|
69
|
+
say " 💡 Run 'bin/dev' to start live scanning as you browse pages", :cyan
|
|
70
|
+
else
|
|
71
|
+
say "⚠️ Procfile.dev already contains an a11y entry. Skipping.", :yellow
|
|
72
|
+
end
|
|
73
|
+
else
|
|
74
|
+
# Create Procfile.dev if it doesn't exist
|
|
75
|
+
procfile_content = <<~PROCFILE
|
|
76
|
+
web: bin/rails server
|
|
77
|
+
a11y: bundle exec a11y_live_scanner
|
|
78
|
+
PROCFILE
|
|
79
|
+
|
|
80
|
+
File.write(procfile_path, procfile_content)
|
|
81
|
+
say "✅ Created #{procfile_path} with live accessibility scanner", :green
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def update_gitignore
|
|
86
|
+
gitignore_path = '.gitignore'
|
|
87
|
+
|
|
88
|
+
if File.exist?(gitignore_path)
|
|
89
|
+
gitignore_content = File.read(gitignore_path)
|
|
90
|
+
|
|
91
|
+
# Add tmp files for live scanner if not already present
|
|
92
|
+
a11y_entries = [
|
|
93
|
+
'tmp/a11y_page_visits.log',
|
|
94
|
+
'tmp/a11y_scanned_pages.json'
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
a11y_entries.each do |entry|
|
|
98
|
+
unless gitignore_content.include?(entry)
|
|
99
|
+
gitignore_content += "\n#{entry}\n"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
File.write(gitignore_path, gitignore_content) if gitignore_content != File.read(gitignore_path)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def show_instructions
|
|
108
|
+
say "\n✅ Rails Accessibility Testing installed successfully!", :green
|
|
109
|
+
say "\n📋 Next Steps:", :yellow
|
|
110
|
+
say ""
|
|
111
|
+
say " 1. Run the accessibility tests:", :cyan
|
|
112
|
+
say " bundle exec rspec spec/system/all_pages_accessibility_spec.rb"
|
|
113
|
+
say ""
|
|
114
|
+
say " 2. For live scanning during development:", :cyan
|
|
115
|
+
say " bin/dev # Starts web server + live accessibility scanner"
|
|
116
|
+
say " # Navigate to pages in your browser to see real-time reports!"
|
|
117
|
+
say ""
|
|
118
|
+
say " 3. Create custom specs for specific pages:", :cyan
|
|
119
|
+
say " # spec/system/my_page_accessibility_spec.rb"
|
|
120
|
+
say " RSpec.describe 'My Page', type: :system do"
|
|
121
|
+
say " it 'is accessible' do"
|
|
122
|
+
say " visit my_page_path"
|
|
123
|
+
say " check_comprehensive_accessibility"
|
|
124
|
+
say " end"
|
|
125
|
+
say " end"
|
|
126
|
+
say ""
|
|
127
|
+
say " 4. Configure which checks run in config/accessibility.yml", :cyan
|
|
128
|
+
say ""
|
|
129
|
+
say " 5. Accessibility checks run automatically after each 'visit' in system specs!", :cyan
|
|
130
|
+
say ""
|
|
131
|
+
say "📚 Documentation:", :yellow
|
|
132
|
+
say " • README: https://github.com/rayraycodes/rails-accessibility-testing"
|
|
133
|
+
say ""
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|