开发者

Webrat / Cucumber Matcher - Testing content match with links

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


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜