gpt4 book ai didi

ruby-on-rails - 在Ruby中使用fakeweb或webmock模拟RestClient::GatewayTimeout?

转载 作者:太空宇宙 更新时间:2023-11-03 16:08:55 25 4
gpt4 key购买 nike

我经常在我的应用程序中看到 RestClient::GatewayTimeout。我试图弄清楚如何对此进行正确测试,以确保我的应用程序能够优雅地处理它。

我看到的最接近这个的是 stub_request(:any, 'www.example.net').to_timeout

不过这引发了 RestClient::RequestTimeout 而不是 RestClient::GatewayTimeout。模拟后者的最佳方法是什么?

最佳答案

stub_request(:any, 'www.example.net').to_raise(RestClient::GatewayTimeout)

这显然只适用于 RestClient,如果您将 RestClient 更改为一些其他库,你也必须改变你的测试。

关于ruby-on-rails - 在Ruby中使用fakeweb或webmock模拟RestClient::GatewayTimeout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7884514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com