Drink or code ... Why should you choose ?
Published at Wed, 17 Jun 2009 20:00:00 +0000

Rails : number of test and code lines

I'm a bit obsessed by my applications statistics. So on many of them, I build tools allowing me to generate graphics with several evolution indicators of theirs datas over time. On RefStats for example, this graphic shows the evolution of the number of positions; the number of users; of websites and the average execution time for the crawler.

Moreover, you probably already know the rails commande rake stats which gives some statistics datas on your application code. Number of code lines, number of test lines, ... The class that builds it is located in the railties. Unfortunately this class isn't abstract at all. It shows directly the datas to the console. Not very cool to enter them to your database.

So I've taken this class to update it and allow you to get those datas in an abstract way and use them in an application :) So let's me introduct you to Rails Code Statistics (yeah my projects names are always very original)

The principle is pretty simple. You instantiate the class :

stats = CodeSearch.new

Then you can the datas as an hash :

p stats.to_h
As a json element :
p stats.to_json

Only the total statistics

p stats.total
Only the detailed statistics
p stats.statistics

And then do whatever you want with them :) For me for example, I have a rake task which is executed automatically once a day and puts the number of code and test lines to my database. Then I only have to manipulate this database to build a graph.

Note : the version above will only work if you've made your tests with RSpec. If you use Shoulda, I let you do it yourself :mrgreen: And if you use Test::Unit, I invite you to try RSpec. You will not want to do anything else after :mrgreen:

Comments

Post a New Comment

Markdown enabled