[英]Mocking request timeout in RSpec
I have a class that makes a request to another service and I want to test error handing around that request. 我有一个向其他服务发出请求的类,我想测试处理该请求的错误。
The code looks like this: 代码如下:
response = RequestObject.post #this triggers a HTTP request
LocalObject.update(foreign_id: response.id, retrieved_at: Time.current )
In my tests I stub the request out and return JSON on success, but I want to test that if that response raises an error that the :foreign_id
and :retrieved_at
aren't set. 在我的测试中,我对请求进行存根处理,并在成功时返回JSON,但我想测试是否该响应引发未设置
:foreign_id
和:retrieved_at
的错误。
I stub the successful request like this: 我将成功的请求存根如下:
allow(RequestObject).to receive(:post).and_return({id: 1,})
What's a good way to mock RequestObject
raising a timeout error? 模拟
RequestObject
引发超时错误的好方法是什么?
(I'm using the Faraday gem for my requests) (我正在根据要求使用法拉第宝石 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.