I am trying my hand at writing a rakefile, and have what I think should call simplecov and then call rspec to run tests, but when I run my rakefile nothing gets executed. Am I doing something wrong? Also, is there a way to give the :spec
task a dependency, I want it to call :simplecov
before it executes.
require 'rake'
task :coverage do
require 'simplecov'
SimpleCov.start 'rails'
end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => [:coverage, :spec]
Unfortunately default can only have one task but you're welcome to use a namespace to package tasks together. Yours might look like:
require 'rake'
namespace :rspec_cov do
task :coverage do
require 'simplecov'
SimpleCov.start 'rails'
end
task :spec do
sh 'bundle exec rspec'
end
end
task :testing => ["rspec_cov:coverage", "rspec_cov:spec"]
now running rake testing
will run both those tasks as you wanted. On a totally separate note, if you receive an exit code issue (like I did) there seems to be a bug in SimpleCov that they're working on (issue here).