Sunday, September 16, 2007

rcov: code coverage for Ruby and Rails rcov plugin

rcov reference
shell> sudo gem install -y rcov
How do I use it? What does it look like?
shell> rcov --help
shell> rcov test/*.rb

Rails Rcov Plugin:
./script/plugin install

For each test:blah task you have for your Rails project, rails_rcov adds two more: test:blah:rcov and test:blah:clobber_rcov.
Running rake test:units:rcov, for example, will run your unit tests through rcov and write the code coverage reports to your_rails_app/coverage/units.
Running test:units:clobber_rcov will erase the generated report for the unit tests.
Each rcov task can take a few options:

rake test:units:rcov SORT=(name|loc|coverage)
rake test:units:rcov SORT_REVERSE=(YES|Y|TRUE|T|1)
rake test:units:rcov THRESHOLD=(INT)
rake test:units:rcov NO_COLOR=(YES|Y|TRUE|T|1)
rake test:units:rcov PROFILE=(YES|Y|TRUE|T|1)
rake test:units:rcov SHOW_WARNINGS=(YES|Y|TRUE|T|1)

These options parallel the rcov options, so check the rcov documentation if this isn’t clear.
Running rake test:rcov will run the unit tests, functional tests, and integration tests sequentially via rcov, and output the results to your_rails_app/coverage/(units|functionals|integration).

No comments :