如何用rspec测试html属性? [英] how to test html attributes with rspec?

查看:137
本文介绍了如何用rspec测试html属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/gravatar.com/emails%>

导致:

 < a href =http://gravatar.com/emails>更改< / a> 

但是我想要确保链接在新标签中打开

  target =blank

属性



rspec测试看起来像:

  it { should have_link('change',href:'http://gravatar.com/emails',target:'_blank')} 

但是当我没有生成目标属性时,测试依然通过。

解决方案

以下为我与水豚1.1.2的作品:

  it {should have_selector(a [href ='http:// gravatar .com / emails'] [target ='_ blank'])} 


the html I have is generated by ruby with:

<%= link_to "change", "http://gravatar.com/emails" %>

which results in:

<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"

attribute

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.

解决方案

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屋!

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