集成测试所做的是打开一个显示购买页面并单击Approve
购买页面。这是 rspec 案例:
it "should display the approve page" do
proj = FactoryGirl.create(:project)
pur = FactoryGirl.create(:purchasing, :project_id => proj.id)
visit project_purchasing_path(proj, pur)
response.should have_selector("a", :href => approve_project_purchasing_path(proj, pur), :content => "Approve")
click_link 'Approve'
end
click_link 'Approve'
即使response
只是验证页面上有'Approve'
链接,最后一行也会导致以下错误:
ActionController::RoutingError:←[0m
←[31mNo route matches [GET] "/projects/1/purchasings/1/approve"
在输出中rake routes
有一个路径approve_project_purchasing_path:
approve_project_purchasing PUT /projects/:project_id/purchasings/:id/approve(.:format)
单击 时代码执行完全没有错误'Approve'
。
我们的 rspec 代码有什么问题?谢谢您的帮助。
更新:这是link_to
for Approve
:
<%= link_to 'Approve', approve_project_purchasing_path(@project, @purchasing), :method => :put, :id => 'purchasing_need_approve', :confirm => 'Approve' + @purchasing.prod_name + '?' %>