[rspec-users] Testing Rails Associations
dchelimsky at gmail.com
Fri Jul 6 03:07:40 EDT 2007
On 7/3/07, Daniel N <has.sox at gmail.com> wrote:
> I'm very new to rspec, so if this is not the right forum please let me
> I'm starting to spec my models first in an existing rails app, porting from
> a mix of Test::Unit, and simply_bdd amongst others.
> I'm at the point where I want to test that certain associations are
> present. What I'm not sure of is should I test the association or the
> method and return object.
> That is, if I wanted to test a has_many should I:
> Confirm the methods exist, and that the return an array etc
> Check that the model has the named has_many association through it's
> On one hand the second one looks like it will be a bit more robust, since
> if there is a has_many relationship, then all the associated methods may be
> used througout the app. This would put testing in the one place.
> On the other hand, this would be really testing the implementation of the
> model rather than it's behaviour. The behaviour is to call
> @article.comments and have an array of comments returned.
> Any thoughts?
I think the jury is still out on this one. Both approaches present
problems, and no better approaches have been proposed. I'd say try it
both ways and report back on experiences.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users