Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created June 10, 2013 13:49

Revisions

  1. natritmeyer created this gist Jun 10, 2013.
    34 changes: 34 additions & 0 deletions Rakefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    # 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