# Debugging in ruby

**URL:** <https://www.ruby-forum.com/t/debugging-in-ruby/165987>\
**Category:** Ruby\
**Created:** [April 20, 2009, 5:43pm UTC](https://www.ruby-forum.com/t/debugging-in-ruby/165987 "2009-04-20T17:43:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 20, 2009, 5:43pm UTC](https://www.ruby-forum.com/t/debugging-in-ruby/165987/1 "2009-04-20T17:43:47Z")

</div>

Hi,  
when I run unittest class, with debugger the flow goes into testcase  
case class as below.  
how can i debug only the testscript instead of going into libraries of  
extended clases

Testscript  
require “test/unit”

class TestSimpleNumber \< Test::Unit::TestCase

def test\_simple  
assert\_equal(“abc”, “abc” )

end

def test\_typecheck  
assert\_equal(“abc”, “abc” )  
end

def test\_failure  
assert\_equal(“abc”, “abc” )  
end

End

Execution:

C:\ruby\>ruby -rubygems -rdebug unittest.rb  
Debug.rb  
Emacs support available.

unittest.rb:1:require “test/unit”  
(rdb:1) b 6  
Set breakpoint 1 at unittest.rb:6  
(rdb:1) cont  
Loaded suite unittest  
Started  
.Breakpoint 1, test\_simple at unittest.rb:6  
unittest.rb:6: assert\_equal(“abc”, “abc” )  
(rdb:1) n  
c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:85: begin  
(rdb:1) n  
c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:86: teardown  
(rdb:1) n  
c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:94: result.add\_run  
(rdb:1) n  
c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:95: yield(FINISHED,  
name)  
(rdb:1) n  
c:/ruby/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:47:  
notify\_listeners(channel, value)  
(rdb:1)

Please help me in this regard.

Thanks,  
Anil

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 20, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/debugging-in-ruby/165987/2 "2009-04-20T18:00:49Z")

</div>

> Please help me in this regard.

Briefly, if you write unit tests, you should not need to debug.

I configure the tests to run after I hit one button. (Report your  
editor, and  
someone might know how to do it. Some, like TextMate, make it hard.)

Then I run them over and over again. Change a statement, predict what  
the tests  
will do, run the tests, see if your prediction matches. Sometimes, of  
course,  
use pp @variable to trace what’s going on.

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 20, 2009, 6:26pm UTC](https://www.ruby-forum.com/t/debugging-in-ruby/165987/3 "2009-04-20T18:26:37Z")

</div>

Phlip wrote:

> Briefly, if you write unit tests, you should not need to debug.

Oh yes you should. A test never debug; it just point out there are  
bugs. To  
remove them is still your job.

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 20, 2009, 6:35pm UTC](https://www.ruby-forum.com/t/debugging-in-ruby/165987/4 "2009-04-20T18:35:59Z")

</div>

Urabe S. wrote:

> Phlip wrote:
> 
> > Briefly, if you write unit tests, you should not need to debug.
> 
> Oh yes you should. A test never debug; it just point out there are bugs. To  
> remove them is still your job.

If you use Test-Driven Development, you have the option to use Undo  
until the  
bug goes away. Try it; you will see what I mean.

On a big project, you might still sometimes need to debug. I have always  
used pp  
for trace statements, out of selected tests. Running them over and over  
again  
works so similar to debugging that you won’t miss it.

However, someone here will have experience with the Ruby debugger and  
can answer  
your actual question. Any port in a storm!

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 22, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/debugging-in-ruby/165987/5 "2009-04-22T22:07:51Z")

</div>

On Monday 20 April 2009 11:25:16 Urabe S. wrote:

> Phlip wrote:
> 
> > Briefly, if you write unit tests, you should not need to debug.
> 
> Oh yes you should. A test never debug; it just point out there are bugs.  
> To remove them is still your job.

Firstly, a test absolutely does help, even after the fact, as a way to  
debug.  
It provides a concise definition of the bug, and if the test is kept  
around, it  
will show whether the bug remains fixed.

But I think the point was that if your specs are comprehensive enough to  
begin  
with, you will not introduce nearly as many bugs. I’m not arrogant  
enough to  
say “none at all”, but I’ve also never worked on a project which did  
Behavior-  
Driven Design religiously enough for this to work.
