Sha256: 736ff97f39a27136c450651ccad419d9525203608ebb7836f7ab28813f1c06a9

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 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.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

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
GUI-graticule-0.2.7.2 test/unit/graticule/geocoder/meta_carta_test.rb
GUI-graticule-0.2.7.3 test/unit/graticule/geocoder/meta_carta_test.rb
GUI-graticule-0.2.7.4 test/unit/graticule/geocoder/meta_carta_test.rb
GUI-graticule-0.2.7.5 test/unit/graticule/geocoder/meta_carta_test.rb
GUI-graticule-0.2.7.6 test/unit/graticule/geocoder/meta_carta_test.rb
norman-graticule-0.2.7 test/unit/graticule/geocoder/meta_carta_test.rb
graticule-0.2.6 test/unit/graticule/geocoder/meta_carta_test.rb
graticule-0.2.4 test/unit/graticule/geocoder/meta_carta_test.rb
graticule-0.2.3 test/unit/graticule/geocoder/meta_carta_test.rb
graticule-0.2.5 test/unit/graticule/geocoder/meta_carta_test.rb