开发者

Problem Unit Testing ActiveResource Model with HttpMock

开发者 https://www.devze.com 2022-12-25 06:09 出处:网络
I\'m working on unit testing an ActiveResource model in my Rails application. I have my ActiveResource::HttpMock code in my test file as follows:

I'm working on unit testing an ActiveResource model in my Rails application. I have my ActiveResource::HttpMock code in my test file as follows:

ActiveResource::HttpMock.respond_to do |mock|
  mock.get "/audience/42/people/1.xml", {"Authorization" => "Basic VTExbTJCTzhkZzNMOmFpdU1nbHZJT2taakdPV3A=", "Accept" => "application/xml"}, @some_ivar
end

When I run my test, I get this message:

ActiveResource::InvalidRequestError: No response recorded for <GET: /audiences/42/people.xml?email_address=user%40domain.tld [AuthorizationBasic VTExbTJCTzhkZzNMOmFpdU1nbHZJT2taakdPV3A=Acceptapplication/xml] ()>

I'm sure this is a simple matter of not having my HttpMock configured properly, but at this point I'm unsure how to adjust to make the HttpMock object actually respond to the method call.

(If it's any help, this is related 开发者_运维问答to the StreamSend API's PeopleController. Since this is a third party API endpoint and there isn't a developer sandbox, mocking is really the only way to go on this one I think.)


Restraining the scope of require 'active_resource/http_mock' fixed this error for me. See this link.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号