[rspec-users] How to mock an association

Edvard Majakari edvard at majakari.net
Mon Feb 11 09:21:23 EST 2008

On Feb 11, 2008 1:43 PM, Wes Shaddix <wshaddix at gmail.com> wrote:
> I've got a "group" model that has a user_id attribute and a
> validates_existence_of :user and validates_presence_of :user_id
> validations. What method(s) do I need to stub on the User mock to
> intercept those validation calls? My goal is to isolate the Group model
> from the User model.

See http://www.ruby-forum.com/topic/138342

and http://tersesystems.com/post/9700067.jhtml

Obvious 'rails mocking associations' seemed to work for me, unless I
misunderstood the question.

Of course, you could just stub 'valid?' for any AR object as well.
"One day, when he was naughty, Mr Bunnsy looked over the hedge into
Farmer Fred's field and it was full of fresh green lettuces. Mr
Bunnsy, however, was not full of lettuces. This did not seem fair."
  -- Terry Pratchett, Mr. Bunnsy Has An Adventure

More information about the rspec-users mailing list