A Clean, Well-Lighted Place

Overwriting "Rake Spec" Task

So you want to change the default behavior of rake spec task? You can do that using RakeTask#clear and RakeTask#enhance methods.

Example:

require 'rake'
require 'rspec/core/rake_task'

task :noop do; end
spec_prereq = Rails.configuration.generators.options[:rails][:orm] == :active_record ?  "db:test:prepare" : :noop

namespace :spec do
  RSpec::Core::RakeTask.new(:lite) do |t|
    t.pattern = "spec/{models,presenters}/**/*_spec.rb"
  end
  RSpec::Core::RakeTask.new(:with_rails) do |t|
    t.pattern = "spec/{controllers,integration}/**/*_spec.rb"
  end
end

task(:spec).clear.enhance([spec_prereq, "spec:lite", "spec:with_rails"])

Comments