0

我在 rails 2.3.9 应用程序中使用水豚和黄瓜。

这是我的html代码

<a href="http://twitter.com/dorelal" target="_blank" title="twitter">
  <img alt="twitter" src="/images/social/twitter.png?1284129939" />
</a>

我想验证以下项目

image should be ending with twitter.png
image alt should be "twitter"
link should have href "http://twitter.com/dorelal"
link should have target "_blank"
link should have title "twitter"
4

2 回答 2

1

Capybara 现在支持检查 href 的功能。

https://github.com/jnicklas/capybara/pull/207

于 2010-12-01T22:01:08.353 回答
0

验证链接的最佳方法是让您的驱动程序单击它,然后检查它是否进入了正确的页面。这将使您更加确信您的应用程序没有错误地出错、重定向等。对于不建议在测试中单击链接的特殊情况(例如:如果链接离开现场),我使用以下步骤:

Then I should see a link titled "foo"
Then I should see a link titled "foo" that goes to "http://www.example.org"

Then /^I should see a link titled "(.+?)"(?: that goes to "(.+)")?$/ do |title, target|
  if target.blank?
    page.should have_link(title)
  else
    page.should have_link(title, :href => target)
  end
end

如果您收到“错误数量的参数(2 对 1)”,请更新您的 Capybara 版本。最近添加了 :href => 'bar' 选项。

于 2011-02-28T19:45:38.390 回答