I''m sorry if this sounds like a totally newbie question, but... Are there good tips and resources for debugging unit tests? Currently, I just fire up script/console using the "test" environment and just poke around randomly until I hit upon some inspiration. But I think there should be a better way, for example, it would be nice to single step through a particular test case using a debugger in one window and watching the test log in the other window. Any tips? Thanks. --wpd
Patrick Doyle wrote:> I''m sorry if this sounds like a totally newbie question, but... > > Are there good tips and resources for debugging unit tests? > Currently, I just fire up script/console using the "test" environment > and just poke around randomly until I hit upon some inspiration. But > I think there should be a better way, for example, it would be nice to > single step through a particular test case using a debugger in one > window and watching the test log in the other window. > > Any tips?Just call the debugger from within your app code, or from the test itself. When the "debug" statement is executed, you''ll be in an interactive debugger. Simple.> > Thanks. > > --wpdBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
On Wed, Oct 7, 2009 at 11:33 AM, Marnen Laibow-Koser <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Patrick Doyle wrote: >> Are there good tips and resources for debugging unit tests? > > Just call the debugger from within your app code, or from the test > itself. When the "debug" statement is executed, you''ll be in an > interactive debugger. Simple. >I''m missing something because it is not simple... class LotTest < ActiveSupport::TestCase ... test "add lot to assembly" do debug ... end end When I try running this as: $ ruby -I test test/unit/lot_test.rb -n test_add_lot_to_assembly the test fails with: NameError: undefined local variable or method `debug'' for ... When I try running this as: $ rdebug -I test test/unit/lot_test.rb -n test_add_lot_to_assembly (rdb:1) c The test runs to completion and doesn''t stop at my #debug statement. I won''t even go into my trials and tribulations trying to get this to run under emacs... I agree though, this should really be simple. Having said that, I must be missing something terribly obvious. --wpd
On Wed, Oct 7, 2009 at 10:33 AM, Marnen Laibow-Koser <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Just call the debugger from within your app code, or from the test > itself. When the "debug" statement is executed, you''ll be in an > interactive debugger. Simple."debug" is for use with views, and does not stop execution. <%= debug @foo %> "debugger" is for actually invoking the debugger and stopping execution. -- Greg Donald http://destiney.com/
2009/10/7 Patrick Doyle <wpdster-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > I''m sorry if this sounds like a totally newbie question, but... > > Are there good tips and resources for debugging unit tests? > Currently, I just fire up script/console using the "test" environment > and just poke around randomly until I hit upon some inspiration. But > I think there should be a better way, for example, it would be nice to > single step through a particular test case using a debugger in one > window and watching the test log in the other window.Have a look at the rails guide on debugging. Particularly the section on ruby-debug. Colin
On Wed, Oct 7, 2009 at 12:45 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/10/7 Patrick Doyle <wpdster-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> Are there good tips and resources for debugging unit tests? > > Have a look at the rails guide on debugging. Particularly the section > on ruby-debug. >Thanks. That''s what I was looking for. Now, if I could just get it to interact sanely with Emacs, I''d be a happy camper :-) --wpd