Using rcov to discover untested parts.

rcov output result for ‘zena’ zafu tags.
How do you know if you have not forgotten to test some crucial part of your application ? How can you get an idea of your current test coverage ?
I first thought I had to use some tool that would read all my code and try to guess what is tested and what not from the content of the tests. This was forgetting how dynamic ruby is. You can find tools that execute all your tests and remember each and every line of code that was used during this testing. It’s then just a question of percentage, counting, drawing and showing nice graphs.
For example, I discoverd that I totally forgot about a special “sprintf” formatting thing. It’s not tested (red line) and I did not document it either…

rcov output telling that the ‘format’ option is not tested in zafu tag “show”.
rcov also gives you an overall test coverage score. The score (missing 90 tests ?) is currently of 77.5% for 10335 lines of code. Which is not too bad.
The command line used:
# rm -rf doc/coverage/*
# rcov --rails --aggregate doc/coverage/coverage.data --text-summary -Ilib --html -o doc/coverage test/**/*_test.rb
# rcov --rails --aggregate doc/coverage/coverage.data --text-summary -Ilib --html -o doc/coverage lib/parser/test/*_test.rbGaspard Bucher