Created
May 17, 2009 00:09
-
-
Save mdoel/112850 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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