Skip to content

Instantly share code, notes, and snippets.

@mdoel
Created May 17, 2009 00:09
Show Gist options
  • Save mdoel/112850 to your computer and use it in GitHub Desktop.
Save mdoel/112850 to your computer and use it in GitHub Desktop.
class MockSuccess < Net::HTTPSuccess
def initialize
end
end
class MockFailure < Net::HTTPSuccess
def initialize
end
end
# Used to prevent RSpec tests from actually calling the Google API
def stub_geocode_lookup(address,datafile)
@xml = File.read(RAILS_ROOT + "/spec/fixtures/geocodes/" + datafile)
response = MockSuccess.new
response.stubs(:body).returns(@xml)
stub_google_call(address,response)
end
def stub_broken_geocode_lookup(address)
response = MockFailure.new
response.stubs(:body).returns(nil)
stub_google_call(address,response)
end
def stub_google_call(address,response)
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector::url_escape(address)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8"
Geokit::Geocoders::GoogleGeocoder.stubs(:call_geocoder_service).with(url).returns(response)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment