From: ext-golla.anil-kumar@... Date: 2009-04-19T18:43:19+09:00 Subject: Re: REG: How can we debug a ruby script in unit test classes Hi, Using the below method mention the below mail, I was successfully able to run and debug the script. But when I run unittest class, the flow goes into testcase case class as below. 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 kumar. >-----Original Message----- >From: b.candler@pobox.com [mailto:b.candler@pobox.com] >Sent: 31 March, 2009 12:14 >To: ruby-talk ML >Subject: Re: REG: How can we debug a ruby script > >Something in your environment is making ruby do -rubygems (require >'rubygems') >Perhaps the RUBYOPT environment variable is set, because I can >replicate your problem like this: > >$ export RUBYOPT=-rubygems >$ ruby -rdebug fact.rb >Debug.rb >Emacs support available. > >/usr/local/lib/site_ruby/1.8/ubygems.rb:10:require 'rubygems' >(rdb:1) > >So if this is the case, solution 1 is simply to unset the >RUBYOPT variable. > >Solution 2 is to set a breakpoint at the start of your program. > >$ ruby -rdebug fact.rb >Debug.rb >Emacs support available. > >/usr/local/lib/site_ruby/1.8/ubygems.rb:10:require 'rubygems' >(rdb:1) b fact.rb:1 >Set breakpoint 1 at fact.rb:1 >(rdb:1) cont >Breakpoint 1, toplevel at fact.rb:1 >fact.rb:1:def fact(n) >(rdb:1) n >fact.rb:9:print fact(2), "\n" >(rdb:1) n >2 >$ > >Solution 3 is to require rubygems *before* requiring debug, >because when it has been required once, it won't be required again: > >$ ruby -rubygems -rdebug fact.rb >Debug.rb >Emacs support available. > >fact.rb:1:def fact(n) >(rdb:1) > >This third one probably involves the least work. >-- >Posted via http://www.ruby-forum.com/. > >