# Testing ActiveResource models with HttpMock

**URL:** <https://www.ruby-forum.com/t/testing-activeresource-models-with-httpmock/153709>\
**Category:** Rails\
**Created:** [November 20, 2008, 11:12am UTC](https://www.ruby-forum.com/t/testing-activeresource-models-with-httpmock/153709 "2008-11-20T11:12:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/2bfe46/32.png) [@xavier](https://www.ruby-forum.com/u/xavier)\
**Post date:** [November 20, 2008, 11:12am UTC](https://www.ruby-forum.com/t/testing-activeresource-models-with-httpmock/153709/1 "2008-11-20T11:12:22Z")

</div>

Hi all,

I have already spent (too) many hours trying to wire HttpMock in my  
test suite and I am stuck. I’m setting up my “remote fixtures” using  
a technique quite similar to what’s described here:

> **[ActiveResource and Testing](https://thoughtbot.com/blog/activeresource-and-testing)**
>
> ActiveResource is a pretty amazing implementation of REST, made in Ruby, for...

but even the simplest of my test requests are not accepted. I always  
bump into “ActiveResource::InvalidRequestError: No response recorded  
for …”

I see two problems:

1. The real API requires HTTP Basic Authentication so all my client  
requests include an authorization header which I’ve added to my  
request. But as there’s no documentation at all about how to do this,  
I might be mistaken. I am adding the expected request header as  
follow:

2. I am wondering if this bug  
[Code Intensity: Bug in ActiveResource's HttpMock?](http://codeintensity.blogspot.com/2007/05/bug-in-activeresources-httpmock.html)  
has actually ever been fixed, looking at HttpMock’s code, I don’t see  
how the ordering of the hash key is guaranteed, unless there’s some  
more ActiveSupport magic involved (but I don’t think so).

Any help about this will be greatly appreciated. If I judge by the  
number of results returned by my various Google searches on that  
topic, it seems like there are not many people using ActiveResource  
testing… or only a bunch unlucky few have problems with it. 😉

Regards,

Xavier

---

<div class="post-metadata">

**Author:** ![xavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/2bfe46/32.png) [@xavier](https://www.ruby-forum.com/u/xavier)\
**Post date:** [January 9, 2009, 2:22am UTC](https://www.ruby-forum.com/t/testing-activeresource-models-with-httpmock/153709/2 "2009-01-09T02:22:28Z")

</div>

On Thu, Nov 20, 2008 at 3:11 AM, Xavier [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Any help about this will be greatly appreciated. If I judge by the  
> number of results returned by my various Google searches on that  
> topic, it seems like there are not many people using ActiveResource  
> testing… or only a bunch unlucky few have problems with it. 😉

I just wrote a blog post summarizing what I could find, and how we are  
going to address the problem of testing (hit a real server with the AR  
client):

[http://pivotallabs.com/users/chad/blog/articles/656-automated-end-to-end-integration-testing-for-activeresource-apis](http://pivotallabs.com/users/chad/blog/articles/656-automated-end-to-end-integration-testing-for-activeresource-apis)

– Chad
