Forum: Ruby on Rails coverage does not work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Szczepan F. (Guest)
on 2005-12-28 23:17
(Received via mailing list)
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
Jamie M. (Guest)
on 2005-12-28 23:29
(Received via mailing list)
Try Insurance instead, I've found it works pretty well.

http://insurance.rubyforge.org/

- Jamie
Michael S. (Guest)
on 2005-12-29 03:43
(Received via mailing list)
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
Szczepan F. (Guest)
on 2005-12-29 20:51
(Received via mailing list)
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. <removed_email_address@domain.invalid>:
Tom L. (Guest)
on 2006-01-08 03:53
(Received via mailing list)
On 12/29/05, Szczepan F. <removed_email_address@domain.invalid> 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/
Szczepan F. (Guest)
on 2006-01-08 05:23
(Received via mailing list)
Hi

Move following line:
require 'coverage' if ENV["coverage"] == 'true'

to top of your test_helper.rb

:)

2006/1/8, Tom L. <removed_email_address@domain.invalid>:
This topic is locked and can not be replied to.