I've been setting up metric_fu on one of my projects, and I ran into a problem where the rcov report was not including my specs. (This is an old project that has both Test::Unit
tests and RSpec specs.) I did lots and lots of digging, and was baffled that no one has mentioned that they cannot run coverage reports for their specs using metric_fu. It seemed like an obvious and heinous oversight on the part of metric_fu.
As always, I suspected that I was missing something. Test::Unit
tests can be run individually from the command line like ruby path/to/test
, and metric_fu appeared to be trying to do this with the specs, but when I did ruby path/to/spec
I got nothing.
I actually looked at the metric_fu specs to discover this, and it is probably very obvious to any serious RSpec user, but I discovered that I needed to add require "spec/autorun"
to the top of my spec_helper.rb
file. This includes the magic that makes ruby path/to/spec
work, and makes rcov include my specs in its report when it is invoked by metric_fu.