Hi people, i''m wondering what''s the best way to test your rails application. Should you constantly write tests while your writing your application code? (method -> test method -> method -> etc.) Or should you focus on building your application and than building the tests? Thanks for your advice. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Petar, A good advise is to use small steps. Create a test, then write (as a rule of thumb) max. 10 lines of code, or a small function. Repeat until you are done ;) IsBOF On Jan 22, 3:21 pm, "Petar" <peros...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi people, > > i''m wondering what''s the best way to test your rails application. > Should you constantly write tests while your writing your application > code? (method -> test method -> method -> etc.) Or should you focus on > building your application and than building the tests? > > Thanks for your advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Petar, If you can start mastering the concepts of Test Driven Development, you would be doing yourself a huge favor. This is what I do: 1) Create a scaffold_resource for the functionality and model I want to build (I am really into RESTful development these days) 2) Write an integration test that contains its own Domain Specific Language (or DSL) so I can write my test cases in english. I basically write out a user story of what I want this part of the app to do. I''ll put an example after this list. 3) Run my integration test and watch it fail in a blaze of glory. 4) Write the code for my migration and model to provide the model-based functionality needed for the integration test. 5) Run the unit tests built by the scaffold, then work the code in the model until the unit tests pass. 6) Write the controller code required to make my integration tests pass. I usually do these one at a time (my integration tests have a number of small scenarios to test in them). Some of the tests will usually pass with the stuff the scaffold generates. That is considered a bonus! I work the rest one at a time, running the test in between each iteration, until everything works. Now if your integration test is a good representation of the user story for that functionality, when you get to this point, your code should be fairly complete. All you should have to do is get your views in order and you''re golden. Here is an example integration test that I have used: class ForumTest < ActionController::IntegrationTest fixtures :forums, :forum_posts, :users def test_forum quentin = enter_site(:quentin) quentin.views_forum_page forum = quentin.selects_forum quentin.views_posts forum quentin.tries_to_post forum quentin.logs_in("quentin", "test", forum) q_post = quentin.posts_to_forum forum aaron = enter_site(:aaron) aaron.logs_in("aaron", "test") posts = aaron.searches_forums a_post = aaron.selects_post_from_results q_post a_reply = aaron.replies_to_post(forum, a_post) quentin.views_posts forum reply = quentin.notes_new_reply q_post quentin.is_reply_aarons_post?(reply, a_reply) end private module ForumTestDSL include ERB::Util attr_writer :name def views_forum_page ... end def selects_forum ... end def views_posts(forum) ... end def tries_to_post(forum) ... end def logs_in(user_name, password, forum=nil) ... end def posts_to_forum(forum) ... end # you get the picture ... def is_reply_aarons_post?(reply, d_post) ... end end def enter_site(name) open_session do |session| session.extend(ForumTestDSL) session.name = name yield session if block_given? end end end There is a ton of info on TDD out there, so you should have no trouble getting really good advice on the subject. Hope this helps! C On Jan 24, 5:14 pm, "IsBOF" <rasmu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Petar, > > A good advise is to use small steps. Create a test, then write (as a > rule of thumb) max. 10 lines of code, or a small function. Repeat until > you are done ;) > > IsBOF > > On Jan 22, 3:21 pm, "Petar" <peros...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi people, > > > i''m wondering what''s the best way to test your rails application. > > Should you constantly write tests while your writing your application > > code? (method -> test method -> method -> etc.) Or should you focus on > > building your application and than building the tests? > > > Thanks for your advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
i do something like redmotive, but i don''t use scaffold (don''t ask me why, i don''t know :) ), i create all by my own, and another difference is that i create first the model and then tests and code, ok, it''s not real TDD with develop first the model, but i think that it''s quite safe, obviously i put in the model only what i need not, not things that MAYBE i''ll need in the future (YAGNI) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Nick, I started using scaffold_resource (as opposed to scaffold) when I started getting into REST. The scaffold_resource generator really does a nice job of creating actions and tests for a RESTful implementation. It also now adds the route to the routes.rb file, which it used to not do. It is very convenient if you want to develop a RESTful application. If you are not into REST, that''s cool. It just so happens that REST was the new direction of Rails when I started developing my new app, so I decided to give it a shot. I like it alot. Unfortunately, the results of that generator are not documented in the latest Agile book, so you kind of have to play around with it (make sure you are running Edge or Rails 1.2 to see it in all its glory). As far as what you are doing, you are basically doing the same thing as you said, but you appear to be leaving out the Integration Test. No problem there, of course, but I have found that writing an Intergration Test first, in the manner in which I do above (with a DSL), helps me to think about what my application needs to do from a user perspective. That''s fantastic if you can keep all of that in your head, but I have found it a lot easier on my short-term memory if I write this out first so that I have a target in mind before I really begin coding. Not that my way is any more right than anyone else''s, it just works for me. C On Jan 26, 8:17 am, nick <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> i do something like redmotive, but i don''t use scaffold (don''t ask me > why, i don''t know :) ), i create all by my own, and another difference > is that i create first the model and then tests and code, ok, it''s not > real TDD with develop first the model, but i think that it''s quite safe, > obviously i put in the model only what i need not, not things that MAYBE > i''ll need in the future (YAGNI) > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
redmotive wrote:> As far as what you are doing, you are basically doing the same thing as > you said, but you appear to be leaving out the Integration Test. No > problem there, of course, but I have found that writing an Intergration > Test first, in the manner in which I do above (with a DSL), helps me to > think about what my application needs to do from a user perspective. > That''s fantastic if you can keep all of that in your head, but I have > found it a lot easier on my short-term memory if I write this out first > so that I have a target in mind before I really begin coding. Not that > my way is any more right than anyone else''s, it just works for me.i''m using integration tests and DSL too :) and the possibility to create more than one single session is great...I''m using also some functional tests for controllers which do just things separately from other controllers -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I hear ya nick. Didn''t mean to impune the integrity of your testing, you just didn''t mention it ;) No offense intended. I have found that writing my integration tests first has helped me keep my head wrapped around the project, but that''s just because I need the extra focus. You may be doing the same thing, I was just commenting on what you wrote. Hope I didn''t offend you! C On Jan 26, 9:59 am, nick <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> redmotive wrote: > > As far as what you are doing, you are basically doing the same thing as > > you said, but you appear to be leaving out the Integration Test. No > > problem there, of course, but I have found that writing an Intergration > > Test first, in the manner in which I do above (with a DSL), helps me to > > think about what my application needs to do from a user perspective. > > That''s fantastic if you can keep all of that in your head, but I have > > found it a lot easier on my short-term memory if I write this out first > > so that I have a target in mind before I really begin coding. Not that > > my way is any more right than anyone else''s, it just works for me.i''m using integration tests and DSL too :) and the possibility to create > more than one single session is great...I''m using also some functional > tests for controllers which do just things separately from other > controllers > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
redmotive wrote:> I hear ya nick. Didn''t mean to impune the integrity of your testing, > you just didn''t mention it ;) No offense intended. I have found that > writing my integration tests first has helped me keep my head wrapped > around the project, but that''s just because I need the extra focus.yes :)> Hope I didn''t offend you!no :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---