Log in

No account? Create an account
Tech Tip: debugging Ruby’s rspec scripts - Shlomif's Technical Posts Community [entries|archive|friends|userinfo]
Shlomif's Technical Posts Community

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

[Links:| Shlomi Fish's Homepage Main Journal Homesite Blog Planet Linux-IL Amir Aharoni in Unicode open dot dot dot ]

Tech Tip: debugging Ruby’s rspec scripts [Aug. 18th, 2012|02:13 pm]
Shlomif's Technical Posts Community


[Tags|, , , , , , , ]
[Current Location |Home]
[Current Mood |productive]
[Current Music |B'Witched - Blame it on the Weatherman]

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

What you should do is:

  1. install the ruby-debug gem: gem install ruby-debug.

  2. Add require 'ruby-debug' to the top of the test script.

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

  4. 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 to this page and to my homepage.