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#putscalls 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.
Add or remove breakpoints with
command + F8.
View existing breakpoints with
command + shift + F8.
Starting the Debugger
Debug the current program with
control + shift + D. This will automatically open the Debug tool window (
command + 5).
control + D to re-run the last debug session. View recent debug sessions with
control + alt/option + D.
Examining a Program
Examine variables in the Debug tool window’s variables pane.
command + N in the Debug tool window’s Watches pane to watch a specific variable.
backspace will delete a watch.
alt/option + F8 to evaluate arbitrary expressions.
control + space triggers autocompletion.
Instead of using the Debug tool window, examine a variable inline by placing your cursor on it and pressing
command + alt/option + F8.
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
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
BiographyMore Content by Jared Carroll