【发布时间】:2021-08-18 18:18:57
【问题描述】:
我有这样的定义
require 'httparty'
def distance_calculation
url = "https://api.distancematrix.ai/maps/api/distancematrix/json?origins=#
{@departure}&destinations=#{@destination}&key=lugtcyuuvliub;o;o"
response = HTTParty.get(url)
distance = response.parsed_response["rows"].first["elements"].first["distance"].
["text"]
end
结束 rspec 测试:
describe "#cargo" do
context "distance" do
it "returns hash with destination addresses, origin addresses & rows of datas" do
end
end
从 URL 解析中,我得到哈希,其中键是目标地址、原始地址、距离和持续时间。 如何通过使用 httparty gem 的 Rspec 定义进行测试,它不返回任何内容,只是将解析的字段(以 km 为单位的距离)写入变量。
【问题讨论】: