2015-01-18 2 views
1
<ul> 
    <% @topic.contents.each do |content| %> 
     <li> 
     <%= content.content %> <%= link_to "Edit", edit_content_path(content) %> <br><br> 
     </li> 
    <% end %> 
</ul> 

카피 바라를 사용하여 이것을 테스트하려면 다소 필요합니다. 내 테스트 파일이 입력 시도 :Capybara find_link가 모호한 일치 오류를냅니다.

test "there is an edit link on the show page" do 
    click_link "Enter" 
    click_link "Ruby" 
    assert find_link("Edit").first.visible? 
end 

를하지만 나에게 메시지를주는 바람이 :

1) Error: 
VisitorFindContentTest#test_there_is_an_edit_link_on_the_show_page: 
Capybara::Ambiguous: Ambiguous match, found 2 elements matching link "Edit" 
    test/integration/visitor_find_content_test.rb:44:in `block in <class:VisitorFindContentTest>' 

내가 다른 무엇을 할 수 있습니까? 무엇을 할 수 있습니까? 각 수정 사항을 고유하게 연결하기 위해 뭔가해야합니까? 아니면 편집 링크의 첫 번째 모양을 찾는 카피 바라 테스트 방법이 있습니까? 다음과 같이

답변

0

content:id 또는 :class 특정 추가 :

<%= content.content %> <%= link_to "Edit", edit_content_path(content), id: "content_#{content.id}" %> <br><br> 

또는

<%= content.content %> <span id: "content_#{content.id}"><%= link_to "Edit", edit_content_path(content) %></span> <br><br> 
다음과 같이 다음 위의 두 번째 옵션 (링크를 클릭이 ID를 사용할 수 있습니다

) :

content = Content.first # or some way of finding the required content object 
within("#content_#{content.id}") do 
    click_link("Edit") 
end