Forum: Ruby debugging in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F05e172ec1523b228e8abc6e36ff39bc?d=identicon&s=25 Anil Gollaa (ganil_22)
on 2009-04-20 17:43
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
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-20 18:00
(Received via mailing list)
> 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.
9d2f78236e45a335301ba1195026105d?d=identicon&s=25 Urabe Shyouhei (Guest)
on 2009-04-20 18:26
(Received via mailing list)
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.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-20 18:35
(Received via mailing list)
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!
1bc63d01bd3fcccc36fb030a62039352?d=identicon&s=25 David Masover (Guest)
on 2009-04-22 22:07
(Received via mailing list)
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.
This topic is locked and can not be replied to.