# \[rails\] attaching the debugger to functional test

**URL:** <https://rubytalk.org/t/rails-attaching-the-debugger-to-functional-test/22024>\
**Category:** ruby-talk\
**Created:** [30 October 2005 19:24 UTC](https://rubytalk.org/t/rails-attaching-the-debugger-to-functional-test/22024 "2005-10-30T19:24:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Bikle1](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@Dan\_Bikle1](https://rubytalk.org/u/Dan_Bikle1)\
**Post date:** [30 October 2005 19:24 UTC](https://rubytalk.org/t/rails-attaching-the-debugger-to-functional-test/22024/1 "2005-10-30T19:24:10Z")

</div>

People,

I'm trying to run the ruby debugger against a Test::Unit::TestCase class  
which is a parent of a Rails class.

I started my study with a simple script:

> **···**
>
> #  
> # bikle\_test.rb  
> #  
> require 'test/unit'
> 
> class BikleTest \< Test::Unit::TestCase  
> &nbsp;&nbsp;def setup  
> &nbsp;&nbsp;&nbsp;&nbsp;@string10 = "hello"  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def test10  
> &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal @string10, "hello"  
> &nbsp;&nbsp;end  
> end
> 
> The following command line works great:
> 
> ruby -r debug bikle\_test.rb
> 
> Next, I create a new rails application with this command line:
> 
> rails rtest
> 
> Then, I create a database.yml:
> 
> test:  
> &nbsp;&nbsp;adapter: sqlite3  
> &nbsp;&nbsp;dbfile: db/rtest.db
> 
> Then I copied bikle\_test.rb to...
> 
> rtest/test/functional/
> 
> I altered it a bit so it behaves like a typical Rails test:
> 
> #  
> # bikle\_test.rb  
> #  
> require File.dirname(\_\_FILE\_\_) + '/../test\_helper'
> 
> class BikleTest \< Test::Unit::TestCase  
> &nbsp;&nbsp;def setup  
> &nbsp;&nbsp;&nbsp;&nbsp;@string10 = "hello"  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def test10  
> &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal @string10, "hello"  
> &nbsp;&nbsp;end  
> end
> 
> When I run it, I see this:
> 
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$ ls  
> ./ ../ bikle\_test.rb  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$ ruby b\*  
> Loaded suite bikle\_test  
> Started  
> .  
> Finished in 0.131351 seconds.
> 
> 1 tests, 1 assertions, 0 failures, 0 errors  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$
> 
> When I try to run it in the debugger I see this:
> 
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$ ruby -r debug b\*  
> Debug.rb  
> Emacs support available.
> 
> bikle\_test.rb:1:  
> (rdb:1) l  
> [-4, 5] in bikle\_test.rb  
> =\> 1 require File.dirname(\_\_FILE\_\_) + '/../test\_helper'  
> &nbsp;&nbsp;&nbsp;2  
> &nbsp;&nbsp;&nbsp;3 class BikleTest \< Test::Unit::TestCase  
> &nbsp;&nbsp;&nbsp;4 def setup  
> &nbsp;&nbsp;&nbsp;5 @string10 = "hello"  
> &nbsp;&nbsp;&nbsp;6 end  
> &nbsp;&nbsp;&nbsp;7 def test10  
> &nbsp;&nbsp;&nbsp;8 assert\_equal @string10, "hello"  
> &nbsp;&nbsp;&nbsp;9 end  
> &nbsp;&nbsp;&nbsp;10 end  
> &nbsp;&nbsp;&nbsp;11  
> &nbsp;&nbsp;&nbsp;12  
> (rdb:1) b 5  
> Set breakpoint 1 at bikle\_test.rb:5  
> (rdb:1) c  
> /opt/local/lib/ruby/1.8/drb/drb.rb:1572: `DRb::DRbServerNotFound'  
> (DRb::DRbServerNotFound)  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems/custom\_require.rb:21:in  
> `require'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.2.1/lib/active\_support/dependencies.rb:213:in  
> `require'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:182:in `activate'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:181:in `each'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:181:in `activate'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:167:in `activate'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:166:in `each'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:166:in `activate'  
> &nbsp;&nbsp;from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems/custom\_require.rb:26:in  
> `require'  
> &nbsp;&nbsp;from /Users/oracle/CD/railsdemos/rtest/config/boot.rb:14  
> &nbsp;&nbsp;from /Users/oracle/CD/railsdemos/rtest/config/environment.rb:8:in `require'  
> &nbsp;&nbsp;from /Users/oracle/CD/railsdemos/rtest/config/environment.rb:8  
> &nbsp;&nbsp;from ./../test\_helper.rb:2:in `require'  
> &nbsp;&nbsp;from ./../test\_helper.rb:2  
> &nbsp;&nbsp;from bikle\_test.rb:1:in `require'  
> &nbsp;&nbsp;from bikle\_test.rb:1  
> /opt/local/lib/ruby/1.8/drb/drb.rb:1572:  
> (rdb:1) q  
> Really quit? (y/n) y  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> zmac11:/cd/railsdemos/rtest/test/functional oracle$
> 
> So, it's telling me that it is looking for a DRb Server.
> 
> Question 1:  
> Why does it need to talk with a DRb Server?
> 
> Outside of Rails... it does not need to talk with a DRb Server.
> 
> Question 2:  
> How do I start a DRb Server which would make the debugger happy?
> 
> I looked in the DT-PickAxe book and found this:
> 
> # Sample code from Programing Ruby, page 399  
> require 'drb'
> 
> class TestServer  
> &nbsp;&nbsp;def add(\*args)  
> &nbsp;&nbsp;&nbsp;&nbsp;args.inject {|n,v| n + v}  
> &nbsp;&nbsp;end  
> end
> 
> server = TestServer.new  
> DRb.start\_service('druby://localhost:9000', server)  
> DRb.thread.join # Don't exit just yet!
> 
> So, it looks like I give the server a port to listen on  
> which would be easy enough.
> 
> But, how do I then tell the debugger what that port is?
> 
> Can any of you offer any insight, solutions, or ideas to experiment with?
> 
> Thanks,
> 
> -Dan

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [30 October 2005 20:28 UTC](https://rubytalk.org/t/rails-attaching-the-debugger-to-functional-test/22024/2 "2005-10-30T20:28:28Z")

</div>

For Rails questions you'll get the best and fastest answers from the Rails mailing list:

[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

> **···**
>
> On Oct 30, 2005, at 11:24 AM, Dan Bikle wrote:
> 
> > People,
> > 
> > I'm trying to run the ruby debugger against a Test::Unit::TestCase class  
> > which is a parent of a Rails class.
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Dan\_Bikle](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@Dan\_Bikle](https://rubytalk.org/u/Dan_Bikle)\
**Post date:** [14 November 2005 06:11 UTC](https://rubytalk.org/t/rails-attaching-the-debugger-to-functional-test/22024/3 "2005-11-14T06:11:17Z")

</div>

People,

I got a good tip from the yahoo ba-rb group on this subject.

The tip is to…  
‘Ignore the error and just press c to continue’

the tip worked for me.

-Dan

> **···**
>
> On 10/30/05, Dan Bikle [dan.bikle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org](mailto:dan.bikle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote:
> 
> > People,
> > 
> > I’m trying to run the ruby debugger against a Test::Unit::TestCase class  
> > which is a parent of a Rails class.
> > 
> > I started my study with a simple script:
> > 
> > # 
> > 
> > # bikle\_test.rb
> > 
> > # 
> > 
> > require ‘test/unit’
> > 
> > class BikleTest \< Test::Unit::TestCase  
> > def setup  
> > @string10 = “hello”  
> > end  
> > def test10  
> > assert\_equal @string10, “hello”  
> > end  
> > end
> > 
> > The following command line works great:
> > 
> > ruby -r debug bikle\_test.rb
> > 
> > Next, I create a new rails application with this command line:
> > 
> > rails rtest
> > 
> > Then, I create a database.yml:
> > 
> > test:  
> > adapter: sqlite3  
> > dbfile: db/rtest.db
> > 
> > Then I copied bikle\_test.rb to…
> > 
> > rtest/test/functional/
> > 
> > I altered it a bit so it behaves like a typical Rails test:
> > 
> > # 
> > 
> > # bikle\_test.rb
> > 
> > # 
> > 
> > require File.dirname( **FILE** ) + ‘/…/test\_helper’
> > 
> > class BikleTest \< Test::Unit::TestCase  
> > def setup  
> > @string10 = “hello”  
> > end  
> > def test10  
> > assert\_equal @string10, “hello”  
> > end  
> > end
> > 
> > When I run it, I see this:
> > 
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$ ls  
> > ./ …/ bikle\_test.rb  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$ ruby b\*  
> > Loaded suite bikle\_test  
> > Started  
> > .  
> > Finished in 0.131351 seconds.
> > 
> > 1 tests, 1 assertions, 0 failures, 0 errors  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$
> > 
> > When I try to run it in the debugger I see this:
> > 
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$ ruby -r debug b\*  
> > Debug.rb  
> > Emacs support available.
> > 
> > bikle\_test.rb:1:  
> > (rdb:1) l  
> > [-4, 5] in bikle\_test.rb  
> > =\> 1 require File.dirname( **FILE** ) + ‘/…/test\_helper’  
> > 2  
> > 3 class BikleTest \< Test::Unit::TestCase  
> > 4 def setup  
> > 5 @string10 = “hello”  
> > 6 end  
> > 7 def test10  
> > 8 assert\_equal @string10, “hello”  
> > 9 end  
> > 10 end  
> > 11  
> > 12  
> > (rdb:1) b 5  
> > Set breakpoint 1 at bikle\_test.rb:5  
> > (rdb:1) c  
> > /opt/local/lib/ruby/1.8/drb/drb.rb:1572: `DRb::DRbServerNotFound' (DRb::DRbServerNotFound) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:21:in `require’  
> > from /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.2.1/lib/active\_support/dependencies.rb:213:in  
> > `require' from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems.rb:182:in `activate’  
> > from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:181:in `each' from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems.rb:181:in `activate’  
> > from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:167:in `activate' from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems.rb:166:in `each’  
> > from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems.rb:166:in `activate' from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:26:in `require’  
> > from /Users/oracle/CD/railsdemos/rtest/config/boot.rb:14  
> > from /Users/oracle/CD/railsdemos/rtest/config/environment.rb:8:in `require' from /Users/oracle/CD/railsdemos/rtest/config/environment.rb:8 from ./../test_helper.rb:2:in `require’  
> > from ./…/test\_helper.rb:2  
> > from bikle\_test.rb:1:in `require’  
> > from bikle\_test.rb:1  
> > /opt/local/lib/ruby/1.8/drb/drb.rb:1572:  
> > (rdb:1) q  
> > Really quit? (y/n) y  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$  
> > zmac11:/cd/railsdemos/rtest/test/functional oracle$
> > 
> > So, it’s telling me that it is looking for a DRb Server.
> > 
> > Question 1:  
> > Why does it need to talk with a DRb Server?
> > 
> > Outside of Rails… it does not need to talk with a DRb Server.
> > 
> > Question 2:  
> > How do I start a DRb Server which would make the debugger happy?
> > 
> > I looked in the DT-PickAxe book and found this:
> > 
> > # Sample code from Programing Ruby, page 399
> > 
> > require ‘drb’
> > 
> > class TestServer  
> > def add(\*args)  
> > args.inject {|n,v| n + v}  
> > end  
> > end
> > 
> > server = TestServer.new  
> > DRb.start\_service(‘druby://localhost:9000’, server)  
> > DRb.thread.join # Don’t exit just yet!
> > 
> > So, it looks like I give the server a port to listen on  
> > which would be easy enough.
> > 
> > But, how do I then tell the debugger what that port is?
> > 
> > Can any of you offer any insight, solutions, or ideas to experiment with?
> > 
> > Thanks,
> > 
> > -Dan
