Hi All, I''ve got a single unit test working on a two-variable Portfolio model. The model has transformations, pattern-matching etc. to clean up user sloppiness and ensure data quality. To make sure the transformations/tests remain valid as the model undergoes future changes, I''ve got about a dozen tests codified in 3- element hashes: user-input, transformed-value-expected, error- messages (if any, expected to be produced by the validations) What''s a better way to handling these triplets? 1. write a Ruby script to generate test_1, test_2, etc. 2. iterate through list, generate the test_x''s and add those methods to the PortfoloTest class with metaprogramming. (I know I could do it manually, but I don''t like to write repetitive code.) I''ve got the simple working model and test code posted at http://www.pastie.org/231118. The test code included the hashes described above included as data in the unit-test file. Thanks in advance for any suggestions you may offer. Richard --~--~---------~--~----~------------~-------~--~----~ 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 just started reading http://manuals.rubyonrails.com/read/chapter/26 and earlier chapters. I see that fixtures are processed by eRB so that could be part of the story. Maybe its OK to generate the test fragments and stuff them all into a single test, perhaps test_UserInput. This looks promising to me. Regards, Richard On Jul 9, 7:49 pm, RichardOnRails <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:> Hi All, > > I''ve got a single unit test working on a two-variable Portfolio > model. The model has transformations, pattern-matching etc. to clean > up user sloppiness and ensure data quality. > > To make sure the transformations/tests remain valid as the model > undergoes future changes, I''ve got about a dozen tests codified in 3- > element hashes: user-input, transformed-value-expected, error- > messages (if any, expected to be produced by the validations) > > What''s a better way to handling these triplets? > 1. write a Ruby script to generate test_1, test_2, etc. > 2. iterate through list, generate the test_x''s and add those methods > to the PortfoloTest class with metaprogramming. > > (I know I could do it manually, but I don''t like to write repetitive > code.) > > I''ve got the simple working model and test code posted athttp://www.pastie.org/231118. The test code included the hashes > described above included as data in the unit-test file. > > Thanks in advance for any suggestions you may offer. > Richard--~--~---------~--~----~------------~-------~--~----~ 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 wrote up a long beginner''s guide to unit testing here: http://www.nullislove.com/2007/11/10/testing-in-rails-introduction/ You sound more advanced than beginner, but if you skim it, it might help answer some questions. Best, Kevin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Kevin. I''ll check it out. Regards. Richard On Jul 10, 10:02 am, Kevin Skoglund <ke...-WGmuFPN42W8gMxX8nMqP6gC/G2K4zDHf@public.gmane.org> wrote:> I wrote up a long beginner''s guide to unit testing here: > > http://www.nullislove.com/2007/11/10/testing-in-rails-introduction/ > > You sound more advanced than beginner, but if you skim it, it might > help answer some questions. > > Best, > Kevin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Kevin, You could have been nice and pointed me directly to "Part 6: Fixtures", instead of making me read all the preceding sections :-) Actually, the preceding sections presented several insights that I value. But learning that fixtures were preprocessed by eRB was the key to my problem. At least I think so. I''ll try to confirm that tomorrow. Again, thank you very much for responding to my request for guidance. Best wishes, Richard On Jul 10, 10:02 am, Kevin Skoglund <ke...-WGmuFPN42W8gMxX8nMqP6gC/G2K4zDHf@public.gmane.org> wrote:> I wrote up a long beginner''s guide to unit testing here: > > http://www.nullislove.com/2007/11/10/testing-in-rails-introduction/ > > You sound more advanced than beginner, but if you skim it, it might > help answer some questions. > > Best, > Kevin--~--~---------~--~----~------------~-------~--~----~ 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''ve been very happy writing unit tests with shoulda and factory_girl. Shoulda makes tests (and output) easier to read, and it comes with some handy ones built in. Factory_girl helps you do away with fixtures entirely! Have a look: http://thoughtbot.com/projects/shoulda http://thoughtbot.com/projects/factory_girl On Jul 12, 10:13 pm, RichardOnRails <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:> Hey Kevin, > > You could have been nice and pointed me directly to "Part 6: > Fixtures", instead of making me read all the preceding sections :-) > > Actually, the preceding sections presented several insights that I > value. But learning that fixtures were preprocessed by eRB was the > key to my problem. At least I think so. I''ll try to confirm that > tomorrow. > > Again, thank you very much for responding to my request for guidance. > > Best wishes, > Richard > > On Jul 10, 10:02 am, Kevin Skoglund <ke...-WGmuFPN42W8gMxX8nMqP6gC/G2K4zDHf@public.gmane.org> wrote: > > > I wrote up a long beginner''s guide to unit testing here: > > >http://www.nullislove.com/2007/11/10/testing-in-rails-introduction/ > > > You sound more advanced than beginner, but if you skim it, it might > > help answer some questions. > > > Best, > > Kevin--~--~---------~--~----~------------~-------~--~----~ 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 G.S., Thanks for the links. I didn''t see them until today. The initial page of each looks great. I won''t dig into them further until I get my current unit test + fixtures working. I''m going to post my latest problem with them shortly. Best wishes, Richard On Jul 13, 1:08 am, gsterndale <gsternd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve been very happy writing unit tests with shoulda and factory_girl. > Shoulda makes tests (and output) easier to read, and it comes with > some handy ones built in. Factory_girl helps you do away with fixtures > entirely! > > Have a look:http://thoughtbot.com/projects/shouldahttp://thoughtbot.com/projects/factory_girl > > On Jul 12, 10:13 pm, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > > Hey Kevin, > > > You could have been nice and pointed me directly to "Part 6: > > Fixtures", instead of making me read all the preceding sections :-) > > > Actually, the preceding sections presented several insights that I > > value. But learning that fixtures were preprocessed by eRB was the > > key to my problem. At least I think so. I''ll try to confirm that > > tomorrow. > > > Again, thank you very much for responding to my request for guidance. > > > Best wishes, > > Richard > > > On Jul 10, 10:02 am, Kevin Skoglund <ke...-WGmuFPN42W8gMxX8nMqP6gC/G2K4zDHf@public.gmane.org> wrote: > > > > I wrote up a long beginner''s guide to unit testing here: > > > >http://www.nullislove.com/2007/11/10/testing-in-rails-introduction/ > > > > You sound more advanced than beginner, but if you skim it, it might > > > help answer some questions. > > > > Best, > > > Kevin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---