我一直试图打开,开放的uri版本,我没有成功.
我已尝试执行以下操作,但请求仍在继续:
Kernel.should_receive(:open).and_return("Whatever for now")
我也尝试过
OpenURI::OpenRead.should_receive(:open).and_return("Whatever for now")
自从我追踪到了在OpenURI中发出HTTP请求的地方.
在此先感谢您的任何建议!
解决方法
这就是我做的
class Gateway def do_something open('http://example.com').read end end
在我的规范中,我做了以下几点:
describe 'communication' do it 'should receive valid response from example.com' do gateway = Gateway.new gateway.stub_chain(:open,:read).and_return('Remote server response') gateway.do_something.should == "Remote server response" end end