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