【发布时间】:2018-10-16 16:03:38
【问题描述】:
我有一个叫做token wrapper的模块,里面有一个方法getToken:
def Tokenwrapper.getToken
uri = URI.parse("[URL REDACTED]/api/authenticate")
request = Net::HTTP::Post.new(uri)
request.basic_auth("email@domain.com", "pass")
request.content_type = "application/json"
request["Accept"] = "application/json"
req_options = {
use_ssl: uri.scheme == "https",
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
response
end
当我尝试使用以下断言对其进行测试时:
assert_equal("#<Net::HTTPOK:",Tokenwrapper.getToken[0..13])
我收到此错误:
NoMethodError: undefined method 'downcase' for 0..13:Range
我没有手动调用 downcase 方法,我看不出 ruby 应该自动调用的任何理由。为什么会发生这种情况?如何让我的测试运行?
老实说,我对 HTTP API 响应以及该网络领域的运作方式知之甚少,因此我希望能提供任何资源以及此问题的答案。
【问题讨论】: