ruby – RSpec如何打开?

我一直试图打开,开放的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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...