Skip to content

Instantly share code, notes, and snippets.

@somebox
Created December 1, 2009 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somebox/246367 to your computer and use it in GitHub Desktop.
Save somebox/246367 to your computer and use it in GitHub Desktop.
# 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