Some have probably already discovered this but I''ve been working through some ui stories, using the rails integration test stuff. I had a story where one very used step was failing in one place. The failing expectation looked like this: response.should have_tag("tr.group_info_row td",group_title) I wanted to look at the response, but only for the case which was failing, so I changed this to: debugger unless have_tag("tr.group_info_row td",group_title).matches?(response) response.should have_tag("tr.group_info_row td",group_title) And rdebug broke right before the expectation would have thrown its exception, and I could see the problem, which was an earlier step which had checked that the request had redirected without following the redirect. I think that this pattern of using a matcher as a predicate might be useful in future debugging sessions. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/
On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote:> Some have probably already discovered this but I''ve been working > through some ui stories, using the rails integration test stuff. > > I had a story where one very used step was failing in one place. The > failing expectation looked like this: > > response.should have_tag("tr.group_info_row td",group_title) > > I wanted to look at the response, but only for the case which was > failing, so I changed this to: > > debugger unless have_tag("tr.group_info_row > td",group_title).matches?(response) > response.should have_tag("tr.group_info_row td",group_title) > > And rdebug broke right before the expectation would have thrown its > exception, and I could see the problem, which was an earlier step > which had checked that the request had redirected without following > the redirect.Yeah - I use this all the time. I have a textmate snippet called debug(tab) which inserts the following: require "rubygems"; require "ruby-debug"; debugger This allows me to use it in all sort of contexts - migrations, outside of rails projects, in failing test cases, etc. It should be noted that in other languages (like Smalltalk and lisp) the debugger pops up automatically when a test case fails. I don''t know why this technique has never picked up and become popular. Scott
On Fri, Apr 18, 2008 at 10:13 PM, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote: > > > Some have probably already discovered this but I''ve been working > > through some ui stories, using the rails integration test stuff. > > > > I had a story where one very used step was failing in one place. The > > failing expectation looked like this: > > > > response.should have_tag("tr.group_info_row td",group_title) > > > > I wanted to look at the response, but only for the case which was > > failing, so I changed this to: > > > > debugger unless have_tag("tr.group_info_row > > td",group_title).matches?(response) > > response.should have_tag("tr.group_info_row td",group_title) > > > > And rdebug broke right before the expectation would have thrown its > > exception, and I could see the problem, which was an earlier step > > which had checked that the request had redirected without following > > the redirect. > > Yeah - I use this all the time. I have a textmate snippet called > debug(tab) which inserts the following: > > require "rubygems"; require "ruby-debug"; debuggerWell I wasn''t really talking about just using the debugger, but using matcher.matches?(value) instead of value.should matcher as a way to trigger a conditional break. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/
On Fri, Apr 18, 2008 at 7:13 PM, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote: > > > Some have probably already discovered this but I''ve been working > > through some ui stories, using the rails integration test stuff. > > > > I had a story where one very used step was failing in one place. The > > failing expectation looked like this: > > > > response.should have_tag("tr.group_info_row td",group_title) > > > > I wanted to look at the response, but only for the case which was > > failing, so I changed this to: > > > > debugger unless have_tag("tr.group_info_row > > td",group_title).matches?(response) > > response.should have_tag("tr.group_info_row td",group_title) > > > > And rdebug broke right before the expectation would have thrown its > > exception, and I could see the problem, which was an earlier step > > which had checked that the request had redirected without following > > the redirect. > > Yeah - I use this all the time. I have a textmate snippet called > debug(tab) which inserts the following: > > require "rubygems"; require "ruby-debug"; debugger > > This allows me to use it in all sort of contexts - migrations, outside > of rails projects, in failing test cases, etc.+1 Its awesome. I also use intellij Idea, which has a console. The console does IO with the debugger. Whats cool is I can click or use a shortcut to jump to the file + line link that the debugger gives.> > It should be noted that in other languages (like Smalltalk and lisp) > the debugger pops up automatically when a test case fails. > > I don''t know why this technique has never picked up and become popular. > > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Apr 19, 2008, at 12:43 PM, Brian Takita wrote:> On Fri, Apr 18, 2008 at 7:13 PM, Scott Taylor > <mailing_lists at railsnewbie.com> wrote: >> >> On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote: >> >>> Some have probably already discovered this but I''ve been working >>> through some ui stories, using the rails integration test stuff. >>> >>> I had a story where one very used step was failing in one place. >>> The >>> failing expectation looked like this: >>> >>> response.should have_tag("tr.group_info_row td",group_title) >>> >>> I wanted to look at the response, but only for the case which was >>> failing, so I changed this to: >>> >>> debugger unless have_tag("tr.group_info_row >>> td",group_title).matches?(response) >>> response.should have_tag("tr.group_info_row td",group_title) >>> >>> And rdebug broke right before the expectation would have thrown its >>> exception, and I could see the problem, which was an earlier step >>> which had checked that the request had redirected without following >>> the redirect. >> >> Yeah - I use this all the time. I have a textmate snippet called >> debug(tab) which inserts the following: >> >> require "rubygems"; require "ruby-debug"; debugger >> >> This allows me to use it in all sort of contexts - migrations, >> outside >> of rails projects, in failing test cases, etc. > +1 Its awesome. > > I also use intellij Idea, which has a console. The console does IO > with the debugger. > Whats cool is I can click or use a shortcut to jump to the file + line > link that the debugger gives.Yeah - I often use ruby-debug''s mate command, which will open up the file in textmate on the line and file you''re currently on (it''s incredibly convenient).> >> >> It should be noted that in other languages (like Smalltalk and lisp) >> the debugger pops up automatically when a test case fails. >> >> I don''t know why this technique has never picked up and become >> popular. >> >> Scott >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users