2
Я пытаюсь заглушить запрос геокодирования HTTP с помощью webmock.Webmock Ответ JSON для геокодирования
Но я всегда получаю эту ошибку:
NoMethodError: undefined method `[]' for nil:NilClass
context "geocoding" do
before :each do
@user = Fabricate :user
stub_request(:get, /.*yboss.yahooapis.com*/).to_return(:body => File.read(File.join("spec", "fixtures", "geocoder", "yahoo_maps_data.json")))
end
it 'should geocode if coordinates missing' do
without_coordinates = Location.new(name: "Test",
street: "Revierstrasse 1",
zipcode: "5020",
country: "AT",
user: @user, affiliate: @user)
result = without_coordinates.geocode
without_coordinates.coordinates.should == [47.8029, 13.0472]
end
end
JSON FILE /spec/fixtures/geocoder/yahoo_maps_data.json
{"quality": "59",
"latitude": "47.8029",
"longitude": "13.0472",
"offsetlat": "47.802898",
"offsetlon": "13.04185",
"radius": "8600",
"boundingbox": {
"north": "47.854401",
"south": "47.7514",
"east": "13.1075",
"west": "12.9869"
}, "name": "",
"line1": "",
"line2": "5020 Salzburg",
"line3": "",
"line4": "Austria",
"cross": "",
"house": "", "street": "",
"xstreet": "",
"unittype": "",
"unit": "",
"postal": "5020",
"neighborhood": "",
"city": "Salzburg",
"county": "Salzburg",
"state": "Salzburg",
"country": "Austria",
"countrycode": "AT",
"statecode": "5",
"countycode": "5",
"timezone": "Europe/Vienna",
"uzip": "5020",
"hash": "",
"woeid": "12816173",
"woetype": "11"}
Что такое правильный способ ее реализации успешно?
Спасибо!