Created
December 1, 2009 15:26
-
-
Save somebox/246367 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
# GeoKit geocoder mocks, place in test_helper.rb | |
# mocks | |
def geo_mock(options={}) | |
defaults = {:lat=>1, :lng=>2, | |
:precision=>'address', :success => true, | |
:street_address=>'address', :zip=>'12345', | |
:city=>'city', :state=>'state', | |
:full_address => 'full address'} | |
res = mock('response') | |
res.stubs(defaults.merge(options)) | |
res | |
end | |
def failed_geo_mock | |
res = mock('response') | |
res.stubs({:success => false}) | |
res | |
end | |
# mocha | |
def mock_geocoder_returns(options) | |
MultiGeocoder.expects(:geocode).returns(geo_mock(options)) | |
end | |
def geocoder_should_be_used(times=1) | |
MultiGeocoder.expects(:geocode).times(times).returns(geo_mock) | |
end | |
def geocoder_should_fail | |
MultiGeocoder.expects(:geocode).returns(failed_geo_mock) | |
end | |
def geocoder_should_not_be_used | |
MultiGeocoder.expects(:geocode).never | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment