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