[rspec-users] Mocking ActiveResource

Pat Maddox pergesu at gmail.com
Wed Feb 7 12:10:16 EST 2007


On 2/7/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> On 2/7/07, Pat Maddox <pergesu at gmail.com> wrote:
> > On 2/7/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> > > On 2/7/07, Pat Maddox <pergesu at gmail.com> wrote:
> > > > I want to use ActiveResource in my app.  Instead of hitting server
> > > > though, I want it to load from a file when I call find.  Any clue how
> > > > I do that?
> > > >
> > >
> > > In the same way as you'd mock ActiveRecord I would think. Is this not
> > > working for you?
> >
> > No I want it to actually go through the process of finding something,
> > but just have it use a file rather than an actual server.
> >
>
> I see, so you don't want to mock ActiveResource, but the transport used by it.

Right

> This is an approach that I generally don't recommend. The lower level
> you're mocking at (HTTP, database connections, File I/O etc) the more
> you have to set up and things become very verbose and fragile. As a
> general rule:
>
>   Don't mock APIs you don't own.

I agree with you.  This is certainly how I work with my AR classes.
However there's a big difference in maturity between AR and ARes.
ARes isn't even "official" yet.  So while with AR I can mock
MyClass.find and know that AR does the right thing, I'm not entirely
sure with ARes.  I don't know how it's going to parse an XML document.
 Turns out it did some funky things and I couldn't use it.

Once I had one spec that demonstrated ARes worked for my purposes, I'd
just mock out all subsequent specs.

Pat


More information about the rspec-users mailing list