[mocha-developer] Automatically mocking ActiveRecord methods

Frederick Cheung fred at 82ask.com
Mon Apr 2 12:29:14 EDT 2007


On 2 Apr 2007, at 17:24, James Moore wrote:

>
> I'm now wondering whether a better way to do this is to add a  
> facility to
> add callbacks that can create mocks and stubs when a particular  
> object is
> instantiated from the database.  A sort of cleanup method on Rails  
> find*()
> methods that will allow you to do mock/stub methods on an object  
> with a
> particular id (or some set of criteria) when it's created.

I did this via the after_find callback a few weeks ago. I posted my  
code here when I did it maybe you'll find some inspiration there ?

Fred
>
> In any case, I agree that it should be some sort of addon facility,  
> and I
> don't think there's any reason why it would need to touch Object  
> directly.
>
>  - James Moore
>
> On 3/27/07, James Mead <jamesmead44 at gmail.com> wrote:
>>
>> I can see why you might want to do this. I'm not sure I would want  
>> to add
>> another public instance method to Object - recently I've been  
>> looking into
>> how to reduce the number of such methods added to Object. Also I  
>> don't
>> really want to incorporate any more Rails-specific code into  
>> Mocha. The
>> Mocha Rails plugin is currently little more than a conditional  
>> require
>> statement.
>>
>> Can I suggest you consider creating your own Rails plugin and see how
>> things
>> go...?
>>
>> --
>> James.
>> http://blog.floehopper.org
>> _______________________________________________
>> mocha-developer mailing list
>> mocha-developer at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/mocha-developer
>>
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer



More information about the mocha-developer mailing list