如何测试命名空间 post :post 路由?
我
# routes.rb
namespace :admin do
resources :departments
end
在控制器测试中有这些路线和以下代码。它失败是因为 post :create 未前往 admin_departments_path。正确的写法是什么?
# test/functional/admin/departments_controller_test.rb
# ActionController::RoutingError: No route matches (FAIL)
post :create, :department => @new_department.attributes
I have these route
# routes.rb
namespace :admin do
resources :departments
end
And following code in controller test. It fails because post :create is not heading to admin_departments_path. What is the correct way to write this?
# test/functional/admin/departments_controller_test.rb
# ActionController::RoutingError: No route matches (FAIL)
post :create, :department => @new_department.attributes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控制器测试是不必要的痛苦,并且与实现的联系过于紧密。不要使用它们。
正确的方法是编写一个 Cucumber 场景,将某些内容发布到表单中,然后检查您是否最终到达了您想要的页面。
Controller tests are needlessly painful and too closely coupled to implementation. Don't use them.
The correct way to do this is to write a Cucumber scenario that posts something to the form, then checks that you ended up on the page you wanted to.