[rspec-users] stub_model() and ActiveRecord Associations

Zach Dennis zach.dennis at gmail.com
Tue Aug 26 22:26:50 EDT 2008


On Tue, Aug 26, 2008 at 10:03 PM, David Chelimsky <dchelimsky at gmail.com> wrote:
> On Tue, Aug 26, 2008 at 8:51 PM, Mark Wilden <mark at mwilden.com> wrote:
>> On Tue, Aug 26, 2008 at 5:01 PM, David Chelimsky <dchelimsky at gmail.com>
>> wrote:
>>
>>>
>>> @target_comment = stub_model(Target)
>>> @target.stub!(:comments).and_return([@target_comment])
>>
>> That's what we do - what would the drawbacks be?
>
> It's more invasive than I'd like. It's not all that risky though. I
> just feel dirty whenever I mock methods on the objects I'm focused on.
> FWIW.

A similar approach I've used when I'm not utilizing custom SQL logic
(that requires hitting the database) which is less "dirty" IMO than
modifying the object you're focusing on is:

  comments = [stub_model(Target)]
  @target.comments = comments


-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com




-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com


More information about the rspec-users mailing list