The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
rcov 0.8.1: compatibility with Ruby 1.8.6-p11[01], intentional testing with RSpec, etc.

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
rcov 0.8.1: compatibility with Ruby 1.8.6-p11[01], intentional testing with RSpec, etc. Posted: Nov 19, 2007 4:01 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: rcov 0.8.1: compatibility with Ruby 1.8.6-p11[01], intentional testing with RSpec, etc.
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

Version 0.8.1 of the rcov code coverage tool for Ruby addresses the problems experienced by ruby 1.8.6-p11[01] (and in particular Leopard) users, and includes a few new features.

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

"Spec-only" mode

You can indicate that only code executed inside a spec must be considered covered (this is similar to --test-unit-only).

Here's a minimal example. Consider this target code:

# bowling.rb
class Bowling
  def hit(pins)
  end

  def score
    0
  end

  def num_throws
    1
  end
end

and the following spec:

require 'rubygems'
require 'spec'
require 'bowling'

describe Bowling do
  before(:each) do
    @bowling = Bowling.new
  end

  it "should score 0 for gutter game" do
    20.times { @bowling.hit(0) }
    @bowling.score.should == 0
  end
end

Bowling.new.num_throws

If you invoke rcov with the --spec-only option, you'll obtain:

$ rcov --text-coverage --no-color --spec-only bowling_spec.rb 
.

Finished in 0.016369 seconds

1 example, 0 failures
 ================================================================================
bowling.rb
================================================================================
!! # bowling.rb
!! class Bowling
     def hit(pins)
     end
   
     def score
       0
     end
!! 
!!   def num_throws
!!     1
!!   end
!! end
   
================================================================================
bowling_spec.rb
================================================================================
!! require 'spec'
!! require 'bowling'
   
   describe Bowling do
     before(:each) do
       @bowling = Bowling.new
     end
   
     it "should score 0 for gutter game" do
       20.times { @bowling.hit(0) }
       @bowling.score.should == 0
     end
   end
!! 
!! Bowling.new.num_throws

Note how the num_throws method is not covered: it wasn't executed inside the spec. This allows you to differentiate deliberate from "accidental" code coverage.

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.8.0)


Read more...

Read: rcov 0.8.1: compatibility with Ruby 1.8.6-p11[01], intentional testing with RSpec, etc.

Topic: Just Published a New Book: "Troubleshooting Ruby Processes: Leveraging the Unix Platform When... Previous Topic   Next Topic Topic: Class Methods Part IV - DSL's

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use