|Tech Tip: debugging Ruby’s rspec scripts
||[Aug. 18th, 2012|02:13 pm]
This post will cover how to debug test scripts (and their equivlent
production code) of the Ruby programming language’s
RSpec framework using an interactive
debugger, which was a problem I've
ran into lately when working on some Ruby code. Most of the other posts I
found about the topic were either incomplete or out-of-date, but I got
some help from #ruby-lang on Freenode, so I was able to figure it
What you should do is:
install the ruby-debug gem: gem install ruby-debug.
Add require 'ruby-debug' to the top of the test script.
Add a debugger statement to lines where you want to place a
breakpoint. This is important because otherwise the debugger will never
stop. (I am unhappy with it.)
Use the --debug flag in rspec:
rspec --debug t/parse-board.rb.
After doing all that it worked for me, so now I'm happy.
Copyright and License
The text is copyrighted by Shlomi Fish, and is made available under
the Creative Commons Attribution License 3.0 Unported (or at
your option, any later version). In order to attribute the text to me (=
Shlomi Fish), please link
page and to my homepage.