Hello, As I''m becoming more and more familiar with mocking/stubbing, I''m going back to some of my model specs and revaluating how I wrote them. I have certain models in which validation requires the presence of an associated model, which itself needs to be valid(validates_presence_of and validates_associated). When I wrote the specs, I wrote helpers for the attributes instead of fixtures, like so: module UserSpecHelper def valid_user_attributes { :email => "test at here.com", :password => "tttttt", :password_confirmation => "tttttt" } end end If the model had a required associated model, I''d also add some valid attribute helpers to make the associated model pass as well: module UserSpecHelper def valid_user_attributes { :email => "test at here.com", :password => "tttttt", :password_confirmation => "tttttt" } end def valid_shipping_address_attributes { :street => "blah street", :city => "blah", :state => "CA", :zip => "54455" } end end Now, I''ve been thinking, I should probably just stub out the associated models in order to focus my specs on one model, the model being tested. Would that be better practice? Thanks, Matt Lins
Matthew, If your intent is to test the behaviour of your model(s), then yes mocking and stubbing are a good [_the_] way to go.> > Cheers!sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071114/7bd49a79/attachment.html
On Nov 14, 2007, at 4:08 PM, sinclair bain wrote:> Matthew, > > If your intent is to test the behaviour of your model(s), then yes > mocking and > stubbing are a good [_the_] way to go.Except, of course, that you are no longer really validating the associated models - only your mocks. Scott
But, that should be okay, since my intent is not to test the associated models. I have a separate spec file for those models. On 11/14/07 3:27 PM, "Scott Taylor" <mailing_lists at railsnewbie.com> wrote:> > On Nov 14, 2007, at 4:08 PM, sinclair bain wrote: > >> Matthew, >> >> If your intent is to test the behaviour of your model(s), then yes >> mocking and >> stubbing are a good [_the_] way to go. > > Except, of course, that you are no longer really validating the > associated models - only your mocks. > > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
of course, you do both. you need to unit test in isolation, as well as integration test the stack. On Nov 15, 2007 5:44 AM, Matthew Lins <mlins at webinforem.com> wrote:> But, that should be okay, since my intent is not to test the associated > models. I have a separate spec file for those models. > > > > On 11/14/07 3:27 PM, "Scott Taylor" <mailing_lists at railsnewbie.com> wrote: > > > > > On Nov 14, 2007, at 4:08 PM, sinclair bain wrote: > > > >> Matthew, > >> > >> If your intent is to test the behaviour of your model(s), then yes > >> mocking and > >> stubbing are a good [_the_] way to go. > > > > Except, of course, that you are no longer really validating the > > associated models - only your mocks. > > > > 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 >