Hi folks, I''m pretty new to TDD. Is there a standard approach on this: Is it better to write individual tests, or combine them? A specific example - if a model Foo validates the presence of both bar and baz, is it better to have a test each for bar and for baz, or to combine the validations into a combined bar/baz test? Thanks! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jan-13 22:51 UTC
Re: Best practice: individual or combined tests?
acreadinglist wrote:> Hi folks, > > I''m pretty new to TDD. Is there a standard approach on this: Is it > better to write individual tests, or combine them? A specific example > - if a model Foo validates the presence of both bar and baz, is it > better to have a test each for bar and for baz, or to combine the > validations into a combined bar/baz test?I''d test them individually. In general, you want each test pretty atomic. So for example, take a look at http://github.com/marnen/quorum2/blob/master/spec/models/event_spec.rb (the validation specs start at line 217). I''ve got separate specs for each validation. That code could use some DRYing up, though, and I do sometimes do things like [''one'', ''two'', ''three''].each do |field| it "should require #{field}" do @model.send "#{field}=", nil @model.should_not be_valid end end but note that this still produces three separate specs. I''d feel wrong if it didn''t.> > Thanks!Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jan-13 22:53 UTC
Re: Best practice: individual or combined tests?
Marnen Laibow-Koser wrote:> acreadinglist wrote: >> Hi folks, >> >> I''m pretty new to TDD. Is there a standard approach on this: Is it >> better to write individual tests, or combine them? A specific example >> - if a model Foo validates the presence of both bar and baz, is it >> better to have a test each for bar and for baz, or to combine the >> validations into a combined bar/baz test? > > I''d test them individually. In general, you want each test pretty > atomic. > > So for example, take a look at > http://github.com/marnen/quorum2/blob/master/spec/models/event_spec.rb > (the validation specs start at line 217).Trust Github to be smart about this! The direct URL for that line (!) is http://github.com/marnen/quorum2/blob/master/spec/models/event_spec.rb#L217 . Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.