使用fakeweb或webmock在Ruby中模拟RestClient::GatewayTimeout?
我经常在我的应用程序中看到 RestClient::GatewayTimeout
。我正在尝试找出如何正确测试这一点,以确保我的应用程序能够优雅地处理它。
我看到的与此最接近的东西是 stub_request(:any, 'www.example.net').to_timeout
它会引发 RestClient::RequestTimeout
但不是 RestClient::GatewayTimeout
。模拟后者的最佳方法是什么?
I often see RestClient::GatewayTimeout
in my application. I'm trying to figure out how to properly test for this, to make sure my application handles it gracefully.
The closest thing to this that I see is stub_request(:any, 'www.example.net').to_timeout
That raises RestClient::RequestTimeout
however and not RestClient::GatewayTimeout
. What's the best way to simulate the latter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
stub_request(:any, 'www.example.net').to_raise(RestClient::GatewayTimeout)
显然,这仅适用于 RestClient,并且如果您将 RestClient 更改为
其他一些库,你也必须改变你的测试。
stub_request(:any, 'www.example.net').to_raise(RestClient::GatewayTimeout)
This will obviously work only for RestClient and if you change RestClient to
some other library, you'll have to change your test too.