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.
- 将
gem'debugger'
添加到我的Gemfile的开发组。 - 运行
束
。 - 将
require'debugger'
添加到我的耙子顶部 - 添加调用
debugger
我想要在我的耙子任务中使用断点。 - 从命令行正常运行耙子任务,例如:
rake my:task
。
- Add
gem 'debugger'
to my Gemfile's development group. - Run
bundle
. - Add
require 'debugger'
to the top of my rake task. - Add a call to
debugger
where I wanted a breakpoint in my rake task. - Run the rake task normally from the command line, e.g.:
rake my:task
.