Geokit was proving a difficult customer when it came to functional tests, I'd opted for the simple :auto_geocode option on an Address model and these were being created and saved via a Machinist blueprint.

The problem was that this triggered a call to the geolocation provider which slowed the tests and sometimes bombed by contravening request frequency rules set by the provider.

Anyhoo this article got me pointed in the right direction but the FakeGeocoder.geocode method still didnt get called, I was beginning to hate the internet for offering false hope, then a bit pokedy-poke-poke in geocoders.rb from the Geokit gem gave the answer... needed to override the FakeGeocoder.do_geocode method and bingo, we had a winner.

So in essence all you do is stick this at the end of yr blueprints.rb:

 

module GeoKit

  module Geocoders

    class FakeGeocoder < Geocoder

      def self.do_geocode(address, options = {})

        geocode_payload = GeoKit::GeoLoc.new(:lat => 123.456, :lng => 123.456)

        geocode_payload.success = true

        geocode_payload

      end

    end

  end

end

 

and whack this in  test_helper.rb

GeoKit::Geocoders::provider_order = [:fake]

and smell the sweet scent of victory in air.