How to run Rspec with debugger

Ruby On Rails logo
Well, this is may be very rarely. The time when you need to run your Rspec test with debugger inside the codes. It even doesn't look make sense when you think you will need to run Rspec with debugger. However, my experience showed that even it sounds non-sense, it happened. There is a time when I need to run my Rspec test with debugger inside my Rails codes. Okay, now tell me how to run Rspec with debugger.

If you put debugger on codes, then run Rspec as usual with rake spec then you must see the message that you need to enable debugger to make it work by adding --debug or -d parameters. I already done that. Running such:

rake spec -d #not work , raise an error : invalid parameter
rake spec --debug #not work, raise an error : invalid parameter

Then, how to enable debugger when running Rspec test? After doing a little research on the internet, some folks suggested me to add ruby-debug on the top of Rspec file. However, it seems not working when you're running Rails 3.0.x.

Knowing that fact, I continue my little research and I found this one is working :
rake spec SPEC_OPTS="--debug"

That's it. --debug parameters should be put inside SPEC_OPTS in order to enable debugger when you're running Rspec test. I hope this post can be useful when you're facing the same problem as mine.