Andrey Kuznetsov Andrey Kuznetsov - 10 months ago 88
Ruby Question

Ruby on Rails: debugging rake tasks

When I write

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?

Answer Source

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:

  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.