RSpec 2查看测试以验证可访问标记? [英] RSpec 2 View test to validate accessible markup?

查看:95
本文介绍了RSpec 2查看测试以验证可访问标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在RSpec中进行一些基本的可访问性测试(显然,稍后将由其他工具和用户进行验证;这是为了抓住低挂的果实,例如查找不带alt标签的图像等)

I want to make some basic accessibility tests in RSpec (obviously, to be further validated by other tools and users later; this is to catch the low-hanging fruit like finding images w/o alt tags and such)

大多数示例只是检查内容是否相似;我想要做的是获取一个标签列表,然后断言所找到的所有标签都符合特定条件(例如,所有图像必须具有alt或longdesc;每个表单输入都需要标签或标题,等等)。

Most of the examples have just checking content is present is similar; what I want to do is get a list of tags, and then make assertions that "all" the tags found meet certain criteria (e.g. all images have to have either an alt or a longdesc; each form input needs either a label or title, etc).

RSpec可以做到这一点吗?如果没有,是否可以使用一种工具?

Can RSpec do this, or if not, is there a tool that can?

谢谢。 p>

Thanks.

推荐答案

您可以使用 webrat 在您的视图规格上测试XPath选择器:

You can use webrat to test for XPath selectors on your view specs:

describe 'my/view.html.erb' do
  it 'should not have images without alt or longdesc attributes' do
    render
    rendered.should_not have_xpath('//img[not(@alt) and not(@longdesc)]')
  end
end

水豚也支持XPath选择器。

Capybara supports XPath selectors, too.

这篇关于RSpec 2查看测试以验证可访问标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆