2013-01-08 61 views
0

我試着去實現一個HTTP調用rspec的......但我至今沒有成功..Rspec的REST的API調用

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 

我需要爲this..Though進出口新的這一個RSpec ,我試過很多方法,但它說,預計:1次好評:0次

這是所有我自己編寫:

it "should be success" do 
    @mock_http = mock("http") 
    @mock_http.should_receive(:new).with("secured site url") 
end 

請糾正我,如果我錯了..任何幫助表示讚賞!由於

回答

0

當然,你需要激活,其中新語句調用,所以你的代碼應該看起來像的方法:

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 
+0

感謝您的答覆..其實我試圖存根響應,然後使用它..我也試過這個,但它說失敗/錯誤:http.use_ssl = true NoMethodError:未定義的方法'use_ssl ='爲零:NilClass – unknown