Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: debugging rake tasks

When I write debugger it does not start:

NoMethodError: undefined method `run_init_script' for Debugger:Module from /usr/local/lib/ruby/gems/1.8/gems/ruby-debug-base-0.10.3/lib/ruby-debug-base.rb:239:in `debugger' from (irb):4 

If I run rake my:task --debugger,it returns me to console immediately. How is it possible to debug rake tasks?

like image 601
Andrey Kuznetsov Avatar asked Apr 18 '10 20:04

Andrey Kuznetsov


People also ask

What is Rake task in Ruby on Rails?

Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.

How do I see all Rake tasks?

You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks . Each task has a description, and should help you find the thing you need.


2 Answers

I found the solution.

$ gem install ruby-debug $ ruby-debug rake my:task 

or on some systems

$ rdebug rake my:task 
like image 156
Andrey Kuznetsov Avatar answered Sep 24 '22 14:09

Andrey Kuznetsov


Andrey Kouznetsov's answer didn't work for me using Ruby 1.9.3. The ruby-debug gem doesn't seem to support Ruby 1.9. I had to use the debugger gem: https://github.com/cldwalker/debugger.

  1. Add gem 'debugger' to my Gemfile's development group.
  2. Run bundle.
  3. Add require 'debugger' to the top of my rake task.
  4. Add a call to debugger where I wanted a breakpoint in my rake task.
  5. Run the rake task normally from the command line, e.g.: rake my:task.
like image 29
Liron Yahdav Avatar answered Sep 23 '22 14:09

Liron Yahdav