如何使用 rspec 测试 html 属性? [英] how to test html attributes with rspec?
本文介绍了如何使用 rspec 测试 html 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我拥有的 html 是由 ruby 生成的:
the html I have is generated by ruby with:
<%= link_to "change", "http://gravatar.com/emails" %>
导致:
<a href="http://gravatar.com/emails">change</a>
但我想确保链接在带有
but I want to ensure that the link opens in a new tab with the
target="blank"
属性
rspec 测试看起来像:
the rspec test looks like:
it { should have_link('change', href: 'http://gravatar.com/emails', target: '_blank') }
但是当我没有生成目标属性时,测试仍然通过.
but the test still passes when I don't have the target attribute being generated.
推荐答案
以下适用于水豚 1.1.2:
The following works for me with capybara 1.1.2:
it { should have_selector("a[href='http://gravatar.com/emails'][target='_blank']") }
这篇关于如何使用 rspec 测试 html 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文