Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to debug unit tests in Ruby on Rails?

So, I just moved to new project that is built on Ruby on Rails. I'm new to it and I'm still learning it. I can debug most of the application code, but it seems I can not debug unit test code and code that is tested.

When I run unit testing in debug mode, I can set a breakpoint in unit test class code, for example where fixtures are added, but breakpoints do not work inside test method code and do not work inside tested code, where they do work during normal workflow. Everyone else in team uses print statement for unit test debugging.

So, is that even possible to debug unit test code in rails?

We are using jruby 1.3.1, rails-2.3.1 and I use IntelliJ IDEA to debug, also I'm ok if I have to switch to eclipse or netbeans.

EDIT: actually, "no, it is not possible" would be a helpful answer as well, if you know it is so. At least I would stop wasting time on it

like image 965
Pavel Feldman Avatar asked Feb 26 '10 18:02

Pavel Feldman


People also ask

Can you debug a unit test?

Debug and analyze unit tests with Test ExplorerYou can use Test Explorer to start a debugging session for your tests. Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test.

Does Ruby have a debugger?

To help deal with bugs, the standard distribution of Ruby includes a debugger. In order to start the Ruby debugger, load the debug library using the command-line option -r debug. The debugger stops before the first line of executable code and asks for the input of user commands.


1 Answers

Yes, it is possible.

First of all you must install ruby-debug.

sudo gem install ruby-debug

then you write

debugger

immediately before the line you wish to start debugging.

Next step: run your unit tests as you would do normaly.

At the moment that ruby reaches the line that contain the debugger directive it will stop and show you a console prompt.

Now you can debug in the same way as you would do with gdb.

This link explains it in a very nice way: http://blog.nanorails.com/articles/2006/07/14/a-better-rails-debugger-ruby-debug

I hope this informtaion will be useful to you.

like image 85
Plicatibu Avatar answered Nov 15 '22 09:11

Plicatibu