Thursday, October 25, 2007

Stepping through your rails action code

For a long time I couldn't figure out what I could do with breakpoint. Other than running console like operations and inspecting instance variables, I couldn't seem to do much. So I relied mostly on logger.warn and console kind of debugging. Of course, I didn't have to debug much since I write a lot of tests ;)

I come from perl world which has an awesome debugger available. I wanted to be able to step through the code and inspect my local variables in a loop and break on conditionals etc.

Recently I found ruby-debug and it seems to do all the things I have been wanting to do.

The debugger drops me in the action and much to my delight I could inspect loop variables and break on conditionals. Inspecting variables is easy using the command "p".
I ran irb at the rdb prompt and it dropped me into a script/console like environment. The scope is still at the action. Much much better than where breakpoint drops me (lib/breakpoint).

Check it out. I know it will make my life a lot more easier now.


No comments: