From 1de2bb922b8183dd1bc568c3d498a67cb1edee9e Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 24 Aug 2012 22:49:32 -0400 Subject: [PATCH] Add documentation for :test lookup. --- README.rdoc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.rdoc b/README.rdoc index fa4371d2..f77f8dfe 100644 --- a/README.rdoc +++ b/README.rdoc @@ -440,6 +440,29 @@ You can use Geocoder outside of Rails by calling the <tt>Geocoder.search</tt> me This returns an array of <tt>Geocoder::Result</tt> objects with all information provided by the geocoding service. Please see above and in the code for details. +== Testing Apps that Use Geocoder + +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 and use the <tt>:test</tt> lookup. For example: + + Geocoder::Configuration.lookup = :test + + Geocoder::Lookup::Test.add_stub( + "New York, NY", [ + { + 'latitude' => 40.7143528, + 'longitude' => -74.0059731, + 'address' => 'New York, NY, USA', + 'state' => 'New York', + 'state_code' => 'NY', + 'country' => 'United States', + 'country_code' => 'US' + } + ] + ) + +Now, any time Geocoder looks up "New York, NY" its results array will contain one result with the above attributes. + + == Command Line Interface When you install the Geocoder gem it adds a +geocode+ command to your shell. You can search for a street address, IP address, postal code, coordinates, etc just like you can with the Geocoder.search method for example: -- GitLab