Search code examples
rubyrake

Invoke namespaced rake task in ruby code


Given some ruby file foo.rb:

require 'rake'

namespace :tmp do
  desc "Foo bar baz.."
  task :some_task do
    puts "running some task..."
  end
end

How can I invoke the namespaced task tmp:some_task task in ruby?

I've tried:

require_relative 'foo'
#=> true
Rake::Task[tmp:some_task].invoke
#=> NameError: undefined local variable or method `some_task' for main:Object

Solution

  • You are calling the task incorrectly - pass the name of the task as string:

    Rake::Task['tmp:some_task'].invoke