Adding to the default Rake task
You have a Rails app with a Rakefile. When you type
rake, it runs all the tests (or specs if you prefer).
You want it to do something else as well: let’s say you want to run
RuboCop on your
Don’t do this:
task(:default).clear task default: [:spec, :rubocop]
Do this instead:
task(:default).prerequisites << task(:rubocop)
Update or just this: as Avdi points out, it’s the same.
task default: :rubocop
With the first pattern, you need to collect together all the tasks in one place, and it’s easy to accidentally redefine the prerequisites so that something that you thought was running isn’t any longer.
With the second pattern, however, you can configure each
additional task in a self-contained file in
lib/tasks/[name].rake, and they won’t step on each