Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Rake task to the default Rake task?

Tags:

ruby

rake

Somehow Rspec and Cucumber are making it into my default rake task (which is fine because I want them there). But I have tried adding additional tasks to the default task and it has no effect.

What is the proper way to add tasks to the default rake task?

like image 346
Andrew Avatar asked May 17 '13 06:05

Andrew


Video Answer


2 Answers

Typically your Rakefile will have something like this:

task :default => [:spec] 

You just need to add more tasks into this list.

like image 56
davogones Avatar answered Nov 01 '22 08:11

davogones


The answer from davogenes is correct for non-namespaced rake tasks.

If you want to have a default task in namespaces you need to do the following

namespace :mynamespace do   desc "This should be the default"   task :mydefault do     Do.something_by_default   end    desc "Another task in this namespace"   task :other do     Do.something   end end  desc "This is the default task of mynamespace" task mynamespace: 'mynamespace:mydefault' 

Then you can run rake mynamespace as well as rake mynamespace:other or rake mynamespace:mydefault.

like image 30
basiszwo Avatar answered Nov 01 '22 09:11

basiszwo