Sha256: 13da1b37a25e983efa05e9cb88a26e13d6fc1376db6ba84a11b213406d608a32

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

require File.dirname(__FILE__) + '/../../../test_helper'

module Graticule
  module Geocoder
    class GoogleTest < Test::Unit::TestCase
      def setup
        URI::HTTP.responses = []
        URI::HTTP.uris = []
        @geocoder = Google.new(:key => 'APP_ID')
      end
    
      def test_success
        return unless prepare_response(:success)
      
        location = Location.new(
          :street => "1600 Amphitheatre Pkwy",
          :locality => "Mountain View",
          :region => "CA",
          :postal_code => "94043",
          :country => "US",
          :longitude => -122.083739,
          :latitude => 37.423021,
          :precision => :address
        )
        assert_equal location, @geocoder.locate('1600 Amphitheatre Parkway, Mountain View, CA')
      end
    
      def test_bad_key
        return unless prepare_response(:badkey)
        assert_raises(CredentialsError) { @geocoder.locate('x') }
      end
    
      def test_locate_missing_address
        return unless prepare_response(:missing_address)
        assert_raises(AddressError) { @geocoder.locate 'x' }
      end
    
      def test_locate_server_error
        return unless prepare_response(:server_error)
        assert_raises(Error) { @geocoder.locate 'x' }
      end

      def test_locate_too_many_queries
        return unless prepare_response(:limit)
        assert_raises(CredentialsError) { @geocoder.locate 'x' }
      end

      def test_locate_unavailable_address
        return unless prepare_response(:unavailable)
        assert_raises(AddressError) { @geocoder.locate 'x' }
      end

      def test_locate_unknown_address
        return unless prepare_response(:unknown_address)
        assert_raises(AddressError) { @geocoder.locate 'x' }
      end

    protected

      def prepare_response(id = :success)
        URI::HTTP.responses << response('google', 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/google_test.rb
graticule-0.2.1 test/unit/graticule/geocoder/google_test.rb
graticule-0.2.2 test/unit/graticule/geocoder/google_test.rb