rake 路线显示:
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),但它说没有这样的路径??
最佳答案
看起来您正在编写 Controller 规范(rails 称之为功能测试)
在这些测试中,get
、post
等方法期望第一个参数是操作的名称,第二个参数是选项的哈希值 - 它们绕过路由(尽管他们确实检查操作是否可路由)。相反,你会这样做
get :show, id: e.id
另一方面,在集成测试(请求规范或功能规范)中,您将使用实际路径(并且取决于您将使用 visit
或 get
的设置、 post
等,但它们是不同的 get
方法)
关于ruby-on-rails - 在现有路由的 rspec 测试中找不到路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28551578/