Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make coverage work in 1.8, 1.9 and jruby for both

Use Rcov for 1.8 in both mri and jruby, and simplecov for coverage in 1.9
  • Loading branch information...
commit 5c80a9c2666d27c04b0b47b17703f25dfd0cc936 1 parent 60cb0d6
Jeremy Hinegardner authored May 17, 2012
41  Rakefile
@@ -56,7 +56,7 @@ task :develop => "develop:default"
56 56
 begin
57 57
   require 'rspec/core/rake_task'
58 58
   RSpec::Core::RakeTask.new( :test ) do |t|
59  
-    t.ruby_opts    = %w[ -w ]
  59
+    #t.ruby_opts    = %w[ -w ]
60 60
     t.rspec_opts   = %w[ --color --format documentation ]
61 61
   end
62 62
   task :default => :test
@@ -86,17 +86,30 @@ end
86 86
 # Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
87 87
 #            for the moment only rcov is listed.
88 88
 #------------------------------------------------------------------------------
89  
-begin
90  
-  require 'rcov/rcovtask'
91  
-  Rcov::RcovTask.new do |t|
92  
-    t.libs      << 'spec'
93  
-    t.pattern   = 'spec/**/*_spec.rb'
94  
-    t.verbose   = true
95  
-    t.rcov_opts << "-x ^/"           # remove all the global files
96  
-    t.rcov_opts << "--sort coverage" # so we see the worst files at the top
  89
+if RUBY_VERSION < "1.9.2"
  90
+  begin
  91
+    require 'rcov/rcovtask'
  92
+    Rcov::RcovTask.new( :coverage ) do |t|
  93
+      t.libs      << 'spec'
  94
+      t.pattern   = 'spec/**/*_spec.rb'
  95
+      t.verbose   = true
  96
+      t.rcov_opts << "-x ^/"           # remove all the global files
  97
+      t.rcov_opts << "--sort coverage" # so we see the worst files at the top
  98
+    end
  99
+  rescue LoadError
  100
+    Util.task_warning( 'rcov' )
  101
+  end
  102
+else
  103
+  begin
  104
+    require 'simplecov'
  105
+    desc "Run tests with code coverage"
  106
+    task :coverage do
  107
+      ENV['COVERAGE'] = 'true'
  108
+      Rake::Task[:test].execute
  109
+    end
  110
+  rescue LoadError
  111
+    Util.task_warning( 'simplecov' )
97 112
   end
98  
-rescue LoadError
99  
-  Util.task_warning( 'rcov' )
100 113
 end
101 114
 
102 115
 #------------------------------------------------------------------------------
@@ -163,7 +176,11 @@ This.gemspec = Gem::Specification.new do |spec|
163 176
 
164 177
   # The Development Dependencies
165 178
   spec.add_development_dependency( 'rake'  , '~> 0.9.2.2')
166  
-  spec.add_development_dependency( 'rcov'  , '~> 1.0.0'  )
  179
+  if RUBY_VERSION < "1.9.2" then
  180
+    spec.add_development_dependency( 'rcov'  , '~> 0.9.11'  )
  181
+  else
  182
+    spec.add_development_dependency( 'simplecov', '~> 0.6.4' )
  183
+  end
167 184
   spec.add_development_dependency( 'rspec' , '~> 2.8.0'  )
168 185
   spec.add_development_dependency( 'rdoc'  , '~> 3.12'   )
169 186
 
6  spec/spec_helper.rb
... ...
@@ -1,3 +1,8 @@
  1
+if RUBY_VERSION >= '1.9.2' then
  2
+  require 'simplecov'
  3
+  SimpleCov.start if ENV['COVERAGE']
  4
+end
  5
+
1 6
 require "rspec/autorun"
2 7
 require 'qup'
3 8
 
@@ -24,3 +29,4 @@ def temp_dir( token, unique_id = Process.pid )
24 29
     end
25 30
   end
26 31
 end
  32
+

0 notes on commit 5c80a9c

Please sign in to comment.
Something went wrong with that request. Please try again.