Sha256: 442bcd3e6c762acdcde579c777f9e932a25820531f38152352879dd9aae71128

Contents?: true

Size: 1.78 KB

Versions: 11

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

describe Sgeoip do
  it 'should return correct info for ip' do
    ip_info = Sgeoip::scrape('8.8.8.8')

    ip_info["host"].should == "google-public-dns-a.google.com"
    ip_info["country"].should == "United States"
    ip_info["country_code"].should == "US (USA)"
    ip_info["region"].should == "California"
    ip_info["city"].should == "Mountain View"
    ip_info["zip"].should == "94043"
    ip_info["error"].should be_nil
  end
  
  it 'should return correct info for ip using geoip tool' do
    ip_info = Sgeoip::geoiptool('8.8.8.8')

    ip_info["host"].should == "google-public-dns-a.google.com"
    ip_info["country"].should == "United States"
    ip_info["country_code"].should == "US (USA)"
    ip_info["region"].should == "California"
    ip_info["city"].should == "Mountain View"
    ip_info["zip"].should == "94043"
    ip_info["error"].should be_nil
  end
  
  it 'should return correct info for ip using hostip' do
    ip_info = Sgeoip::hostip('8.8.8.8')

    ip_info["host"].should == "N/A"
    ip_info["country"].should == "United States"
    ip_info["country_code"].should == "US"
    ip_info["region"].should == "N/A"
    ip_info["city"].should == "Mountain View"
    ip_info["zip"].should == "N/A"
    ip_info["error"].should be_nil
  end
  
  it 'should return an error for a bad ip' do
    ip_info = Sgeoip::scrape('1.c.aa.p/')
    
    ip_info["error"].should == "Results Not Found"
  end
  
  it 'should strip and special non utf-8 characters' do
    ip_info = Sgeoip::scrape('189.62.243.113')

    ip_info["host"].should == "bd3ef371.virtua.com.br"
    ip_info["country"].should == "Brazil"
    ip_info["country_code"].should == "BR (BRA)"
    ip_info["region"].should == "Sao Paulo"
    ip_info["city"].should == "So Paulo"
    ip_info["error"].should be_nil
  end
  
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sgeoip-0.2.2 spec/sgeoip_spec.rb
sgeoip-0.2.1 spec/sgeoip_spec.rb
sgeoip-0.2.0 spec/sgeoip_spec.rb
sgeoip-0.1.7.1.5 spec/sgeoip_spec.rb
sgeoip-0.1.7.1 spec/sgeoip_spec.rb
sgeoip-0.1.7 spec/sgeoip_spec.rb
sgeoip-0.1.6 spec/sgeoip_spec.rb
sgeoip-0.1.5 spec/sgeoip_spec.rb
sgeoip-0.1.4 spec/sgeoip_spec.rb
sgeoip-0.1.3 spec/sgeoip_spec.rb
sgeoip-0.1.2 spec/sgeoip_spec.rb