require 'test/unit'
require 'rc_rest/uri_stub'
require 'yahoo/geocode'
class Yahoo::TestGeocode < Test::Unit::TestCase
def setup
URI::HTTP.responses = []
URI::HTTP.uris = []
@g = Yahoo::Geocode.new 'APP_ID'
@location = '701 First Street, Sunnyvale, CA'
end
def test_locate
URI::HTTP.responses << <<-EOF.strip
37.416384-122.024853701 FIRST AVESUNNYVALECA94089-1019US
EOF
assert_equal [37.416384, -122.024853],
@g.locate('701 First Street, Sunnyvale, CA').first.coordinates
assert_equal true, URI::HTTP.responses.empty?
assert_equal 1, URI::HTTP.uris.length
assert_equal 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=APP_ID&location=701%20First%20Street,%20Sunnyvale,%20CA&output=xml',
URI::HTTP.uris.first
end
def test_locate_bad_address
URI::HTTP.responses << <<-EOF.strip
The following errors were detected:
unable to parse location
EOF
assert_raise Yahoo::Error do
@g.locate 'yucksthoeusthaoeusnhtaosu'
end
assert_equal true, URI::HTTP.responses.empty?
assert_equal 1, URI::HTTP.uris.length
assert_equal 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=APP_ID&location=yucksthoeusthaoeusnhtaosu&output=xml',
URI::HTTP.uris.first
end
end
class Yahoo::Geocode::TestLocation < Test::Unit::TestCase
def test_coordinates
loc = Yahoo::Geocode::Location.new
loc.latitude = Math::E
loc.longitude = Math::PI
assert_equal [Math::E, Math::PI], loc.coordinates
end
end