我正在为 Ruby ( https://github.com/taf2/curb ) 使用 Curl gem,我需要在我的一个 rspec 测试中存根 Curl.get (返回空白响应)。
这是我尝试过的:
o = OpenStruct.new(:body => '')
Curl.any_instance.stub(:get).and_return(o)
不幸的是,Curl 是一个模块,而不是一个类(https://github.com/taf2/curb/blob/master/lib/curl.rb),所以当我尝试存根时它会出错:
stock_spec.rb:20:in `block (2 levels) in <top (required)>': undefined method `any_instance' for Curl:Module (NoMethodError)
我应该如何使用 rspec 对模块内的方法进行存根?