【发布时间】:2013-05-12 05:34:42
【问题描述】:
不知何故,Rspec 和 Cucumber 正在将其纳入我的默认 rake 任务(这很好,因为我希望它们在那里)。但是我已经尝试在默认任务中添加额外的任务,但没有任何效果。
将任务添加到默认 rake 任务的正确方法是什么?
【问题讨论】:
不知何故,Rspec 和 Cucumber 正在将其纳入我的默认 rake 任务(这很好,因为我希望它们在那里)。但是我已经尝试在默认任务中添加额外的任务,但没有任何效果。
将任务添加到默认 rake 任务的正确方法是什么?
【问题讨论】:
davogenes 的答案对于非命名空间的 rake 任务是正确的。
如果您想在命名空间中有一个默认任务,您需要执行以下操作
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'
然后您可以运行rake mynamespace 以及rake mynamespace:other 或rake mynamespace:mydefault。
【讨论】:
rake --tasks 中(只有 mynamespace 和 mynamespace:other 会出现在 --tasks然后命令)。如果你不这样做,两者都将出现在 --tasks 命令中,因此看起来是重复的。
通常你的 Rakefile 会有这样的东西:
task :default => [:spec]
您只需在此列表中添加更多任务。
【讨论】: