views:

20

answers:

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

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"

Tian