[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

debugging in ruby

Anil Gollaa

4/20/2009 3:44:00 PM

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
--
Posted via http://www.ruby-....

4 Answers

Phlip

4/20/2009 3:58:00 PM

0

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

--
Phlip

Urabe Shyouhei

4/20/2009 4:25:00 PM

0

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.

Phlip

4/20/2009 4:30:00 PM

0

Urabe Shyouhei 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!

David Masover

4/22/2009 8:07:00 PM

0

On Monday 20 April 2009 11:25:16 Urabe Shyouhei 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.