简体   繁体   中英

How to find all unused code in Ruby on Rails

I've inherited a Rails 2.3 app, which lacks a solid test suite. There is a fair amount of testing, but unfortunately, many of the tests test against old, unused models, controllers, and views.

Does anyone have a solid idea of how I might go about testing which models, controllers, views, helpers, etc. are completely unused, as well as look into the ones that ARE used and see which functions specifically are not used?

RCovSimpleCov不会这样做你想要的吗?

You can try to use RubyMine, a Rails IDE, to search for unused code. Try searching for method names and stuff like that. It's been a while since I used it so I dunno if it will have a highlight on unused methods.

Also, you can try some bash commands(grep/ack/find) to search for the code snippets.

You can look at this answer, and perhaps some of the other answers listed: https://stackoverflow.com/a/9788511/485864

I would probably end up logging the methods that you have, and run your code through the paths and anything not listed in the log, may be examined to see if it is indeed not used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM