Testing Rails Application Accessibility
Posted by Eric Stewart Wed, 28 Dec 2005 17:35:00 GMT
As I mentioned previously, I have been working on a Rails plugin to help check the accessibility of pages in a Rails project.
I was inspired by Scott Raymond’s assert_valid_markup plugin for Rails and decided to whip up a similar plugin for testing the accessibility of pages in my current Rails project.
Using
You will be able to write a functional test that does something like:def test_index
get :index
assert_accessible
endI had really wanted to polish this some more before putting it out there for others to use, but I have been slow at finding the time so I’m making it available. It has been working well on my current project but there is much that can be done to improve it. It is still really rough around the edges and your mileage may vary.
You will probably get more mileage out of it by pairing it up with assert_valid_markup, as invalid markup usually triggers some sort of accessibility problem.
Installing
Check out the source from Subversion, or preferable use Rails own script/plugin script to help install it. All you have to do (from the root of your rails project) is:
script/plugin source http://www.eric-stewart.com/svn/rails/plugins/
script/plugin install assert_accessible
Or, for those that want to do a straight subversion checkout:
svn co http://www.eric-stewart.com/svn/rails/plugins/assert_accessible/
That’s it! Let me know how it works for you.
Update: The url’s above for subversion weren’t working externally according to an astute commenter. They have been corrected.
<!- technorati tags start ->
Technorati Tags: accessibility, rails, ruby, testing
<!





The url listed in the post does not work. You must use http://www.eric-stewart.com/svn/rails/plugins/assert_accessible/ .
Thanks. The urls have been corrected.
Really handy. Patch below allows use of env[NONET] to skip tests as per assertvalidasset, which is handy
Index: vendor/plugins/accessible/lib/assert_accessible.rb
— vendor/plugins/accessible/lib/assert_accessible.rb (revision 21) +++ vendor/plugins/accessible/lib/assert_accessible.rb (working copy) @@ -20,33 +20,34 @@ # end # def assert_accessible(fragment=@response.body)
errors = []
filename = File.join Dir::tmpdir, ‘accresponse.’ + MD5.md5(fragment).to_s
fragmentfilename = File.join Dir::tmpdir, ‘accfragment.’ + MD5.md5(fragment).tos
file = File.open(fragment_filename, ‘w’)
file.close
wa = WebAim::AccessibilityValidator.new
response = wa.upload(fragment_filename)
File.open filename, ‘w+’ do |f| Marshal.dump response, f end
end
page_is_accessible = errors.empty?
message = page_is_accessible ? ” : errors.collect { |error| error + “\n” }.join(“\n”)
- assert page_is_accessible, message
page_is_accessible = errors.empty?
end end
Class-level method to quickly create validation tests for a bunch of actions at once.
@@ -65,6 +66,9 @@ end end