6

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?

professormeowingtons
  • 3,504
  • 7
  • 36
  • 50
  • This is done with a [Code Coverage](https://en.wikipedia.org/wiki/Code_coverage) tool. Another thing to consider is marking the old objects/contracts as obsolete (by hand) for better identification. – Paul Jun 25 '13 at 17:24
  • 1
    Possible duplicate of [Find unused code in a Rails app](http://stackoverflow.com/questions/9735307/find-unused-code-in-a-rails-app) – oma Nov 24 '16 at 14:06

3 Answers3

1

RCov or SimpleCov won't do this what you want?

Hauleth
  • 22,873
  • 4
  • 61
  • 112
  • 1
    RCov seems to rely on a solid test suite. However, the test suite in our application covers some of the app that is used, but also covers some methods/actions that are NOT used. – professormeowingtons Jun 25 '13 at 17:27
1

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.

renatojf
  • 734
  • 2
  • 11
  • 29
1

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.

Community
  • 1
  • 1
vgoff
  • 10,980
  • 3
  • 38
  • 56