Developing a Ruby/Rails application TDD style, and then in the middle of your spec something odd happens: Wouldn't it be nice to fire up the debugger exactly in that spot? Here is how I am doing this right now, while using Rails, rspec and guard. Well, and pry, which in itself is worth checking out.
Let's say I have the following spec:
The test fails as follows, but why? I've just added the appropriate uniqueness constraint in the User model, so what's going wrong?
Something odd might be happening, so I call pry to the rescue by adding two lines into the test:
Guard re-runs the test and stops with a REPL. A quick debug session (reproduced below) reveals what the issue is:
Aha, the first user didn't even get created! I better provide values for email and password. A quick change to the spec makes guard run it again, this time it succeeds:
Note: I didn't use anything to facilitate sample data for this test. In order to stay sane using factory_girl or fixtures is the way to go. Ryan Bates has created an excellent 15 minute intro on how he does all that.