我正在使用 rspec,并且正在尝试为用户的汽车测试 DELETE 方法:
describe "DELETE " do
it "should delete a car" do
#@car = Factory.create :car
expect { click_link "Delete" }.to change{Car.count}.by(-1)
end
end
当我运行它时,我得到了这个错误:
CarsController DELETE should delete a car
Failure/Error: expect { click_link "Delete" }.to change{Car.count}.by(-1)
Capybara::ElementNotFound:
no link with title, id or text 'Delete' found
# (eval):2:in `click_link'
# ./spec/controllers/car_controller_spec.rb:30:in `block (4 levels) in <top (required)>'
# ./spec/controllers/car_controller_spec.rb:30:in `block (3 levels) in <top (required)>'
我不知道为什么,因为我的 index.html.erb 上有这个链接:
<td><%= link_to 'Delete', user_car_path(@user, car), :confirm => 'Are you sure?', :method => :delete %></td>
但在我的应用程序中它有效