Is it still advisable to test routes in Rails 4 with Minitest?

依然范特西╮ 提交于 2019-12-03 14:10:49

I'm of the belief that testing routes and controllers is totally unnecessary given you have feature tests. This does not directly answer your question, but it should solve your dilemma. I recommend doing some reading on various testing philosophies and (further) formulating an idealogical opinion on how and what to test.

After writing functional tests for a few new controllers recently, without writing any Route Integration Tests, I'm fairly confident that the additional work of testing routes is overkill. Given, that is, if there are functional tests covering all of the routes.

My reasoning is basically that... in any case where I've supplied improper parameters to a get|patch|post|delete call into a controller action, it's always failed. And whenever I write a test for a controller action that exists but that is lacking a corresponding route it always fails. So it appears that the higher-level functional tests also exercise the lower level route integration tests just fine -- so why bother duplicating effort!

I guess I'll still be looking for an updated "official" word on this in the future, but for now I've decided to stop worrying about directly testing my routes whenever overlapping functional tests exist.

UPDATE

I've further decided that testing API routes may still be useful. This helps to ensure that the actual URL string that is published with the API is actually correct and working. Note that it's important to test the string and not the named route as the named route can change with changes to the resources in the routes file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!