Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created June 10, 2013 13:49
Show Gist options
  • Save natritmeyer/5748847 to your computer and use it in GitHub Desktop.
Save natritmeyer/5748847 to your computer and use it in GitHub Desktop.
How to add task dependencies to custom rake tasks that don't allow for the normal rake task behaviour around setting task dependencies.
# Example Rakefile that demonstrates how to add task dependencies
# to custom rake tasks that don't allow for the normal rake task
# behaviour around setting task dependencies.
require 'cucumber/rake/task'
# here's the task that I want to run before any of my cucumber tasks (see below)
namespace :stub do
desc "Start stub required by features"
task :start do
puts "Starting stub"
# `command to start stub`
end
end
namespace :cuke do
Cucumber::Rake::Task.new(:all, "Run all the features") do |t|
t.libs << 'lib'
end
Cucumber::Rake::Task.new(:wip, "Run only wip features") do |t|
t.libs << 'lib'
end
#here's the magic:
# 1) select all tasks that begin with the "cuke:" namespace
tasks_in_cuke_namespace = Rake.application.tasks.select {|task| task.name.start_with? "cuke:"}
# 2) call #enhance on each of those tasks, passing an array of task dependencies
tasks_in_cuke_namespace.each do |task|
task.enhance ["stub:start"]
end
end
@natritmeyer
Copy link
Author

That looks quite cool...

@natritmeyer
Copy link
Author

Good post on adding after-hooks the rake way: http://www.dan-manges.com/blog/modifying-rake-tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment