Coverage does not work

Hi,

I’ve installed coverage (gem install coverage) and try to run tests with
-rcoverage option on, but following error occurs:
ruby: No such file to load – coverage (LoadError)

I try:
ruby -rcoverage mytest.rb

  1. I have rubygems in evn var RUBYOPT
  2. Gem seems to be installed properly (I can read doc via gems, the
    files
    exist in the …/gem/… dirs)

Does anyone know what is the problem?

Thanks in advance
Szczepan

Try Insurance instead, I’ve found it works pretty well.

http://insurance.rubyforge.org/

  • Jamie

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
put
“require ‘coverage’” into my app, that worked.

But I didn’t WANT my app to require coverage, since then I’d get
coverage
all the time (or at least on every test, if I put it into test_helper.rb
or
someplace like that.

To get around this conundrum, I made a file called
test/enable_coverage.rb,
which contains:

require ‘rubygems’
require ‘coverage’

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’,
‘test/unit//*_test.rb’, 'test/functional//_test.rb’,
'test/agent/**/
_test.rb’)
t.test_files = fl
t.verbose = true
end

Insurance looks cool but I will wait for the next release of win32 ruby
since Insurance requires 1.8.3

What about coverage?

Michael,
One enhancement I would make to your idea:

My custom tasks file (placed in lib/tasks) looks:
require ‘coverage’ if ENV[‘coverage’]==‘true’

from command line I invoke standard rake builds (test_units, recent,
etc.)
but if I want coverage I insert ‘coverage=true’, eg:

rake test_units coverage=true

Now I have almost the same development evironment as I would use
-rcoverage.
The problem is that in every new project I have to place my custom rake
file
(I don’t want to make dependencies in RUBY_HOME/lib/… /rails to
coverage).

I hate leaving some blank areas on the map behind. I think that gems in
general do not work with ruby command line -r option (I tested it with
some). Is it the problem with win2k I am using for development? Gems
usage
manual does not shed light on the matter (it states only about require
‘xxx’
in the script. On the other hand in Pragmatic book about Rails the
author is
using coverage from command line -r option…

Question: Can I use gem library just by including -rxxx in ruby command
line
(I have rubygems in RUBYOPT)?

Thanks
Szczepan

2005/12/29, Michael S. [email protected]:

On 12/29/05, Szczepan F. [email protected] wrote:

Michael,
One enhancement I would make to your idea:

My custom tasks file (placed in lib/tasks) looks:
require ‘coverage’ if ENV[‘coverage’]==‘true’

from command line I invoke standard rake builds (test_units, recent, etc.)
but if I want coverage I insert ‘coverage=true’, eg:

rake test_units coverage=true

I made a file lib/tasks/default.rake with only “require ‘coverage’ if
ENV[‘coverage’]==‘true’”, but when I run “rake coverage=true” only
index.html, environment.rb.html, routes.rb.html, and boot.rb.html are
generated. The quality of those results isn’t very good anyway. It
counts continuation lines as not being covered and stopped midway
through my environment.rb for some reason.

Is it working better than this on your system?

Thanks
Szczepan

Sincerely,

Tom L.
http://AllTom.com/
http://GadgetLife.org/

Hi

Move following line:
require ‘coverage’ if ENV[“coverage”] == ‘true’

to top of your test_helper.rb

:slight_smile:

2006/1/8, Tom L. [email protected]: