我目前收到的错误如下:
NoMethodError: undefined method `debug' for nil:NilClass
/mnt/hgfs/Dropbox/Company/Project/lib/project/misc.rb:23:in `debug'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:49:in `block in compare_addresses'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `each'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `compare_addresses'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:32:in `valid?'
/mnt/hgfs/Dropbox/Company/Project/specs/project/validation/google_geocoding_validation_engine_spec.rb:56:in `block (2 levels) in <module:Validation>'
/home/tomas/ruby2/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
我想我会尝试使用byebug找出对象为nil
的原因,因为它永远不应该是nil
。我将byebug
放在错误的行上方:
def debug(&block)
if @logger.nil?
byebug
end
@logger.debug(@logger_name, &block)
end
并进行了测试。我被放到了byebug调试界面,可以确认对象确实是nil
。问题是我无法爬上筹码:
(byebug) up
*** Adjusting would put us beyond the oldest (initial) frame.
(byebug) down
*** Adjusting would put us beyond the newest (innermost) frame.
(byebug) backtrace
--> #0 AddressKit::Misc::Logging.debug(block#Proc) at /mnt/hgfs/Dropbox/Kvantel/Address Kit/lib/addresskit/misc.rb:25
Warning: saved frames may be incomplete; compare with caller(0)
为什么我不能上堆?这是byebug的问题,还是与MiniTest不兼容?
答案 0 :(得分:5)
在像这样的情况下打印和移动callstack应该正常工作并且OP不会有这个问题。
Byebug在调用Byebug.start
之前不会开始跟踪callstack信息,byebug
命令在内部调用它。因此,当您收到调试提示时,只保存了一个callstack框架,这就是您收到该消息的原因:
Warning: saved frames may be incomplete; compare with caller(0)
这就是为什么你无法移动up
或down
:只有一帧。
要正确浏览堆栈,您需要将Byebug.start
放在更高的位置,以便开始跟踪callstack信息。例如,在google_geocoding_validation_engine_spec.rb
中的第56行之前。如果您想要完整的堆栈信息,可以通过运行byebug可执行文件从一开始就运行byebug:
byebug rake
或者你正在运行你的规格。
如果您仍有问题,请告诉我们!
希望这有帮助。