Tuesday, September 15, 2009

Flog and RCov - Code Complexity and Test Coverage in Ruby on Rails

The following might help you get started in measuring code complexity and measuring test coverage for your Rails app.

To get flog:

gem install flog

In your rails app:

flog app
The scores help you concentrate on the parts of your code that are more complex than the others. According to the nasty flog site, "The higher the score, the harder it is to test." Jake Scruggs provided a scale for flog scores.

To get rcov:

gem install rcov

Go to your rails app, then get the rails_rcov as noted here:

./script/plugin install http://svn.codahale.com/rails_rcov
Then use the following to run all tests, as provided by Andrew Montgomery's comment on that page:
rake test:test:rcov
After each set of tests are run, it will output code coverage via tests.

To run a test and re-run test coverage report:

rcov -T test/functional/some_test_name.rb

No comments: