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
end

I 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: , , ,

<!- technorati tags end ->

Comments

  1. Matt said 12 days later:

    The url listed in the post does not work. You must use http://www.eric-stewart.com/svn/rails/plugins/assert_accessible/ .

  2. Eric said 13 days later:

    Thanks. The urls have been corrected.

  3. Simon said 4 months later:

    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 = []
    • unless validitychecksdisabled?
    • errors = []

    • filename = File.join Dir::tmpdir, ‘accresponse.’ + MD5.md5(fragment).to_s

    • begin
    • response = File.open filename do |f| Marshal.load(f) end
    • rescue
    • fragmentfilename = File.join Dir::tmpdir, ‘accfragment.’ + MD5.md5(fragment).tos
    • filename = File.join Dir::tmpdir, ‘accresponse.’ + MD5.md5(fragment).to_s
    • begin
    • response = File.open filename do |f| Marshal.load(f) end
    • rescue
    • fragmentfilename = File.join Dir::tmpdir, ‘accfragment.’ + MD5.md5(fragment).tos

    • file = File.open(fragment_filename, ‘w’)

    • file.write(fragment)
    • file.close
    • file = File.open(fragment_filename, ‘w’)
    • file.write(fragment)
    • file.close

    • wa = WebAim::AccessibilityValidator.new

    • response = wa.upload(fragment_filename)
    • wa = WebAim::AccessibilityValidator.new
    • response = wa.upload(fragment_filename)

    • File.open filename, ‘w+’ do |f| Marshal.dump response, f end

    • begin
    • errors = WebAim::AccessibilityValidator::scanforerrors(response.body)
    • rescue => error
    • assert false, “Exception reported attempting to check accessibility: #{error.to_s}”
    • end
    • end
    • File.open filename, ‘w+’ do |f| Marshal.dump response, f end
    • begin
    • errors = WebAim::AccessibilityValidator::scanforerrors(response.body)
    • rescue => error
    • assert false, “Exception reported attempting to check accessibility: #{error.to_s}”
    • 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?

    • message = page_is_accessible ? ” : errors.collect { |error| error + “\n” }.join(“\n”)
    • assert page_is_accessible, message
    • end end

      Class-level method to quickly create validation tests for a bunch of actions at once.

      @@ -65,6 +66,9 @@ end end

      • def validitychecksdisabled?
    • ENV[“NONET”] == ‘true’
    • end
    • private :validitychecksdisabled? end

(leave url/email »)

   Comment Markup Help Preview comment