I had the same problem, and while I didn’t really figure out why it was
happening, I figured out an easy workaround.
For me, doing ‘-rcoverage’ from the command line didn’t work, but if I
“require ‘coverage’” into my app, that worked.
But I didn’t WANT my app to require coverage, since then I’d get
all the time (or at least on every test, if I put it into test_helper.rb
someplace like that.
To get around this conundrum, I made a file called
Then, from the command line, I can do something like:
ruby -rtest/enable_coverage.rb test/unit/mytest.rb
I don’t actually run it this way. Instead, I made a Rake task to do
coverage, and I had the Rake task include that file, like this:
desc “Run the unit, functional, and agent tests and generate coverage
stats. You must have the coverage gem installed for this to work.”
Rake::TestTask.new(:test_coverage => [ :prepare_test_database ]) do |t|
t.libs << “test”
fl = FileList.new.include(‘test/enable_coverage.rb’,
t.test_files = fl
t.verbose = true