[rspec-users] Testing two interdependent ActiveRecord models
dj at collectiveinsight.net
Thu Jun 21 15:17:19 EDT 2007
Dear geeky, pay-your-debt-up-front-instead-of-later testing guru
(tell me I'm wrong!)...
I would appreciate if you (twould take a look at my message from a
few weeks ago, since I didn't get any replies. Any comments would
appreciated -- even if they are "you are barking up the wrong tree"
-- or "you should read article ____ so that you can rephrase /
rethink your question"
On Jun 8, 2007, at 9:05 AM, David James wrote:
> In my app, I'd like to test two model object objects that interact
> with each other. (In my example, a Person can have Contributions.)
> I guess you could say that I'm testing ActiveRecord associations.
> For example, a Person has zero or many Contributions. A Contribution
> has one or more People. This is the very basic version, but I think
> it will illustrate the dependency. (In practice, I'm interested in
> testing these associations because there is some extra logic going on
> that needs testing.)
> Here are my observations / questions:
> 1. Since there are two models, it doesn't seem quite right to make a
> unit test for this, does it?
> 2. There is an interaction between the two models. What is a good
> way to test the interaction? Do I put some of the testing in
> person_spec.rb and some in contribution_spec.rb? Or do I create some
> sort of "interaction" spec?
> 3. I don't think that an integration test makes sense, because I
> don't want to test the controller and views.
> 4. I wonder if mocks or stubs would make sense. I don't think I need
> to stub out a particular method (i.e. credit card processing),
> though. I'm pretty new to mocking, any advice or perspective would
> be helpful.
> I would appreciate any feedback -- testing philosophy, and maybe some
> hand waving, if you like. :)
> I would also be open to a refactoring / redesign if that will help
> with testing.
> rspec-users mailing list
> rspec-users at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users