July 17, 2011 0

Hudson Code Coverage Reports for Ruby 1.9.2

By in Testing

Want to increase the value of your Hudson Reports with some test/code coverage data? For Ruby 1.8.7 there is a great plugin which uses metrics_fu to display reports within Hudson from Joseph Wilk. But in my case I wanted to use the latest Ruby-1.9.2 stable (in my case p136). The code analysis tools that metrics_fu uses are currently not compatible with 1.9.2, so I decided to use cover_me instead.

But how do you get the cover_me reports into Hudson? It’s actually very easy. Cover me comes with a Emma XML reporting formatter, that can generate XML coverage reports that you then can read with the Emma Hudson Plugin.

So here are the step-by-step instructions on how to configure Ruby 1.9.2-p136, cover_me 1.0.0.rc6, Hudson 2.0.1, Hudson Emma Plugin 1.25 and Rails 3.0.9

  1. Add the following to your Gemfile
  1. Run bundle install to install cover_me and it’s dependencies
  2. Now run the cover_me installer rails g cover_me:install
  3. Edit the cover_me rake tasks file to have it output the coverage reports in the Emma XML format.
  1. Commit your changes and login to your Hudson server.
  2. Configure your project and enable Emma Reports for your project.

Emma Report configuration in Hudson project configuration

  1. That’s it!

For your interest here is my bash-script for running rspec and cucumber with Hudson and generate the Emma Reports:

Tags: , , , , ,

October 26, 2010 1

Rails STI – Single Table Inheritance

By in ActiveRecord, Rails

Yesterday, I  came accross an interesting problem. I wanted to create a super-class called Message and let several other Models inherit from that. My main intention was to map different APIs to my own data-structure. I came up with the following:

After I came up with this structure, I ran into the problem “How do I actually implement this?”. First I found out that Rails ActiveRecord actually supports Single Table Inheritance through a “type” column. That means if I have a model named “Car” and a model named “Porsche” which inherits from Car, then upon saving a Porsche object it will create a Car object with the type attribute set to “porsche”. Sounds like what I wanted.

Unfortunately, Rails ActiveRecord STI implementation did not seem to work with Ruby modules. That’s when i stumbled across this post. He suggest using the Ruby sub-classing syntax, so my structure would look like this:

Looks good to me and works perfectly. Thanks goes to Jud Boulder for his post. And Andreas Nomikos for pointing me in the right direction.

By the way here are some useful links, that I stumbled across during my research on the topic:

Tags: , , , ,