Webrat / Cucumber Matcher - 测试内容与链接匹配

时间:2010-07-13 19:55:13

标签: ruby-on-rails cucumber webrat

目前,我有一个喜欢/不喜欢的投票功能,其输出格式如下:

like(#)dislike(#)

喜欢和不喜欢可点击的链接,更新喜欢/不喜欢投票的总数(由(#)表示)

我正在写一个黄瓜测试来检查喜欢/不喜欢的计数是否正确。我想检查一下

...
Then I should see "like (2) dislike (0)"

然而,我的黄瓜测试没有通过。有人有建议吗?视图如下:

<%= link_to "like", url_for(:action => 'like', :controller => 'comments', :id => c.id) %> 
(<%= c.comment_votes.nil? ? 0 : c.comment_votes.count(:conditions => {:score => 1}) %>)
<%= link_to "dislike", url_for(:action => 'dislike', :controller => 'comments', :id => c.id) %> 
(<%= c.comment_votes.nil? ? 0 : c.comment_votes.count(:conditions => {:score => -1}) %>)

1 个答案:

答案 0 :(得分:0)

我在同一页面上有多个喜欢/不喜欢,我的测试没有通过,因为它需要检查第二个评论。解决方案是使用标记属性来表示不同的注释。

通过标记评论

<tr id = "comment_1">
like (0) like (1)
<tr id = "comment_2">
like (2) like (0)
...

然后我可以将黄瓜测试指向第2部分中的喜欢/不喜欢对     然后我应该在“#comment_2”

中看到“喜欢(2)不喜欢(0)”