Sha256: bb9d5728d3df0e1c1b5ac1e3570bdc1a4403d525a96fccd57112eded911c5617

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe GeoLocation::City do
  before(:each) do
    @city = GeoLocation::City.new(File.expand_path '../data/GeoLiteCity.dat')
  end

  describe "initialization" do
    it "should set the file location" do
      @city.file_location.should == File.expand_path('../data/GeoLiteCity.dat')
    end
  end

  describe ".file_location" do
    it "should be able to change it" do
      @city.file_location = ''

      @city.file_location.should == ''
    end
  end

  describe ".from_ip" do
    it "should resolve to Guadalajara" do
      @city.from_ip('200.92.113.112').should == 'Guadalajara'
    end

    it "should resolve to Syracuse" do
      @city.from_ip('24.24.24.24').should == 'Syracuse'
    end

    it "should not resolve an unknown IP" do
      @city.from_ip('0.0.0.0').should == 'Unknown'
    end

    it "should raise an exception if file not found" do
      @city.file_location = ''
      lambda { @city.from_ip('0.0.0.0') }.should raise_error
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ivanvc-geolocation_city-0.0.1 spec/geolocation_city_spec.rb