2
我有一些代碼在我的Ruby on Rails項目如下,以獲得非軌API的HTTP響應需要幫助的在書面方式模擬的RSpec
應用程序/模型/ rest_api.rb
require "uri"
require "net/https"
require "net/http"
require "active_support"
class RestApi
# the URL for the Twitter Trends endpoint
@url = 'http://api.twitter.com/1/trends.json'
def self.sampleRes
uri = URI.parse(@url)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
return response
end
end
我剛纔開始學習Ruby on Rails和RSPEC。是否有人可以幫助我如何能寫的RSpec的HTTP請求,而不實際做出請求實際API URL(需要一些模擬)
嗨, 感謝您的快速響應。 您能否幫我解決一下在ruby的測試中編寫測試用例的問題:針對上例中給出的相同REST API處理的單元。 – 2011-07-11 07:44:33