Testing ActiveResource models with HttpMock

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:

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:

    request_headers = {
    ‘Authorization’ => ‘Basic REPLACEDBUTYOUGETTHEIDEA==’
    }

    ActiveResource::HttpMock.respond_to do |mock|
    mock.get “/contacts.xml”, request_headers, load_remote_fixtures
    (‘contacts.xml’)
    end

  2. I am wondering if this bug
    Code Intensity: Bug in ActiveResource's HttpMock?
    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. :wink:

Regards,

Xavier

On Thu, Nov 20, 2008 at 3:11 AM, Xavier [email protected]
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. :wink:

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

– Chad