2013-09-25 116 views
0

我想編寫刪除測試場景,但我不明白爲什麼它沒有獲取銷燬鏈接。無法找到「銷燬」鏈接

這裏我的測試場景:

Scenario: User can delete kids 
    Given I am on the kids page 
    When I Destroy kid 
    Then I should see "Kid deleted successfully" 
    Then one kid should not exist 



<h1>Listing kids</h1> 

<tr> 
<th>Kid name</th> 
<th colspan=3>Action</th> 
</tr> 
<% @kids.each do |kid| %> 
    <tr> 
    <td><%= kid.kid_name %></td> 
    <td><%= link_to 'Show', kid %></td> 
    <td><%= link_to 'Edit', edit_kid_path(kid) %></td> 
    <td><%= link_to 'Destroy', kid, method: :delete, 
         data: { confirm: 'Are you sure?' } %></td> 
</tr> 

<%結束%>

<%=的link_to '新來的小子',new_kid_path%>

我的步驟,鏈接認定中:

When /^I Destroy kid$/ do |link|

click_link(link) 

end 

請有人建議刪除鏈接的步驟定義,如果他們在我的方案中有一些錯誤,請糾正我。

謝謝。

+0

您可以發佈正在尋找鏈接步驟? –

+0

您可以發佈./features/step_definitions/event_steps.rb:32:in內容:「/ ^我遵循」([^ \「] *)」$ /' – techvineet

+0

@techvineet這是內容當/ ^我關注「([^ \」] *)「$/do | link | click_link(link) end – atish

回答

0

我找到了銷燬鏈接的答案。它不會支持網頁版,所以我已經刪除網頁和使用水豚,我的問題得到解決。

下面是步驟:

Scenario: Delete Kid

Given I am on the kids page

And there is a kid with kid_name "john"

When I destroy that kid

Then I am on the kids page

step_defination:(。*)

當/^I銷燬$ /做| ELEMENT_TYPE |

element = element_type.classify.constantize.last 

    path = "#{element_type}_path" 

    case page.driver 

when Capybara::RackTest::Driver 

    page.driver.submit :delete, send(path, element), {} 

else 

    visit send(path, element, { method: :delete }) 

end </code>