无法找到“销毁”链接

时间:2013-09-25 11:38:59

标签: ruby-on-rails cucumber capybara

我正在尝试为删除编写测试场景,但我不明白为什么它没有获得销毁链接。

这是我的测试场景:

 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>

&lt;%end%&gt;  

&lt;%= link_to'New Kid',new_kid_path%&gt;

我对链接的步骤定义:

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

   click_link(link)

 end

click_link(link) end

请有人建议删除链接的步骤定义,如果我的方案中出现错误,请纠正我。

谢谢。

1 个答案:

答案 0 :(得分:0)

我找到了破坏链接的答案。它不会支持webrat,所以我删除了webrat并使用了capybara,我的问题得到了解决。

以下是步骤:

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:

When /^I destroy that (.*)$/ do |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

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