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?
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.
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.
I found the solution.
$ gem install ruby-debug $ ruby-debug rake my:task
or on some systems
$ rdebug rake my:task
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.
gem 'debugger'
to my Gemfile's development group.bundle
.require 'debugger'
to the top of my rake task.debugger
where I wanted a breakpoint in my rake task.rake my:task
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With