[rspec-users] Mocking ActiveResource
pergesu at gmail.com
Wed Feb 7 05:55:29 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:
> > 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.
Takes a couple steps (with my current solution):
1. Mock Net::HTTP.new to return some mock http object
2. mock http_object.get to return a mock http response
3. mock http_response.body to return the contents of your file
I think http_object has to have :null_object => true if you want to
keep things simple.
I ended up tossing ARes altogether, so I'm not actually using it at
this point. But that's at least pretty close to what I did. Ugly,
but it worked.
More information about the rspec-users