耙线显示:
estimate_location GET /estimate/location/:id(.:format) estimate/location#show
而我的rspec测试:
it 'should re-direct to location/new from show' do
e = FactoryGirl.create :estimate
get estimate_location_path e
expect(response.status).to eq(302)
end
控制台说:
Failure/Error: get estimate_location_path e
ActionController::RoutingError:
No route matches {:controller=>"estimate/location", :action=>"/estimate/location/1"}
这对我来说没有意义。有一条路线,我传递了一个对象(Rails聪明地从中获取ID),但这是说没有这样的路线?
看来您正在编写控制器规范(该规范称为功能测试)
在这些测试中get
,post
etc方法期望第一个参数是动作的名称,第二个参数是选项的哈希-它们绕过路由(尽管它们确实检查了动作是否可路由)。你会做
get :show, id: e.id
另一方面,在集成测试(请求规格或功能规格)中,您将使用实际路径(并且取决于设置,您将使用visit
或get
,post
等等,但是它们将是不同的get
方法)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句