How to mute gmaps4rails geocoding function in rspec tests?

I am using gmaps4rails and trying to develop some tests.

I have a factory

factory :country do
   sequence(:name) { |n| "Country#{n}" }
end

which is obviously not recognized by Google.

Validation failed: Gmaps4rails address Address invalid

An API call also takes time to execute in my tests.

How can I drown out an API call?

I tried adding

before(:each)
  Country.stub(:geocode)
end

in the spec file, but it has no effect.

My model looks like

class Country < ActiveRecord::Base
  acts_as_gmappable :lat => 'latitude', :lng => 'longitude'
  def gmaps4rails_address
    "#{self.name}" 
  end
  geocoded_by :gmaps4rails_address

  after_validation :geocode
end

Thanks for any ideas.

+5
source share
1 answer

There is nothing to do with the integers in a name.

I think the address is missing or invalid.

In any case, there are many ways to either skip geocoding or drown it out.

Take a look at the characteristics of gemstones

+5
source

All Articles