开发者

Why won't ruby-debug allow me to see local variables in my specs?

I am trying to use ruby-debug to debug my specs. When i do this, i am not able to access local variables. Instance variables, however, are fine. Is there a way to make this work with local variables?

Here is an example spec:

require 'spec/autorun'
describe "empty spec" do
  it "should be able to be debugged" do
    x = 'foo'
    @x = 'bar'
    debugger
  end
end
开发者_开发百科

In the debugger/irb, i can see @x but not x. Detailed output.

Is this just a limitation of using ruby-debug with blocks or is this something I can make work for me?

(In the mean time, i'm using more instance variables than i really should in my specs.)


The example you cite is problematic with ruby-debug. ruby-debug has a limitation that it only stops at statement "line" events and the "debugger" call is the last statement of a block. Therefore in the example you give by the time the debugger stops you are no longer in the "should be able to be debugged" block and x is gone.

One workaround that programmers seem to use a bit is to put some sort of statement after "debugger" but before the end.

In the next incarnation rbdbgr (for YARV Ruby 1.9 with patches), you can stop before returning from the block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜