Skip to content

Instantly share code, notes, and snippets.

@alexdreher
Forked from zhengjia/gist:395021
Created November 10, 2010 00:24
Show Gist options
  • Save alexdreher/670111 to your computer and use it in GitHub Desktop.
Save alexdreher/670111 to your computer and use it in GitHub Desktop.
rcov raketask for Rails 3, RSpec 2
# Forked to get it working with Rails 3 and RSpec 2
#
# From http://github.com/jaymcgavren
#
# Save this as rcov.rake in lib/tasks and use rcov:all =>
# to get accurate spec/feature coverage data
#
# Use rcov:rspec or rcov:cucumber
# to get non-aggregated coverage reports for rspec or cucumber separately
require 'cucumber/rake/task'
require "rspec/core/rake_task"
namespace :rcov do
Cucumber::Rake::Task.new(:cucumber_run) do |t|
t.rcov = true
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/ --aggregate coverage.data}
t.rcov_opts << %[-o "coverage"]
end
RSpec::Core::RakeTask.new(:rspec_run) do |t|
t.pattern = 'spec/**/*_spec.rb'
t.rcov = true
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/}
end
desc "Run both specs and features to generate aggregated coverage"
task :all do |t|
rm "coverage.data" if File.exist?("coverage.data")
Rake::Task["rcov:cucumber_run"].invoke
Rake::Task["rcov:rspec_run"].invoke
end
desc "Run only rspecs"
task :rspec do |t|
rm "coverage.data" if File.exist?("coverage.data")
Rake::Task["rcov:rspec_run"].invoke
end
desc "Run only cucumber"
task :cucumber do |t|
rm "coverage.data" if File.exist?("coverage.data")
Rake::Task["rcov:cucumber_run"].invoke
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment