Hi there, A couple of complete newb questions here. Should I be spec''ing the existence of attributes on models? While reading through the docs and googling I haven''t seen any example that checks if attributes exist on a model. i.e. Game.Description. Likewise, what I''ve seen on spec''ing associations seems light. What spec should I be writing before I add a belongs_to :genre to my game model? The closest I''ve seen is probably this -> http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations Cheers, Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/2c263b4b/attachment.html
Hi Tim, I''m just a newb too, but as I understand it, you should only spec code you write. In the case of attributes on models, it''s ActiveRecord code. You shouldnt need to test that. I have not been doing this. That said, I''d love to get the word from some people that have been doing it for a while. -- Matt Berther http://www.mattberther.com On Mar 31, 2008, at 6:21 PM, Tim Haines wrote:> Hi there, > > A couple of complete newb questions here. > > Should I be spec''ing the existence of attributes on models? While > reading through the docs and googling I haven''t seen any example > that checks if attributes exist on a model. i.e. Game.Description. > > Likewise, what I''ve seen on spec''ing associations seems light. What > spec should I be writing before I add a belongs_to :genre to my game > model? The closest I''ve seen is probably this -> http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > Cheers, > > Tim. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/7129f577/attachment.html
Hey Matt, Cheers for that. Yeah - I''m not speccing methods like save, valid?, errors etc.. I am writing "belongs_to" though, so figure that should be specced somehow. I guess when I''m adding a "description" field to something, I might be writing a migration for it, but no other model code. I guess if there''s no model code for it, then it kinda makes sense that it doesn''t need to be in the model spec. Tim.. On 01/04/2008, Matt Berther <matt at mattberther.com> wrote:> > Hi Tim, > I''m just a newb too, but as I understand it, you should only spec code you > write. In the case of attributes on models, it''s ActiveRecord code. You > shouldnt need to test that. I have not been doing this. > > That said, I''d love to get the word from some people that have been doing > it for a while. > > -- > Matt Berther > http://www.mattberther.com > > > > > On Mar 31, 2008, at 6:21 PM, Tim Haines wrote: > > Hi there, > > A couple of complete newb questions here. > > Should I be spec''ing the existence of attributes on models? While reading > through the docs and googling I haven''t seen any example that checks if > attributes exist on a model. i.e. Game.Description. > > Likewise, what I''ve seen on spec''ing associations seems light. What spec > should I be writing before I add a belongs_to :genre to my game model? The > closest I''ve seen is probably this -> > http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > Cheers, > > Tim. > _______________________________________________ > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/eeaefdfd/attachment.html
I have been using the following approach. Looking forward to see if anyone else does something better to test associations ... describe "Profile Associations" do it "should belong to ..." do Profile.should_receive(:belongs_to).with(:account) load "profile.rb" end end Anthony Broad-Crawford On Mar 31, 2008, at 8:21 PM, Tim Haines wrote:> Hi there, > > A couple of complete newb questions here. > > Should I be spec''ing the existence of attributes on models? While > reading through the docs and googling I haven''t seen any example > that checks if attributes exist on a model. i.e. Game.Description. > > Likewise, what I''ve seen on spec''ing associations seems light. What > spec should I be writing before I add a belongs_to :genre to my game > model? The closest I''ve seen is probably this -> http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > Cheers, > > Tim. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/2f4d34a4/attachment-0001.html
And just to argue with myself a little - the spec output is a pretty nice of how a model works. Perhaps I''m thinking that something for the description should be specced so that it appears in the spec output.. Looking forward to taking this newb hat off sometime soon - I''m definitely spending way too much time on google at the moment. Tim.. On 01/04/2008, Tim Haines <tmhaines at gmail.com> wrote:> > Hey Matt, > > Cheers for that. Yeah - I''m not speccing methods like save, valid?, > errors etc.. I am writing "belongs_to" though, so figure that should be > specced somehow. I guess when I''m adding a "description" field to > something, I might be writing a migration for it, but no other model code. > I guess if there''s no model code for it, then it kinda makes sense that it > doesn''t need to be in the model spec. > > Tim.. > > On 01/04/2008, Matt Berther <matt at mattberther.com> wrote: > > > > Hi Tim, > > I''m just a newb too, but as I understand it, you should only spec code > > you write. In the case of attributes on models, it''s ActiveRecord code. You > > shouldnt need to test that. I have not been doing this. > > > > That said, I''d love to get the word from some people that have been > > doing it for a while. > > > > -- > > Matt Berther > > http://www.mattberther.com > > > > > > > > > > On Mar 31, 2008, at 6:21 PM, Tim Haines wrote: > > > > Hi there, > > > > A couple of complete newb questions here. > > > > Should I be spec''ing the existence of attributes on models? While > > reading through the docs and googling I haven''t seen any example that checks > > if attributes exist on a model. i.e. Game.Description. > > > > Likewise, what I''ve seen on spec''ing associations seems light. What > > spec should I be writing before I add a belongs_to :genre to my game model? > > The closest I''ve seen is probably this -> > > http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > > > Cheers, > > > > Tim. > > _______________________________________________ > > 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 > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/5171c459/attachment.html
It looks like my first note didn''t go through ... so I apologize if it is delayed and this is a duplicate. My colleagues and I have been testing associations like this ... it "should have one account" do Profile.should_receive(:has_one).with(:account) load "profile.rb" end We like this as we are only testing the code we write and not testing ActiveRecord. If anyone has a better approach I know we would be interested in learning about it. Anthony Broad-Crawford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/9c4e627e/attachment-0001.html
for associations, among other things, i''ve been using http://rspec-on- rails-matchers.googlecode.com/svn/trunk/README linoj On Mar 31, 2008, at 8:33 PM, Anthony Broad-Crawford wrote:> I have been using the following approach. Looking forward to see > if anyone else does something better to test associations ... > > describe "Profile Associations" do > > it "should belong to ..." do > Profile.should_receive(:belongs_to).with(:account) > > load "profile.rb" > end > > end > > Anthony Broad-Crawford > > > On Mar 31, 2008, at 8:21 PM, Tim Haines wrote: >> Hi there, >> >> A couple of complete newb questions here. >> >> Should I be spec''ing the existence of attributes on models? While >> reading through the docs and googling I haven''t seen any example >> that checks if attributes exist on a model. i.e. Game.Description. >> >> Likewise, what I''ve seen on spec''ing associations seems light. >> What spec should I be writing before I add a belongs_to :genre to >> my game model? The closest I''ve seen is probably this -> http:// >> blog.imperialdune.com/2007/2/27/rspec-ing-model-associations >> >> Cheers, >> >> Tim. >> _______________________________________________ >> 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-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/d9472122/attachment.html