Hi, So-- I am very very new to BDD.. and I am trying to go over and write some tests for existing code that has been problematic... I am struggling with knowing exactly how to write the proper specs. So I wrote out a list of things this controller action should do, but as far as how to really hook in and test the individual components, I am a bit hazy, so I am hoping some people here can chime in and school me. http://gist.github.com/307464 To give some background on what is going on in this code-- I have a form that lists contacts which is used in two different contexts-- One for newsletter mailings lists, and the other for shipping labels (pdf list). So I have a controller action called ''result_list'' that is part of my contacts_controller (in my routes, it''s a :collection => :put). This action looks if there is a newsletter_id param, and if so, it knows to look up a newsletter, otherwise it looks up a pdf list. If this newsletter/pdf list is not currently being modified / sent / etc, then a rake task is launched which adds or removes additional contacts to the list. After that is complete, if javascript is disabled, it redirects back to the contacts path, and if it''s an ajax request (which it most likely will be, it renders nothing-- there is unobtrusive js that handles updating the page). ... So, if someone could please point me in the right direction as far as what my test code SHOULD look like, I''d greatly appreciate it. I have no idea how to test if a rake task fails or not.. I have no idea how to hook into the controller code and determine whether the result_lis variable is a PdfList class or a Newsletter class... And I have no idea how to test whether a http request redirects to contacts_path, or if an ajax request renders nothing! I feel like, I know what I want to test, but I just have no idea how to test it... Thank you for any guidance. -patrick
patrick99e99 wrote:> Hi, > > So-- I am very very new to BDD.. and I am trying to go over and write > >The best place to start is the RSpec Book. http://www.pragprog.com/titles/achbd/the-rspec-book Peace, Phillip
Yeah, I have the book.. have read it.. also have watched peepcode''s three screencasts on rspec, also have watched the first 7 episodes of BDDCasts. I just am still fuzzy on lots of things, and am hoping someone will be kind enough to go through my spec file and show me what kind of code they would write to get it to accomplish what it needs to. -patrick On Feb 18, 4:34?am, Phillip Koebbe <phillipkoe... at gmail.com> wrote:> patrick99e99 wrote: > > Hi, > > > So-- I am very very new to BDD.. and I am trying to go over and write > > The best place to start is the RSpec Book. > > http://www.pragprog.com/titles/achbd/the-rspec-book > > Peace, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
I to am starting to learn Rspec so i had an attempt at your problem and i came up with this solution http://github.com/ssmithstone/learning_rspec I will expand on this code if you want the render nothing if called with ajax was a puzzler for me as not come across that before as learning rails as well On 18/02/2010 08:25, patrick99e99 wrote: Hi, So-- I am very very new to BDD.. and I am trying to go over and write some tests for existing code that has been problematic... I am struggling with knowing exactly how to write the proper specs. So I wrote out a list of things this controller action should do, but as far as how to really hook in and test the individual components, I am a bit hazy, so I am hoping some people here can chime in and school me. http://gist.github.com/307464 To give some background on what is going on in this code-- I have a form that lists contacts which is used in two different contexts-- One for newsletter mailings lists, and the other for shipping labels (pdf list). So I have a controller action called ''result_list'' that is part of my contacts_controller (in my routes, it''s a :collection => :put). This action looks if there is a newsletter_id param, and if so, it knows to look up a newsletter, otherwise it looks up a pdf list. If this newsletter/pdf list is not currently being modified / sent / etc, then a rake task is launched which adds or removes additional contacts to the list. After that is complete, if javascript is disabled, it redirects back to the contacts path, and if it''s an ajax request (which it most likely will be, it renders nothing-- there is unobtrusive js that handles updating the page). ... So, if someone could please point me in the right direction as far as what my test code SHOULD look like, I''d greatly appreciate it. I have no idea how to test if a rake task fails or not.. I have no idea how to hook into the controller code and determine whether the result_lis variable is a PdfList class or a Newsletter class... And I have no idea how to test whether a http request redirects to contacts_path, or if an ajax request renders nothing! I feel like, I know what I want to test, but I just have no idea how to test it... Thank you for any guidance. -patrick _______________________________________________ rspec-users mailing list rspec-users-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rspec-users
just a note not the greatest of code but just an attempt On 18/02/2010 21:17, Stephen Smithstone wrote: I to am starting to learn Rspec so i had an attempt at your problem and i came up with this solution http://github.com/ssmithstone/learning_rspec I will expand on this code if you want the render nothing if called with ajax was a puzzler for me as not come across that before as learning rails as well On 18/02/2010 08:25, patrick99e99 wrote: Hi, So-- I am very very new to BDD.. and I am trying to go over and write some tests for existing code that has been problematic... I am struggling with knowing exactly how to write the proper specs. So I wrote out a list of things this controller action should do, but as far as how to really hook in and test the individual components, I am a bit hazy, so I am hoping some people here can chime in and school me. http://gist.github.com/307464 To give some background on what is going on in this code-- I have a form that lists contacts which is used in two different contexts-- One for newsletter mailings lists, and the other for shipping labels (pdf list). So I have a controller action called ''result_list'' that is part of my contacts_controller (in my routes, it''s a :collection => :put). This action looks if there is a newsletter_id param, and if so, it knows to look up a newsletter, otherwise it looks up a pdf list. If this newsletter/pdf list is not currently being modified / sent / etc, then a rake task is launched which adds or removes additional contacts to the list. After that is complete, if javascript is disabled, it redirects back to the contacts path, and if it''s an ajax request (which it most likely will be, it renders nothing-- there is unobtrusive js that handles updating the page). ... So, if someone could please point me in the right direction as far as what my test code SHOULD look like, I''d greatly appreciate it. I have no idea how to test if a rake task fails or not.. I have no idea how to hook into the controller code and determine whether the result_lis variable is a PdfList class or a Newsletter class... And I have no idea how to test whether a http request redirects to contacts_path, or if an ajax request renders nothing! I feel like, I know what I want to test, but I just have no idea how to test it... Thank you for any guidance. -patrick _______________________________________________ rspec-users mailing list rspec-users-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________ rspec-users mailing list rspec-users-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rspec-users