ruby on rails 3 - Rspec for REST API call



我试图实现一个http调用的rspec…但到目前为止,我还没有成功……

http = Net::HTTP.new("secured site url", "443")
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE  
response = http.get("/query params",initheader = {'Accept' =>'application/xml'})
return response 

我需要一个rspec ..虽然我是新手,我尝试了很多方法,但它说预期:1次收到:0次

以下是我写的全部内容:

it "should be success" do
  @mock_http = mock("http")
  @mock_http.should_receive(:new).with("secured site url")
end 
如果我说错了,请纠正我。任何帮助都是感激的!由于

当然,您必须激活调用new语句的方法,因此您的代码应该看起来像:

it "should be success" do
  @mock_http = mock("http")
  Net::HTTP.should_receive(:new).with("secured site url", "443")
  some_method
end
def some_method
  http = Net::HTTP.new("secured site url", "443")
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE  
  response = http.get("/query params",initheader = {'Accept' =>'application/xml'})
  return response 
end

相关内容

  • 没有找到相关文章

最新更新