tags:

views:

32

answers:

1

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.)

+1  A: 

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.

rocky