eigenclass logo
MAIN  Index  Search  Changes  PageRank  Login

rcov 0.8.0 (Ruby code coverage): new output modes, fix for RSpec woes, superior emacs integration

Version 0.8.0 of the rcov code coverage tool for Ruby introduces new output modes and superior emacs integration. It also fixes a nasty bug in the rcovrt extension. If you have been getting segfaults or bus errors when using rcov with RSpec, give 0.8.0 a try.

If you are new to rcov, take a look at this sample report. In addition to indicating which code has been covered by your tests, rcov allows you to navigate through your code easily. rcov records where each method was called from and can generate fully cross-referenced reports, letting you inspect the control flow. This is most useful when you're trying to understand the overall organization of third-party code or you're refactoring.

cross-refs-teaser.png

Download

You can get it from rcov: code coverage for Ruby, or install it via RubyGems with

 gem install rcov

(if you get an older version/a 404 error, just wait for a while until the gem propagates to rubyforge's mirrors)

Change summary (since 0.7.0)

Features

  • --annotate mode, which dumps annotated source code which can be used to follow the control flow (very useful when reading third-party code)
  • --gcc option to display uncovered lines in GCC error format
  • superior Emacs support: running rcov, jumping to uncovered code, navigate through cross-referenced annotated code
  • --[no-]validator-links

Bugfixes

  • differential code coverage reports work with filenames containing special characters
  • fixed recent segfaults happening with rspec
  • more careful name mangling

Minor enhancements

  • relevant summary values are identified using separate CSS classes (microformat-style)

Thanks

rubikitch

  • implemented --annotate mode
  • implemented --gcc option
  • superior emacs support
  • testing, refactoring...
  • many other things, see darcs changes

Zed A. Shaw

  • reported and fixed segfault triggered by rspec

Jan Svitok

  • reported typo in rcovtask.rb's RDoc

Thomas Leitner

  • fixed the bug which broke differential reports for filenames with special characters


incorrect reporting of empty rescue clause - David Chelimsky (2007-02-28 (Wed) 06:50:42)

First, thanks for rcov. It has played an important role in the development of rspec for quite some time now.

I did, however, just discover the following bug.

Given this class:

 class Example
   def with_nothing_in_rescue
     begin
       raise "an error"
     rescue => @error
     end
   
     raise @error
   end
   def with_something_in_rescue
     begin
       raise "an error"
     rescue => @error
       @something = "something"
     end
   
     raise @error
   end
 end

and this test:

 require 'example'
 require 'test/unit' 
 class ExampleTest < Test::Unit::TestCase
 
   def test_example_with_nothing_in_rescue
     assert_raises(RuntimeError) do
       Example.new.with_nothing_in_rescue
     end
   end
 
   def test_example_with_something_in_rescue
     assert_raises(RuntimeError) do
       Example.new.with_something_in_rescue
     end
   end
 end

and this spec:

 require 'example'
 require 'rubygems'
 gem 'rspec'
 require 'spec'
 context "Example" do
   specify "with_nothing_in_rescue should raise error" do
     lambda {Example.new.with_nothing_in_rescue}.should_raise
   end
   specify "with_something_in_rescue should raise error" do
     lambda {Example.new.with_something_in_rescue}.should_raise
   end
 end

All the tests and specs pass and RCov correctly reports that the rescue block in #with_something_in_rescue is covered. RCov does not, however, report that the rescue block in #with_nothing_in_rescue is covered.

mfp 2007-02-28 (Wed) 13:24:13

First of all, thank you for the detailed report.

rcov depends on Ruby's event_hook system, which unfortunately doesn't report any event in the above case (so there's no way for rcov to know whether the rescue clause has actually been executed or not).

One workaround would be adding a dummy expression in the rescue clause, like

 rescue => e
   nil
 end

This would be enough to make Ruby report a "line" event and allow rcov to detect that line.


Hooray! - James (2007-02-28 (Wed) 09:13:00)

Thank you, and thank you to all the contributors. I really enjoy this tool.


Combined coverage report - Brittain (2007-02-28 (Wed) 09:52:50)

In 0.7 rcov introduced coverage reports that would aggregate your functionals and units, but I've never found adequate examples to get this working. Would you post something straightforward for this please?

Thanks.

mfp 2007-02-28 (Wed) 13:28:02

You can find some Rake tasks that allow you to aggregate functional, unit and integration runs in the rcov FAQ. ("How can I run all rails tests, like in the example?")


Weird String bug - Toby (2007-05-24 (Thr) 13:01:48)

<code> print %Q{

  1. {'one'}

two

} </code>

If you run this with rcov, the code runs fine, but in the coverage report you'll discover that lines 1-3 were reported as not run. One work around is to use another charactor as the multi-line string delimiter.


html reports encoding - Christos Trochalakis (2007-06-14 (Thr) 02:04:00)

Can we change the html reports encoding somehow?

mfp 2007-06-14 (Thr) 14:59:18

There's no Content-Type META declaration in the generated reports, so your browser will use the charset/encoding indicated by the HTTP server (when that applies).

I'm adding this to the TODO.


No Title - Christos Trochalakis (2007-06-17 (Sun) 01:44:25)

nice! And thanks for this excelent tool :)


Last modified:2007/02/28 04:39:42
Keyword(s):[blog] [ruby] [frontpage] [rcov] [0.8.0] [release] [code] [coverage]
References:[rcov: code coverage for Ruby]