alexreisner / geocoder

Complete Ruby geocoding solution.
http://www.rubygeocoder.com
MIT License
6.35k stars 1.19k forks source link

Rspec configure overriden #1663

Open benj-p opened 1 month ago

benj-p commented 1 month ago

Expected behavior

Geocoder config in Rspec.configure should take precedence in test environment.

Actual behavior

I'm using :mapbox as a default lookup in my app but there's one specific callback where I need to use Nominatim instead (Geocoder.search([latitude, longitude], lookup: :nominatim)).

However, because of this, despite having setup Geocoder to use :test in my Rspec settings (Geocoder.configure(lookup: :test, ip_lookup: :test)) it's using Nominatim when that callback is executed. Removing lookup: :nominatim does make it use the :test lookup in the test environment.

Environment info

alexreisner commented 1 month ago

Thanks for this. Currently, specifying the lookup in the call to Geocoder.search overrides the global config, and that's how it should be in :production and :development environments. I think you're asking whether it should be that way in :test.

I'm not sure. If the behavior were changed, it would make it impossible to use any lookup but :test in the :test environment, and I can imagine cases where people want to make an actual API call.

I think this is best solved by stubbing out your method that calls Geocoder.search with the Nominatim lookup. Your use case is a little unusual and I'm worried that changing the default/override behavior in a single environment will lead to unexpected results. Does that make sense? Let me know if I'm missing anything.