Sha256: 5e41d2457ea982b236ea12541ead2dbc718db4623f13681da60ac6fe5d3cc2a2

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 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.393889, :longitude => 33.338611
        
        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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graticule-0.2.0 test/unit/graticule/geocoder/meta_carta_test.rb
graticule-0.2.1 test/unit/graticule/geocoder/meta_carta_test.rb
graticule-0.2.2 test/unit/graticule/geocoder/meta_carta_test.rb