javascript - Rspec, Capybara: Ambiguous match, found 2 elements matching field 'brief' -


i have implemented inline form show/hide function jquery , few of specs failing. post comments answers , questions, , comments can posted in reply other comments. when form shown, 'add comment' link changes 'cancel' , upon clicking 'cancel', form hidden.

my spec:

scenario 'on answer', js:true     submit_answer @answer.brief     submit_comment @comment_brief, '.answers'     expect(page).to have_content(@idea_brief)     expect(page).to have_content(@question_brief)     expect(page).to have_content(@answer.brief)     expect(page).to have_content(@comment_brief) end scenario 'on comment', js: true     @commentreply = factorygirl.create(:comment)     submit_comment @comment_brief, ".question"     submit_comment @commentreply.brief, '.question-comments', 'reply comment'     expect(page).to have_content(@question_brief)     expect(page).to have_content(@comment_reply) end 

i assume 2 errors identical, having js inline form hide/show.

my failures:

1) visitor submits comment on answer  failure/error: submit_comment @comment_brief, '.answers'  capybara::ambiguous:    ambiguous match, found 2 elements matching field "brief"  # ./spec/support/features/session_helpers.rb:52:in `submit_comment'  # ./spec/features/comment_spec.rb:17:in `block (2 levels) in <top (required)>'  2) visitor submits comment on comment  failure/error: submit_comment @commentreply.brief, '.question-comments', 'reply   comment'  capybara::ambiguous:    ambiguous match, found 2 elements matching field "brief"  # ./spec/support/features/session_helpers.rb:52:in `submit_comment'  # ./spec/features/comment_spec.rb:33:in `block (2 levels) in <top (required)>' 

my partial form answer:

<li class="media answer answer-<%= answer.id %>">      <%= render partial: "evaluations/vote_wrapper", locals: {voteable: answer} %>       <div class="media-body">       <div class="media-item-body">         <%= answer.brief %>       <div class="pull-right">         <%= render answer.user %>       </div>       </div>       <ul class="media-list comments answer-comments">         <% if answer.comments.count > 0 %>           <%= render vote_order(answer.comments.includes(:user)) || "no comments found" %>         <% end %>         <div class="<%= answer.id %>">           <p class="add comment">              <%= link_to "add comment", new_answer_comment_path(answer), remote: true %>           </p>           <p class="comment cancel" style="display:none">             <%= link_to "cancel", new_answer_comment_path(answer), remote: true %>           </p>         </div>       </ul>     </div> </li> 

and finally, new.js.erb comment:

var selector = ".<%= j @commentable.class.to_s.downcase + '-' + @commentable.id.to_s + '  .media-body ' %>" selector0 = selector + ".<%= j @commentable.class.to_s.downcase %>-comments"  var selector1 = ".<%= j @commentable.class.to_s.downcase%>" var selector2 = ".<%= j @commentable.class.to_s.downcase + '-' + @commentable.id.to_s%>" var selector3 = selector1 + selector2 + " div.<%= j @commentable.id.to_s%>"  if($(selector3 + " .add.comment").is(":visible")){          if ($(selector0 + " .js-inline-form").length == 0) {     $(selector0)             .append("<li class='js-inline-form'><%= j render :partial => 'comments/form' %></li>")     }     else {         $(selector0 + " .js-inline-form").remove()         $(selector0)              .append("<li class='js-inline-form'><%= j render :partial => 'comments/form' %></li>") }     $(selector3 + " .add.comment").hide()     $(selector3 + " .comment.cancel").show()  } else if($(selector3 + " .comment.cancel").is(":visible")){     $(selector0 + " li.js-inline-form").remove()     $(selector3 + " .comment.cancel").hide()     $(selector3 + " .add.comment").show() } 

also, have spec helper function:

def submit_comment(brief, selector='html', add_comment_link = 'add comment')   first(selector).click_link add_comment_link   fill_in 'brief', with: brief   click_button 'create comment' end 

i changed find() first() because saw people having issues ambiguity , function in capybara 2.0.1.

don't know what's causing happen? when go on server , test same thing, have no issues. if there other code helpful resolve issue, please let me know. thank you.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -