Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RCov for RSpec 2 not detecting coverage correctly? (not Rails!)

Preface
I've just started getting into Ruby and try to not only learn the language but also some development strategies. As kind of a beginner I'm concentrating on Test and Behaviour Driven Development. (yes, I'm doing both for comparison purposes)

With my small software project I'm using

  • UnitTest (TDD)
  • Cucumber (BDD)
  • Rspec (TDD and BDD)

On various places I encountered RCov as a tool for telling me how much of my actual code I'm really testing.

I set up the following RakeTask in my Rakefile for the covarage analysis of the UnitTests:

desc "Run RCov to get coverage of UnitTests"
Rcov::RcovTask.new(:rcov_units) do |t|
  t.pattern = 'tests/**/tc_*.rb'
  t.verbose = true
  t.rcov_opts << "--html"
  t.rcov_opts << "--text-summary"
  t.output_dir = "coverage/tests"
end

This works fine and I'm getting a nice coloured HTML report in coverage/tests.

Problem Introduction
Similar I wrote the following RakeTasks for RCov to be used for coverage analysis of my specs:

desc "Run RCov to get coverage of Specs"
Rcov::RcovTask.new(:rcov_spec) do |t|
  t.pattern = 'spec/**/*_spec.rb'
  t.verbose = true
  t.rcov_opts << "--html"
  t.rcov_opts << "--text-summary"
  t.output_dir = "coverage/spec"
end

Problem Definition
However, the generated HTML report in coverage/spec looks somehow incomplete and almost failed.

None of the tested method bodies are marked as covered and thus red. However, I'm 100% sure they are executed within the specs. Only the lines def method_name(args) and class ClassName are marked 'green'. (as well lines with attr_reader :instance_variable)

Am I missing something?


$: ruby --version  
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]

$: rspec --version  
2.8.0

$: rcov --version  
rcov 0.9.11 2010-02-28

$: rake --version  
rake, version 0.9.2
like image 664
Torbjörn Avatar asked Jan 16 '12 21:01

Torbjörn


1 Answers

I've got similar trouble. I am 100% sure that specs are not executed when I run them win RCov. But they do when I disable RCov.

Downgrading RSpec to version 2.6.0 helped me.

like image 165
Sergey Potapov Avatar answered Oct 17 '22 06:10

Sergey Potapov