Posted in Knowledge
Tags: activeresource, rest
Ever that kind of error when trying to use HttpMock to test your ActiveResource client code ?
I got that error, and for hours couldnt figure out why. I have followed the tests in the library (such as test/base_test.rb):
ActiveResource::HttpMock.respond_to do |mock|
mock.get “/people/1.xml”, {}, @somexml
…
Well, it turns out that I need to set .site = “http://localhost” on the ActiveResource class I’m using!
Hope this helps anyone who experience the same problem as mine.
But if you are developing both the web service client and the provider, it’s better to just execute the XML request to the provider application instead of doing HttpMock. Because well, it’s a local connection, so it’s fast. Also it can help find bugs in the provider application.