Sha256: f66b268ab3333beda8a1f9684e96680b0e6535ffe3ab7ec0c0fb23f4dff5c6d2

Contents?: true

Size: 1010 Bytes

Versions: 3

Compression:

Stored size: 1010 Bytes

Contents

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

module Graticule
  module Geocoder
    class HostIpTest < Test::Unit::TestCase
      
      def setup
        @geocoder = HostIp.new
        URI::HTTP.responses = []
        URI::HTTP.uris = []
      end
      
      def test_success
        prepare_response :success
        
        location = Location.new :country => 'US', :locality => 'Mountain View',
          :region => 'CA', :latitude => 37.402, :longitude => -122.078
        
        assert_equal location, @geocoder.locate('64.233.167.99')
      end
      
      def test_unknown
        prepare_response :unknown
        assert_raises(AddressError) { @geocoder.locate('127.0.0.1') }
      end

      def test_private_ip
        prepare_response :private
        assert_raises(AddressError) { @geocoder.locate('127.0.0.1') }
      end
    private
    
      def prepare_response(id = :success)
        URI::HTTP.responses << response('host_ip', id, 'txt')
      end
      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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