鉴于跟踪路线......
post '/a/link.aspx', to: 'vendor_simulator#an_action'
,路线显示为......
Prefix Verb URI Pattern Controller#Action
POST /a/link.aspx(.:format) vendor_simulator#an_action
以下通过考试......
it "returns http success" do
post :an_action, return_xml, :content_type => 'application/xml'
expect(response).to have_http_status(:success)
end
为什么以下测试失败...
it "returns http success" do
post "/a/link.aspx", return_xml, :content_type => 'application/xml'
expect(response).to have_http_status(:success)
end
有......
1) VendorSimulatorController POST '/a/link' returns http success
Failure/Error: post "/a/link.aspx", return_xml, :content_type => 'application/xml'
ActionController::UrlGenerationError:
No route matches {:action=>"/a/link.aspx", :content_type=>"application/xml", :controller=>"vendor_simulator"}
答案 0 :(得分:1)
看起来你有一个控制器测试(而不是集成测试)。如果是这种情况,则第二个失败,因为控制器测试绕过路由,而是需要告知哪个操作方法要使用帖子(或获取或放置或删除)而不是给出URL路径。