【发布时间】:2014-08-28 15:09:52
【问题描述】:
我正在尝试使用 webmock 模拟来自 web api 的意外行为,例如找不到服务器和超时。
最好的方法是什么?我能想到的就是做这样的事情:
stubbed_request = stub_request(:get, "#{host}/api/something.json").
with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
to_return(:status => [500, "Internal Server Error"])
这应该适用于 404 等问题,但我如何测试超时、找不到服务器/离线服务器和没有互联网连接强>?
【问题讨论】: