The Geocoder gem allows for stubbing while testing: https://github.com/alexreisner/geocoder#testing
Testing
When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the :test lookup and/or :ip_lookup
Geocoder.configure(lookup: :test, ip_lookup: :test)
Add stubs to define the results that will be returned:
Geocoder::Lookup::Test.add_stub(
"New York, NY", [
{
'coordinates' => [40.7143528, -74.0059731],
'address' => 'New York, NY, USA',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US'
}
]
)
This works when calling the service without specifying a service:
results = Geocoder.search(self.address)
But when I specify a service directly in the call, the stubbing doesn't happen. Is there a way to stub this type of call?
results = Geocoder.search(self.address, lookup: :google)
I am new to ruby and rails and would appreciate any help.