Sha256: f2a965d09a6f17ab6b40995fb0023068ca307b8689e6280a472ced0b82c97ae1

Contents?: true

Size: 950 Bytes

Versions: 6

Compression:

Stored size: 950 Bytes

Contents

# encoding: UTF-8
require '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

6 entries across 6 versions & 1 rubygems

Version Path
graticule-2.7.2 test/graticule/geocoder/host_ip_test.rb
graticule-2.7.1 test/graticule/geocoder/host_ip_test.rb
graticule-2.7.0 test/graticule/geocoder/host_ip_test.rb
graticule-2.6.0 test/graticule/geocoder/host_ip_test.rb
graticule-2.5.0 test/graticule/geocoder/host_ip_test.rb
graticule-2.4.0 test/graticule/geocoder/host_ip_test.rb