# Rcov-0.8.1: compatibility with Ruby 1.8.6-p11\[01\], intentional testing with RSpec, etc

**URL:** <https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691>\
**Category:** Ruby\
**Created:** [November 19, 2007, 9:07pm UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691 "2007-11-19T21:07:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [November 19, 2007, 9:07pm UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691/1 "2007-11-19T21:07:00Z")

</div>

Source code, additional information, screenshots… available at  
[eigenclass.org](http://eigenclass.org/hiki/rcov)  
Release info:  
[eigenclass.org](http://eigenclass.org/hiki/rcov-0.8.1)  
Sample fully cross-referenced report at  
[eigenclass.org](http://eigenclass.org/static/rcov-sample-report-full-crossref/)

This release includes two RubyGems packages: a binary one for Win32 and  
a  
platform-independent one, for all those with a compiler (or a lot of  
patience,  
if willing to run rcov in pure-Ruby mode), so  
gem install rcov  
should work once the packages have propagated to the mirror network.

# Overview

rcov is a code coverage tool for Ruby. It is commonly used for viewing  
overall  
test coverage of target code. It features:

- fast execution: 20-300 times faster than previous tools
- multiple analysis modes: standard, bogo-profile, “intentional  
testing”,  
dependency analysis…
- detection of uncovered code introduced since the last run  
(“differential  
code coverage”)
- fairly accurate coverage information through code linkage inference  
using  
simple heuristics
- cross-referenced XHTML and several kinds of text reports
- support for easy automation with Rake and Rant
- colorblind-friendliness

# What’s new in 0.8.1

## Features

- you can use an existent data file to generate coverage reports without  
having to execute your code again
- –spec-only: only consider covered code executed inside a spec  
(tested with RSpec 1.0.5, 1.0.8)
- –charset can be used to specify the charset in the Content-Type  
declaration

## Bugfixes

- workaround for bugs in Safari, IE (self-closing anchors break  
colorization)
- workaround for bugs in REXML shipped with 1.8.6-p11[01]
- rethrow exceptions generated by traced scripts
- compatibility with Ruby \< 1.8.5

# Thanks go to

Lee M.:

- patch allowing to run rcov against a data file with no input code

Kurt Stephens:

- patch to rethrow any exceptions generated by the traced scripts after  
report generation; notably SystemExit, allowing to use the exit code  
from  
test runners under rake.

Brian C.:

- found compatibility issues with the REXML lib included in  
ruby-1.8.6-p110  
and provided a workaround

Mat S.:

- reported missing line colorization on Safari and probably other  
browsers,  
owing to self-closing not being handled properly despite being  
valid  
XHTML 1.0.
 
 

Sam Granieri:

 
- tested workaround for REXML bug

 

Kosmas Schütz, Daniel B., François Beausoleil, Bil K.:

 
- provided information about the ruby-1.8.6-p11[01] REXML problems

 
# How do I use it?

In the common scenario, your tests are under test/ and the target code  
(whose coverage you want) is in lib/. In that case, all you have to do  
is  
use rcov to run the tests (instead of testrb), and a number of XHTML  
files  
with the code coverage information will be generated, e.g.

```
rcov -Ilib test/*.rb

```

will execute all the .rb files under test/ and generate the code  
coverage  
report for the target code (i.e. for the files in lib/) under coverage/.  
The  
target code needs not be under lib/; rcov will detect is as long as it  
is  
require()d by the tests. rcov is smart enough to ignore “uninteresting”  
files: the tests themselves, files installed in Ruby’s standard  
locations,  
etc. See rcov --help for the list of regexps rcov matches filenames  
against.

rcov can also be used from Rake; see README.rake or the RDoc  
documentation  
for more information.

rcov can output information in several formats, and perform different  
kinds  
of analyses in addition to plain code coverage. See rcov --help for a  
description of the available options.

# Sample output

See [eigenclass.org](http://eigenclass.org/hiki/rcov) (once again) for screenshots.

rcov can generate HTML reports and a number of plain text reports. The  
default text report (also used by default in RcovTasks) resembles

±----------------------------------------------------±------±------±-------+  
| File | Lines | LOC | COV |  
±----------------------------------------------------±------±------±-------+  
|lib/rcov.rb | 572 | 358 | 91.3% |  
±----------------------------------------------------±------±------±-------+  
|Total | 572 | 358 | 91.3% |  
±----------------------------------------------------±------±------±-------+  
91.3% 1 file(s) 572 Lines 358 LOC

The (undecorated) textual output with execution count information looks  
like this:

# $ rcov --no-html --text-counts b.rb

# ./b.rb

```
                                                                   | 

```

2  
a, b, c = (1…3).to\_a |  
2  
10.times do |  
1  
a += 1 |  
10  
20.times do |i| |  
10  
b += i |  
200  
b.times do |  
200  
c += (j = (b-a).abs) \> 0 ? j : 0 |  
738800  
end |  
0  
end |  
0  
end |  
0

rcov can detect when you’ve added code that was not covered by your unit  
tests:

```
$ rcov --text-coverage-diff --no-color test/*.rb
Started
.......................................
Finished in 1.163085 seconds.

39 tests, 415 assertions, 0 failures, 0 errors

================================================================================
!!!!! Uncovered code introduced in lib/rcov.rb

### lib/rcov.rb:207

```

def precompute\_coverage(comments\_run\_by\_default = true)  
changed = false  
lastidx = lines.size - 1  
if (!is\_code?(lastidx) || /^ **END** $/ =~ @lines[-1]) &&  
!@coverage[lastidx]  
!! # mark the last block of comments  
!! @coverage[lastidx] ||= :inferred  
!! (lastidx-1).downto(0) do |i|  
!! break if is\_code?(i)  
!! @coverage[i] ||= :inferred  
!! end  
!! end  
(0…lines.size).each do |i|  
next if @coverage[i]  
line = @lines[i]

## License

rcov is released under the terms of Ruby’s license.  
rcov includes xx 0.1.0, which is subject to the following conditions:

ePark Labs Public License version 1  
Copyright (c) 2005, ePark Labs, Inc. and contributors  
All rights reserved.

Redistribution and use in source and binary forms, with or without  
modification,  
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright  
notice, this  
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright  
notice,  
this list of conditions and the following disclaimer in the  
documentation  
and/or other materials provided with the distribution.
3. Neither the name of ePark Labs nor the names of its contributors  
may be  
used to endorse or promote products derived from this software  
without  
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS  
IS” AND  
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  
IMPLIED  
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE  
LIABLE FOR  
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
DAMAGES  
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR  
SERVICES;  
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  
AND ON  
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  
THIS  
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

---

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [November 20, 2007, 10:20am UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691/2 "2007-11-20T10:20:12Z")

</div>

Mauricio F. wrote:

> Source code, additional information, screenshots… available at  
> [http://eigenclass.org/hiki/rcov](http://eigenclass.org/hiki/rcov)  
> Release info:  
> [eigenclass.org](http://eigenclass.org/hiki/rcov-0.8.1)  
> Sample fully cross-referenced report at  
> [eigenclass.org](http://eigenclass.org/static/rcov-sample-report-full-crossref/)
> 
> This release includes two RubyGems packages: a binary one for Win32 and  
> a  
> platform-independent one, for all those with a compiler (or a lot of  
> patience,  
> if willing to run rcov in pure-Ruby mode), so  
> gem install rcov  
> should work once the packages have propagated to the mirror network.
> 
> Brian C.:
> 
> - found compatibility issues with the REXML lib included in  
> ruby-1.8.6-p110  
> and provided a workaround

Still a REXML incompatibility in 0.8.1. ?

Microsoft Windows XP [version 5.1.2600]  
(C) Copyright 1985-2001 Microsoft Corp.  
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]  
(this is the one click installer 1.8.6-25)

C:\>rcov …

Microsoft Windows XP [version 5.1.2600]  
(C) Copyright 1985-2001 Microsoft Corp.

C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov/report.rb:19:in  
`wr ite': uninitialized constant REXML::Formatters (NameError) from (eval):93:in `pretty’  
from  
C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov/report  
.rb:760:in `format_overview' from C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov/report .rb:795:in `create\_index’  
from (eval):104:in `create' from (eval):80:in `tracking\_additions’  
from (eval):103:in `create' from (eval):372:in `x\_’  
from  
C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov/report  
.rb:795:in `create_index' ... 22 levels... from C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov.rb:640 :in `each’  
from  
C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov.rb:640  
:in `dump\_coverage\_info’  
from  
C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/bin/rcov:421  
from C:/ruby/bin/rcov:16

---

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [November 20, 2007, 11:26am UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691/3 "2007-11-20T11:26:50Z")

</div>

On Tue, Nov 20, 2007 at 06:20:09PM +0900, Michel D. wrote:

> Mauricio F. wrote:
> 
> > Brian C.:
> > 
> > - found compatibility issues with the REXML lib included in  
> > ruby-1.8.6-p110 and provided a workaround
> 
> Still a REXML incompatibility in 0.8.1. ?

[…]

> ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]  
> (this is the one click installer 1.8.6-25)
> 
> C:\>rcov …  
> […]  
> C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov/report.rb:19:in  
> `wr ite': uninitialized constant REXML::Formatters (NameError) from (eval):93:in`pretty’  
> from  
> […]

The workaround must only be used with ruby 1.8.6 p11[01]. This is  
entirely my  
mistake (not Brian C.'s), and it’s been corrected in rcov 0.8.1.1  
(see my  
other post on this thread).

---

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [November 20, 2007, 11:21am UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691/4 "2007-11-20T11:21:31Z")

</div>

On Mon, Nov 19, 2007 at 09:06:01PM +0100, Mauricio F. wrote:

> # Source code, additional information, screenshots… available at [http://eigenclass.org/hiki/rcov](http://eigenclass.org/hiki/rcov) Release info: [eigenclass.org](http://eigenclass.org/hiki/rcov-0.8.1) Sample fully cross-referenced report at [eigenclass.org](http://eigenclass.org/static/rcov-sample-report-full-crossref/) […] What’s new in 0.8.1

[…]

> ## Bugfixes
> 
> - workaround for bugs in Safari, IE (self-closing anchors break colorization)
> - workaround for bugs in REXML shipped with 1.8.6-p11[01]
> - rethrow exceptions generated by traced scripts
> - compatibility with Ruby \< 1.8.5

The REXML workaround was being used incorrectly with 1.8.6 \< p110.  
Either apply the patch below, or upgrade to rcov 0.8.1.1.

# Changes since 0.8.1

## Bugfixes

- REXML workaround incorrectly applied to 1.8.6 \< p110
- –spec-only should work with RSpec trunk and detect when it cannot  
work

# Thanks

Chad H.:

- indicated that Spec::DSL::Example has changed in RSpec trunk

Tue Nov 20 10:37:40 CET 2007 Mauricio F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

- lib/rcov/report.rb: the REXML workaround only applies to some 1.8.6  
builds.  
diff -rN -u old-head/lib/rcov/report.rb new-head/lib/rcov/report.rb  
— old-head/lib/rcov/report.rb 2007-11-20 11:19:01.000000000 +0100  
+++ new-head/lib/rcov/report.rb 2007-11-20 11:19:01.000000000 +0100  
@@ -6,7 +6,8 @@

# Try to fix bug in the REXML shipped with Ruby 1.8.6

# This affects Mac OSX 10.5.1 users and motivates endless bug reports.

-if RUBY\_VERSION == “1.8.6” && defined? REXML  
+if RUBY\_VERSION == “1.8.6” && defined? REXML::Formatters::Transitive &&

- RUBY\_RELEASE\_DATE \< “2007-11-04”  
class REXML::Document  
def write( output=$stdout, indent=-1, trans=false,  
ie\_hack=false )  
if xml\_decl.encoding != “UTF-8” && !output.kind\_of?(Output)

---

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [November 20, 2007, 12:41pm UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691/5 "2007-11-20T12:41:15Z")

</div>

On Tue, Nov 20, 2007 at 08:03:05PM +0900, Michel D. wrote:

> Mauricio F. wrote:
> 
> > On Tue, Nov 20, 2007 at 06:20:09PM +0900, Michel D. wrote:
> > 
> > > Mauricio F. wrote:
> > > 
> > > > Brian C.:
> > > > 
> > > > - found compatibility issues with the REXML lib included in  
> > > > ruby-1.8.6-p110 and provided a workaround
> > > 
> > > Still a REXML incompatibility in 0.8.1. ?  
> > > […]  
> > > Bulk updating Gem source index for: [http://gems.rubyforge.org](http://gems.rubyforge.org)  
> > > Building native extensions. This could take a while…  
> > > ERROR: Error installing rcov:  
> > > ERROR: Failed to build gem native extension.

If you use the mswin32 binary package, gem shouldn’t try to build the  
extension. Could it be that the RubyForge indexer hasn’t picked up the  
win32  
gem yet? It might work if you try again. gem should ask you which  
version you  
want or install the mswin32 binary directly; if not, there’s probably a  
bug in  
RubyGems or RubyForge’s indexer:

$ gem install rcov  
Bulk updating Gem source index for: [http://gems.rubyforge.org](http://gems.rubyforge.org)  
Select which gem to install for your platform (i686-linux)

1. rcov 0.8.1.1.0 (mswin32)
2. rcov 0.8.1.1.0 (ruby)
3. rcov 0.8.1.0 (mswin32)
4. rcov 0.8.1.0 (ruby)
5. Skip this gem
6. Cancel installation

You can find rcov-0.8.1.1.0-mswin32.gem at  
[http://rubyforge.org/frs/?group\_id=1750](http://rubyforge.org/frs/?group_id=1750)

---

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [November 20, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691/6 "2007-11-20T17:27:50Z")

</div>

there’s probably a

> bug in  
> RubyGems or RubyForge’s indexer:

Yes.  
Actually, it looks like a bug of the last version of rubygems-update  
(0.9.5) which pretends to guess your platform and guesses wrong…

I reverted, and loaded the good rcov, and it works. Thanks !  
MD

---

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [November 20, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/rcov-0-8-1-compatibility-with-ruby-1-8-6-p11-01-intentional-testing-with-rspec-etc/120691/7 "2007-11-20T12:03:04Z")

</div>

Mauricio F. wrote:

> On Tue, Nov 20, 2007 at 06:20:09PM +0900, Michel D. wrote:
> 
> > Mauricio F. wrote:
> > 
> > > Brian C.:
> > > 
> > > - found compatibility issues with the REXML lib included in  
> > > ruby-1.8.6-p110 and provided a workaround
> > 
> > Still a REXML incompatibility in 0.8.1. ?
> 
> […]
> 
> > ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]  
> > (this is the one click installer 1.8.6-25)
> > 
> > C:\>rcov …  
> > […]  
> > C:/RUBY/lib/ruby/gems/1.8/gems/rcov-0.8.1.0-mswin32/lib/rcov/report.rb:19:in  
> > `wr ite': uninitialized constant REXML::Formatters (NameError) from (eval):93:in `pretty’  
> > from  
> > […]
> 
> The workaround must only be used with ruby 1.8.6 p11[01]. This is  
> entirely my  
> mistake (not Brian C.'s), and it’s been corrected in rcov 0.8.1.1  
> (see my  
> other post on this thread).

Sorry to insist : now rcov does not install .

Microsoft Windows XP [version 5.1.2600]  
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Michel\>gem install rcov  
Bulk updating Gem source index for: [http://gems.rubyforge.org](http://gems.rubyforge.org)  
Building native extensions. This could take a while…  
ERROR: Error installing rcov:  
ERROR: Failed to build gem native extension.

C:/ruby/bin/ruby.exe extconf.rb install rcov  
creating Makefile

nmake  
‘nmake’ n’est pas reconnu en tant que commande interne  
ou externe, un programme exÃ©cutable ou un fichier de commandes.

Gem files will remain installed in  
C:/ruby/lib/ruby/gems/1.8/gems/rcov-0.8.1.1.0  
for inspection.  
Results logged to  
C:/ruby/lib/ruby/gems/1.8/gems/rcov-0.8.1.1.0/ext/rcovrt/gem\_m  
ake.out
