Debugging in RubyMine

May 21, 2013 Jared Carroll

Before using RubyMine, my debugging workflow went something like this:

Why isn’t this test passing?. It should’ve passed. Let me add a few Kernel#puts calls to see what’s going on. Hmmm, ok, it’s still failing. I’m going to need some more output. Man, these tests take forever to run. Syntax error?!. Ugh, typo…

Debugging like this isn’t fun; especially when pairing. Fortunately, RubyMine can help. RubyMine includes a standard debugger that has minimal setup and works out of the box. I still don’t enjoy debugging, but RubyMine has made it much less painful. In this post, we’ll look at debugging in RubyMine on OS X.

Setting Breakpoints

Add or remove breakpoints with command + F8.

breakpoint.png

View existing breakpoints with command + shift + F8.

view-breakpoints.png

Starting the Debugger

Debug the current program with control + shift + D. This will automatically open the Debug tool window (command + 5).

debug-tool-window.png

Use control + D to re-run the last debug session. View recent debug sessions with control + alt/option + D.

debug-menu.png

Examining a Program

Examine variables in the Debug tool window’s variables pane.

variables.png

Use command + N in the Debug tool window’s Watches pane to watch a specific variable. backspace will delete a watch.

watches.png

Use alt/option + F8 to evaluate arbitrary expressions. control + space triggers autocompletion.

evaluate-expression.png

Instead of using the Debug tool window, examine a variable inline by placing your cursor on it and pressing command + alt/option + F8.

quick-evaluate-expression.png

Stepping through a Program

Step into a method with F7. Step over a method with F8. Step out of a method with shift + F8.

Use your cursor as a temporary breakpoint with alt/option + F9. Continue your debug session with F9.

Stop #puts’ing

If you’re using an IDE, take time to learn its debugger. Don’t litter your code with Kernel#puts and friends. Instead, set a breakpoint, start the debugger, examine some objects, and slowly step through your problems.

About the Author

Biography

Previous
Simple Test Parallelization
Simple Test Parallelization

Let’s look at a simple approach to parallelizing a test suite for a Ruby app. Parallelizing your specs can ...

Next
A Responsible Recipe for the Fewest Possible Meetings
A Responsible Recipe for the Fewest Possible Meetings

Meetings are crucial to healthy team communication. But they’re also opportunities for waste, occasionally ...