First of all, you will need to install the rails_rcov plugin. This useful plugin allows you to really easily run RCov using rake, and is essential to simple RCov integration with your CruiseControl.rb builds. You can install rails_rcov like this:
./script/plugin install http://svn.codahale.com/rails_rcov
Use the "-x" option if you want to use an svn:external link to the latest version of the plugin. I personally don't like to do that...I want control over when the software I am using gets updated, thanks.
Once the plugin is installed into your project you have some useful rake tasks like this one:
# sort by coverage
rake test:units:rcov RCOV_PARAMS="--sort=coverage"
Now you are ready for the final bit, which is adding a "cruise.rake" task to the "lib/tasks" directory of your Ruby on Rails project. The task should have something like this, which was lifted verbatim from the CruiseControl.rb build of CruiseControl.rb itself (that all sounds kinda twisted, but it is cool):
desc 'Continuous build target'
task :cruise do
out = ENV['CC_BUILD_ARTIFACTS']
mkdir_p out unless File.directory? out if out
ENV['SHOW_ONLY'] = 'models,lib,helpers'
Rake::Task["test:units:rcov"].invoke
mv 'coverage/units', "#{out}/unit test coverage" if out
ENV['SHOW_ONLY'] = 'controllers'
Rake::Task["test:functionals:rcov"].invoke
mv 'coverage/functionals', "#{out}/functional test coverage" if out
Rake::Task["test:integration"].invoke
end
That's it. Now you have incredible code coverage goodness right within your build. You can even browse the source within the browser window of the CruiseControl.rb dashboard and see which lines of code were covered by your tests, and which were not...
So if you have a Ruby on Rails project, with a project team of greater than 1 developer, you had better start using CruiseControl.rb. It is too easy, and the payoff of doing continuous integration is huge!
7 comments:
Hi Ron, this is Shawn from CW. I just wanted to say hello, nice blog, and to wish you success in your future endeavors. I can be reached at shawn at shawnwhite dot biz.
Thanks so much for posting this! It was a great help.
Thanks Ron,
You turned this into a 3 minute task for me, including adapting for rspec.
Yup, works just fine.
It's 2009 and I still found your blog entry useful,
This is really amazing to see... I integrated the rcov today to a new project and it just works fine without any hassle the way u have described here ...
thx a lot man
cheers :D
amazing stuff.. works really smooth
thx a lot :D
cheers
Post a Comment