Ruby on Rails:调试rake任务

Ruby on Rails:调试rake任务

问题描述:

当我写调试器它不会启动:

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

如果我运行 rake my:task --debugger ,它立即返回到控制台。如何调试耙子任务?

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

Andrey Kouznetsov的答案对我使用Ruby 1.9.3没有用。 ruby-debug gem似乎不支持Ruby 1.9。我不得不使用调试器宝石: https://github.com/cldwalker/debugger

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. gem'debugger'添加到我的Gemfile的开发组。

  2. 运行

  3. require'debugger'添加到我的耙子顶部

  4. 添加调用 debugger 我想要在我的耙子任务中使用断点。

  5. 从命令行正常运行耙子任务,例如: rake my:task

  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.