Since you did not state your test framework, I'll give a specific answer.
I am using Cucumber and Rspec. While all of the above is true from @DevDude and @malandrina, here is a more complete tip for where the code can go, and how to also add entries for reverse geocoding (lat/lon --> address):
Put your stubs in the spec folder. I created an array of arrays so that I could add multiple "lookups" to be stubbed out:
spec/support/geocoder_stubs.rb
addresses = {
"230 West 43rd St., New York City, NY 10036" => {
'latitude' => 40.7573862,
'longitude' => -73.9881256,
'address' => '230 West 43rd St., New York City, NY 10036',
'city' => 'New York City',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US'
},
[40.75747130000001, -73.9877319] => {
'latitude' => 40.75747130000001,
'longitude' => -73.9877319,
'address' => '229 West 43rd St., New York City, NY 10036',
'city' => 'New York City',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US'
},
"Worthington, OH" => {
'latitude' => 40.09846115112305,
'longitude' => -83.01747131347656,
'address' => 'Worthington, OH',
'city' => 'Worthington',
'state' => 'Ohio',
'state_code' => 'OH',
'country' => 'United States',
'country_code' => 'US'
},
}
Geocoder.configure(:lookup => :test)
addresses.each { |lookup, results| Geocoder::Lookup::Test.add_stub(lookup, [results]) }
Reference your stubs in the Cucumber support folder:
features/support/env.rb
require Rails.root.join("spec/support/geocoder_stubs")
Hope this helps!