我正在编写一个请求规范,并想测试字符串“Reports » Aging Reports”是否存在。如果我直接将字符放入匹配器表达式中,我会收到错误(无效的多字节字符),所以我尝试了以下操作:page.should have_content("Reports » Aging Reports")
测试失败并显示以下消息:
expected there to be content "Reports » Aging Reports" in "\n Reports » Aging Reports\n
我尝试过类似的事情.html_safe
没有成功。有没有办法测试包含 html 实体的文本?
Edit:
这是 html 源的相关区域:
<a href="/reports">Reports</a> » <a href="/aging_reports">Aging Reports</a>
您也可以让测试查看页面的原始源代码:
breadcrumb = '<a href="/reports">Reports</a> » <a href="/aging_reports">Aging Reports</a>'
page.body.should include(breadcrumb)
expect(page.body).to include(breadcrumb) # rspec 2.11+
话虽如此,我不确定这是最优雅的解决方案。假设有一个类名为.breadcrumb
在链接周围,您可以验证 div 中是否存在链接:
within '.breadcrumb' do
page.should have_css('a', text: 'Reports')
page.should have_css('a', text: 'Aging Reports')
expect(page).to have_css('a', text: 'Reports') # rspec 2.11+
expect(page).to have_css('a', text: 'Aging Reports') # rspec 2.11+
end
这样,您就可以在面包屑块中明确查找 href。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)