forked from collectiveidea/graticule
/
meta_carta_test.rb
44 lines (34 loc) · 1.2 KB
/
meta_carta_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
module Graticule
module Geocoder
class MetaCartaTest < Test::Unit::TestCase
def setup
URI::HTTP.responses = []
URI::HTTP.uris = []
@geocoder = MetaCarta.new
end
def test_locate
prepare_response(:success)
expected = Location.new :latitude => 44.3939, :longitude => 33.3386
assert_equal expected, @geocoder.locate('baghdad')
assert_equal true, URI::HTTP.responses.empty?
assert_equal 1, URI::HTTP.uris.length
assert_equal 'http://labs.metacarta.com/GeoParser/?output=locations&q=baghdad',
URI::HTTP.uris.first
end
def test_locate_bad_address
prepare_response(:bad_address)
assert_raises(AddressError) { @geocoder.locate('aoeueou') }
end
def test_locations
prepare_response(:multiple)
expected = Location.new :latitude => -122.33083, :longitude => 47.60639
assert_equal expected, @geocoder.locate('seattle')
end
protected
def prepare_response(id = :success)
URI::HTTP.responses << response('meta_carta', id)
end
end
end
end