# \[ANN\] rcov 0.7.0 (code coverage for Ruby)

**URL:** <https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627>\
**Category:** ruby-talk\
**Created:** [4 August 2006 14:23 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627 "2006-08-04T14:23:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mauricio\_Fernandez](https://rubytalk.org/u/Mauricio_Fernandez)\
**Post date:** [4 August 2006 14:23 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/1 "2006-08-04T14:23:53Z")

</div>

Source code, additional information, screenshots... available at  
&nbsp;&nbsp;&nbsp;&nbsp;[http://eigenclass.org/hiki.rb?rcov](http://eigenclass.org/hiki.rb?rcov)  
Release information:  
&nbsp;&nbsp;&nbsp;&nbsp;[http://eigenclass.org/hiki.rb?rcov+0.7.0](http://eigenclass.org/hiki.rb?rcov+0.7.0)

Sample (fully) cross-referenced report at  
&nbsp;&nbsp;&nbsp;&nbsp;[http://eigenclass.org/static/rcov-sample-report-full-crossref/](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  
&nbsp;&nbsp;gem install rcov  
should work once the packages have propagated to the mirror network (as of  
14:20 UTC, about 5H since I uploaded them to Rubyforge, they haven't).

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",  
> &nbsp;&nbsp;dependency analysis...  
> \* detection of uncovered code introduced since the last run ("differential  
> &nbsp;&nbsp;code coverage")  
> \* fairly accurate coverage information through code linkage inference using  
> &nbsp;&nbsp;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.7.0
> 
> See [http://eigenclass.org/hiki.rb?rcov+0.7.0](http://eigenclass.org/hiki.rb?rcov+0.7.0) for the detailed change summary.
> 
> Features  
> --------  
> \* coverage/callsite data from multiple runs can be aggregated (--aggregate)
> 
> Bugfixes  
> --------  
> \* the SCRIPT\_LINES\_\_ workaround works better  
> \* fixed silly bug in coverage data acquisition (line after the correct one  
> &nbsp;&nbsp;marked in some situations)  
> \* avoid problems with repeated path separators in default ignore list, based  
> &nbsp;&nbsp;on rbconfig's data
> 
> # 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.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;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 [http://eigenclass.org/hiki.rb?rcov](http://eigenclass.org/hiki.rb?rcov) (once again) for screenshots.
> 
> The text report (also used by default in RcovTasks) resembles
> 
> +-----------------------------------------------------+-------+-------+--------+
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\> 2  
> a, b, c = (1..3).to\_a | 2  
> 10.times do | 1  
> &nbsp;&nbsp;&nbsp;a += 1 | 10  
> &nbsp;&nbsp;&nbsp;20.times do |i| | 10  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b += i | 200  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b.times do | 200  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c += (j = (b-a).abs) \> 0 ? j : 0 | 738800  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end | 0  
> &nbsp;&nbsp;&nbsp;end | 0  
> end | 0
> 
> rcov can detect when you've added code that was not covered by your unit  
> tests:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;$ rcov --text-coverage-diff --no-color test/\*.rb  
> &nbsp;&nbsp;&nbsp;&nbsp;Started  
> &nbsp;&nbsp;&nbsp;&nbsp;.......................................  
> &nbsp;&nbsp;&nbsp;&nbsp;Finished in 1.163085 seconds.  
> &nbsp;&nbsp;&nbsp;&nbsp;  
> &nbsp;&nbsp;&nbsp;&nbsp;39 tests, 415 assertions, 0 failures, 0 errors  
> &nbsp;&nbsp;&nbsp;&nbsp;  
> &nbsp;&nbsp;&nbsp;&nbsp;================================================================================  
> &nbsp;&nbsp;&nbsp;&nbsp;!!!!! Uncovered code introduced in lib/rcov.rb  
> &nbsp;&nbsp;&nbsp;&nbsp;  
> &nbsp;&nbsp;&nbsp;&nbsp;### lib/rcov.rb:207  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
> &nbsp;&nbsp;&nbsp;def precompute\_coverage(comments\_run\_by\_default = true)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;changed = false  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lastidx = lines.size - 1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!is\_code?(lastidx) || /^\_\_END\_\_$/ =~ @lines[-1]) && !@coverage[lastidx]  
> &nbsp;&nbsp;&nbsp;&nbsp;!! # mark the last block of comments  
> &nbsp;&nbsp;&nbsp;&nbsp;!! @coverage[lastidx] ||= :inferred  
> &nbsp;&nbsp;&nbsp;&nbsp;!! (lastidx-1).downto(0) do |i|  
> &nbsp;&nbsp;&nbsp;&nbsp;!! break if is\_code?(i)  
> &nbsp;&nbsp;&nbsp;&nbsp;!! @coverage[i] ||= :inferred  
> &nbsp;&nbsp;&nbsp;&nbsp;!! end  
> &nbsp;&nbsp;&nbsp;&nbsp;!! end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(0...lines.size).each do |i|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next if @coverage[i]  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line = @lines[i]
> 
> # Thanks
> 
> Thomas Leitner:  
> \* reported that the SCRIPT\_LINES\_\_ workaround did not always work
> 
> Assaph Mehr:  
> \* beta-tested 0.7.0 and found a bug in --aggregate (missing files)
> 
> Ryan Kinderman:  
> \* suggested that -Ipath be passed to ruby instead of rcov in RcovTasks
> 
> 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:
> 
> &nbsp;&nbsp;1. Redistributions of source code must retain the above copyright notice, this  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list of conditions and the following disclaimer.  
> &nbsp;&nbsp;2. Redistributions in binary form must reproduce the above copyright notice,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this list of conditions and the following disclaimer in the documentation  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and/or other materials provided with the distribution.  
> &nbsp;&nbsp;3. Neither the name of ePark Labs nor the names of its contributors may be  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used to endorse or promote products derived from this software without  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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.
> 
> --  
> Mauricio Fernandez - [http://eigenclass.org](http://eigenclass.org) - singular Ruby

---

<div class="post-metadata">

**Author:** ![Herb\_Asher](https://avatars.discourse-cdn.com/v4/letter/h/7bcc69/32.png) [@Herb\_Asher](https://rubytalk.org/u/Herb_Asher)\
**Post date:** [7 August 2006 03:15 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/2 "2006-08-07T03:15:30Z")

</div>

I am wondering, for a rails project, would this be the correct way to use  
this?

rcov -Ilib test/\*\*/\*.rb

That works for me, albeit about 30% of my tests fail then, while when I run  
them using the rake task ("rake"), they all pass. So I suppose I must be  
doing something wrong.

Thanks alot, great project,

Rob

> **···**
>
> On 8/4/06, Mauricio Fernandez \<mfp@acm.org\> wrote:
> 
> > Source code, additional information, screenshots... available at  
> > &nbsp;&nbsp;&nbsp;&nbsp;[http://eigenclass.org/hiki.rb?rcov](http://eigenclass.org/hiki.rb?rcov)  
> > Release information:  
> > &nbsp;&nbsp;&nbsp;&nbsp;[http://eigenclass.org/hiki.rb?rcov+0.7.0](http://eigenclass.org/hiki.rb?rcov+0.7.0)
> > 
> > Sample (fully) cross-referenced report at  
> > &nbsp;&nbsp;&nbsp;&nbsp;[http://eigenclass.org/static/rcov-sample-report-full-crossref/](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  
> > &nbsp;&nbsp;gem install rcov  
> > should work once the packages have propagated to the mirror network (as of  
> > 14:20 UTC, about 5H since I uploaded them to Rubyforge, they haven't).
> > 
> > # 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",  
> > &nbsp;&nbsp;dependency analysis...  
> > \* detection of uncovered code introduced since the last run ("differential  
> > &nbsp;&nbsp;code coverage")  
> > \* fairly accurate coverage information through code linkage inference  
> > using  
> > &nbsp;&nbsp;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.7.0
> > 
> > See [http://eigenclass.org/hiki.rb?rcov+0.7.0](http://eigenclass.org/hiki.rb?rcov+0.7.0) for the detailed change  
> > summary.
> > 
> > Features  
> > --------  
> > \* coverage/callsite data from multiple runs can be aggregated  
> > (--aggregate)
> > 
> > Bugfixes  
> > --------  
> > \* the SCRIPT\_LINES\_\_ workaround works better  
> > \* fixed silly bug in coverage data acquisition (line after the correct one  
> > &nbsp;&nbsp;marked in some situations)  
> > \* avoid problems with repeated path separators in default ignore list,  
> > based  
> > &nbsp;&nbsp;on rbconfig's data
> > 
> > # 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.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;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 [http://eigenclass.org/hiki.rb?rcov](http://eigenclass.org/hiki.rb?rcov) (once again) for screenshots.
> > 
> > The 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  
> > &nbsp;&nbsp;&nbsp;a +=  
> > 1 | 10  
> > &nbsp;&nbsp;&nbsp;20.times do |i|  
> > \> 10  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b +=  
> > i | 200  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b.timesdo | 200  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c += (j = (b-a).abs) \> 0 ? j : 0 |  
> > 738800  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > \> 0  
> > &nbsp;&nbsp;&nbsp;end  
> > \> 0  
> > end  
> > \> 0
> > 
> > rcov can detect when you've added code that was not covered by your unit  
> > tests:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;$ rcov --text-coverage-diff --no-color test/\*.rb  
> > &nbsp;&nbsp;&nbsp;&nbsp;Started  
> > &nbsp;&nbsp;&nbsp;&nbsp;.......................................  
> > &nbsp;&nbsp;&nbsp;&nbsp;Finished in 1.163085 seconds.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;39 tests, 415 assertions, 0 failures, 0 errors
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;================================================================================  
> > &nbsp;&nbsp;&nbsp;&nbsp;!!!!! Uncovered code introduced in lib/rcov.rb
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;### lib/rcov.rb:207
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def precompute\_coverage(comments\_run\_by\_default = true)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;changed = false  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lastidx = lines.size - 1  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!is\_code?(lastidx) || /^\_\_END\_\_$/ =~ @lines[-1]) &&  
> > !@coverage[lastidx]  
> > &nbsp;&nbsp;&nbsp;&nbsp;!! # mark the last block of comments  
> > &nbsp;&nbsp;&nbsp;&nbsp;!! @coverage[lastidx] ||= :inferred  
> > &nbsp;&nbsp;&nbsp;&nbsp;!! (lastidx-1).downto(0) do |i|  
> > &nbsp;&nbsp;&nbsp;&nbsp;!! break if is\_code?(i)  
> > &nbsp;&nbsp;&nbsp;&nbsp;!! @coverage[i] ||= :inferred  
> > &nbsp;&nbsp;&nbsp;&nbsp;!! end  
> > &nbsp;&nbsp;&nbsp;&nbsp;!! end  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(0...lines.size).each do |i|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next if @coverage[i]  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line = @lines[i]
> > 
> > # Thanks
> > 
> > Thomas Leitner:  
> > \* reported that the SCRIPT\_LINES\_\_ workaround did not always work
> > 
> > Assaph Mehr:  
> > \* beta-tested 0.7.0 and found a bug in --aggregate (missing files)
> > 
> > Ryan Kinderman:  
> > \* suggested that -Ipath be passed to ruby instead of rcov in RcovTasks
> > 
> > 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:
> > 
> > &nbsp;&nbsp;1. Redistributions of source code must retain the above copyright  
> > notice, this  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list of conditions and the following disclaimer.  
> > &nbsp;&nbsp;2. Redistributions in binary form must reproduce the above copyright  
> > notice,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this list of conditions and the following disclaimer in the  
> > documentation  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and/or other materials provided with the distribution.  
> > &nbsp;&nbsp;3. Neither the name of ePark Labs nor the names of its contributors may  
> > be  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used to endorse or promote products derived from this software  
> > without  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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.
> > 
> > --  
> > Mauricio Fernandez - [http://eigenclass.org](http://eigenclass.org) - singular Ruby

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [7 August 2006 03:29 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/3 "2006-08-07T03:29:32Z")

</div>

[http://www.agilewebdevelopment.com/plugins/rails\_rcov](http://www.agilewebdevelopment.com/plugins/rails_rcov)

That plugin takes a lot of the headache out of using rails + rcov.  
(Please don't top post).

> **···**
>
> On Aug 6, 2006, at 11:15 PM, Robert MannI wrote:
> 
> > I am wondering, for a rails project, would this be the correct way to use  
> > this?
> > 
> > rcov -Ilib test/\*\*/\*.rb
> > 
> > That works for me, albeit about 30% of my tests fail then, while when I run  
> > them using the rake task ("rake"), they all pass. So I suppose I must be  
> > doing something wrong.
> > 
> > Thanks alot, great project,

---

<div class="post-metadata">

**Author:** ![Assaph\_Mehr1](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Assaph\_Mehr1](https://rubytalk.org/u/Assaph_Mehr1)\
**Post date:** [7 August 2006 03:54 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/4 "2006-08-07T03:54:45Z")

</div>

This was actually discovered on a rails project. In Rails case there  
seems to be some weird interaction where running all tests  
(integreation and functional for me) causes clashes. The rake tasks  
for rails also launch a separate test process for each, and now rcov  
mimics that.

Using the coverage.task template provided by Mauricio for rails seems  
to fix the issue.

HTH,  
Assaph

> **···**
>
> On 8/7/06, Robert MannI \<robmnl@gmail.com\> wrote:
> 
> > I am wondering, for a rails project, would this be the correct way to use  
> > this?
> > 
> > rcov -Ilib test/\*\*/\*.rb
> > 
> > That works for me, albeit about 30% of my tests fail then, while when I run  
> > them using the rake task ("rake"), they all pass. So I suppose I must be  
> > doing something wrong.

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mauricio\_Fernandez](https://rubytalk.org/u/Mauricio_Fernandez)\
**Post date:** [7 August 2006 11:40 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/5 "2006-08-07T11:40:45Z")

</div>

As Assaph said, this can fail in some circumstances, the reason being that  
unit, functional and integration tests cannot always be run in the same  
process safely; this is why the test task in Rails apps executes them  
separately.

So, if you are lucky and there are no clashes, just

&nbsp;&nbsp;rcov --rails -Ilib test/\*\*/\*\_test.rb

would do. --rails tells rcov to ignore config/, environment/ and vendor/ in  
the statistics.

Now, if you see that the outcome of the tests when run as shown above differs  
from the results given by rake test (as happened to you), you have to execute  
unit, functional and integration tests in three different processes.  
You can do it manually as follows:

&nbsp;&nbsp;rm -f coverage.data  
&nbsp;&nbsp;rcov --no-html --rails --aggregate coverage.data -Ilib test/unit/\*\_test.rb  
&nbsp;&nbsp;rcov --no-html --rails --aggregate coverage.data -Ilib test/functional/\*\_test.rb  
&nbsp;&nbsp;rcov --rails --aggregate coverage.data -Ilib test/integration/\*\_test.rb

--aggregate is used to merge the coverage data from the three runs in a  
single report; --no-html is used in the first two runs because anyway the  
last execution will create the report with all the information.

If you want a recipe to automate that, have a look at  
[http://eigenclass.org/hiki.rb?rcov+0.7.0](http://eigenclass.org/hiki.rb?rcov+0.7.0)  
where I show a small snippet you can dump into e.g. lib/tasks/rcov.rake.  
It will generate a number of tasks in the test:coverage namespace, as well as  
a test:coverage task that runs all the tests under rcov.

Unfortunately, --aggregate is relatively slow because it has to save quite a  
lot of information across runs: all the Ruby code that was parsed, the  
coverage data, etc. There's no way around that though. Of course, you can also  
create separate reports for unit, functional and integration tests (using -o  
to choose the destination dirs for the reports, and omitting --aggregate),  
but you won't be able to obtain a single unified coverage rate that way.

HTH,

> **···**
>
> On Mon, Aug 07, 2006 at 12:15:30PM +0900, Robert MannI wrote:
> 
> > I am wondering, for a rails project, would this be the correct way to use  
> > this?
> > 
> > rcov -Ilib test/\*\*/\*.rb
> > 
> > That works for me, albeit about 30% of my tests fail then, while when I run  
> > them using the rake task ("rake"), they all pass. So I suppose I must be  
> > doing something wrong.
> 
> --  
> Mauricio Fernandez - [http://eigenclass.org](http://eigenclass.org) - singular Ruby

---

<div class="post-metadata">

**Author:** ![Michael\_Trier](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@Michael\_Trier](https://rubytalk.org/u/Michael_Trier)\
**Post date:** [7 August 2006 03:43 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/6 "2006-08-07T03:43:31Z")

</div>

Mauricio thanks for the excellent tool. I use it every day.

Michael

---

<div class="post-metadata">

**Author:** ![Herb\_Asher](https://avatars.discourse-cdn.com/v4/letter/h/7bcc69/32.png) [@Herb\_Asher](https://rubytalk.org/u/Herb_Asher)\
**Post date:** [8 August 2006 08:43 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/7 "2006-08-08T08:43:15Z")

</div>

Mauricio, the coverage tasks is awesome.

It is working for me now.

Speed is not an issue for me, as I only do coverage runs once in a while.

Thank you,  
Rob

> **···**
>
> On 8/7/06, Mauricio Fernandez \<mfp@acm.org\> wrote:
> 
> > On Mon, Aug 07, 2006 at 12:15:30PM +0900, Robert MannI wrote:  
> > \> I am wondering, for a rails project, would this be the correct way to  
> > use  
> > \> this?  
> > \>  
> > \> rcov -Ilib test/\*\*/\*.rb  
> > \>  
> > \> That works for me, albeit about 30% of my tests fail then, while when I  
> > run  
> > \> them using the rake task ("rake"), they all pass. So I suppose I must be  
> > \> doing something wrong.
> > 
> > As Assaph said, this can fail in some circumstances, the reason being that  
> > unit, functional and integration tests cannot always be run in the same  
> > process safely; this is why the test task in Rails apps executes them  
> > separately.
> > 
> > So, if you are lucky and there are no clashes, just
> > 
> > &nbsp;&nbsp;rcov --rails -Ilib test/\*\*/\*\_test.rb
> > 
> > would do. --rails tells rcov to ignore config/, environment/ and vendor/  
> > in  
> > the statistics.
> > 
> > Now, if you see that the outcome of the tests when run as shown above  
> > differs  
> > from the results given by rake test (as happened to you), you have to  
> > execute  
> > unit, functional and integration tests in three different processes.  
> > You can do it manually as follows:
> > 
> > &nbsp;&nbsp;rm -f coverage.data  
> > &nbsp;&nbsp;rcov --no-html --rails --aggregate coverage.data -Ilib  
> > test/unit/\*\_test.rb  
> > &nbsp;&nbsp;rcov --no-html --rails --aggregate coverage.data -Ilib  
> > test/functional/\*\_test.rb  
> > &nbsp;&nbsp;rcov --rails --aggregate coverage.data -Ilib test/integration/\*\_test.rb
> > 
> > --aggregate is used to merge the coverage data from the three runs in a  
> > single report; --no-html is used in the first two runs because anyway the  
> > last execution will create the report with all the information.
> > 
> > If you want a recipe to automate that, have a look at  
> > [http://eigenclass.org/hiki.rb?rcov+0.7.0](http://eigenclass.org/hiki.rb?rcov+0.7.0)  
> > where I show a small snippet you can dump into e.g. lib/tasks/rcov.rake.  
> > It will generate a number of tasks in the test:coverage namespace, as well  
> > as  
> > a test:coverage task that runs all the tests under rcov.
> > 
> > Unfortunately, --aggregate is relatively slow because it has to save quite  
> > a  
> > lot of information across runs: all the Ruby code that was parsed, the  
> > coverage data, etc. There's no way around that though. Of course, you can  
> > also  
> > create separate reports for unit, functional and integration tests (using  
> > -o  
> > to choose the destination dirs for the reports, and omitting --aggregate),  
> > but you won't be able to obtain a single unified coverage rate that way.
> > 
> > HTH,  
> > --  
> > Mauricio Fernandez - [http://eigenclass.org](http://eigenclass.org) - singular Ruby

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_Cra1](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Meino\_Christian\_Cra1](https://rubytalk.org/u/Meino_Christian_Cra1)\
**Post date:** [7 August 2006 04:29 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/8 "2006-08-07T04:29:13Z")

</div>

Hi,

sorry for being -- may be -- a little offtopic.

Currently I am playing around with """""encryption""""" -- the  
meaning of all those "'s is: "Encryption" in the sense of "convert  
readable text into unreadable text" not in the sense of "Bullet  
proof encryption suitable for secret service agents".

Just something to play around with...

What I need is the following "device":

Input is a freely defineable range of anything a byte can stand  
for. Output is again a value of the same range. This mapping from an  
input to an output value should be made variable in two manners:  
First is to change the mapping itsself the second way is to define  
an offset. This should work as follows:

Without offset: With offset 3:

A -\> Z A -\> I // wrapped around from the end  
B -\> H B -\> B // of the previously defined  
C -\> L C -\> Q // range  
D -\> P D -\> Z  
E -\> F E -\> H  
F -\> D F -\> L  
. G -\> P  
. H -\> F  
. I -\> D

The offset should be changeable at each new mapping action.

My first idea was to define an Hash which maps an input range  
to an index. To this index it is easy to add an offset. The  
second step would be an array, which maps the new calculated index  
(old index + offset) to the same range again, but this time  
the range was "sorted" by sort{rand} st initialization time.

But when I do a "a=device.new", what should I return as an obejct  
to the caller ??? TWO objects -- the hash AND the array ?

I am curious whether there are better, more elegant ways to accomplish  
this in a more rubyish way.

I would be happy to read of your ideas how to implement this! 🙂  
Thank you very much in advance for any help and any idea !

Ruby! 🙂  
mcc

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [7 August 2006 13:48 UTC](https://rubytalk.org/t/ann-rcov-0-7-0-code-coverage-for-ruby/29627/9 "2006-08-07T13:48:30Z")

</div>

The whole point of wrapping something like this is in an object is that these are just internal details user code for the object never needs to worry about. For example, users are going to call your code something like:

&nbsp;&nbsp;&nbsp;dev = Device.new( .. )  
&nbsp;&nbsp;&nbsp;after = dev.encryrpt(before)

All they know is that they are working with a Device. They don't need to worry about Hashes and Arrays.

I recommend using a Hash internally in the object. When a problem says "mapping" that usually means Hash. You could build the interface to handle either a Hash or an Integer being passed to the constructor:

&nbsp;&nbsp;&nbsp;class Device  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def initialize(mapping\_or\_offset)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if mapping\_or\_offset.is\_a? Hash  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@mapping = build\_mapping\_from\_hash(mapping\_or\_offset)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else # offset  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@mapping = build\_mapping\_from\_integer(mapping\_or\_offset)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def encrypt(bytes)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# use @mapping here...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def build\_mapping\_from\_hash(hash)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def build\_mapping\_from\_integer(integer)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;end

Hope that gives you some fresh ideas.

James Edward Gray II

> **···**
>
> On Aug 6, 2006, at 11:29 PM, Meino Christian Cramer wrote:
> 
> > My first idea was to define an Hash which maps an input range  
> > to an index. To this index it is easy to add an offset. The  
> > second step would be an array, which maps the new calculated index  
> > (old index + offset) to the same range again, but this time  
> > the range was "sorted" by sort{rand} st initialization time.
> > 
> > But when I do a "a=device.new", what should I return as an obejct  
> > to the caller ??? TWO objects -- the hash AND the array ?
