Forum: Ruby on Rails Testing ActiveResource models with HttpMock

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Xavier (Guest)
on 2008-11-20 12:12
(Received via mailing list)
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:
http://giantrobots.thoughtbot.com/2007/2/2/activer...
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
http://codeintensity.blogspot.com/2007/05/bug-in-a...
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
Chad W. (Guest)
on 2009-01-09 03:22
(Received via mailing list)
On Thu, Nov 20, 2008 at 3:11 AM, Xavier <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/65...

-- Chad
This topic is locked and can not be replied to.