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

发布于 2024-09-09 04:04:08 字数 818 浏览 1 评论 0原文

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

喜欢 (#) 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}) %>)

Currently I have a like/dislike voting functionality that outputs in the following format:

like (#) dislike (#)

Where like and dislike are clickable links that update the total count of like/dislike votes (represented by (#))

I am writing a cucumber test to check the like/dislike counts are correct. I'd like to check

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

However, my cucumber test isn't pass. Does anyone have any advice? The view is below:

<%= 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}) %>)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2024-09-16 04:04:08

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

通过标记评论

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

然后我可以将黄瓜测试直接指向第 2 节中的喜欢/不喜欢对
然后我应该在“#comment_2”中看到“喜欢(2)不喜欢(0)”

I had multiple like/dislikes in the same page, and my test wasn't passing because it need to check the second comment. The solution is using tag attributes to denote different comments.

By labeling comments

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

Then I can direct cucumber test to the like/dislike pair in section 2 by
Then I should see "like (2) dislike (0)" within "#comment_2"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文