Search code examples
ruby-on-railsrubytestingmockingrails-geocoder

Manual mock for Geocoder


How could I mock any method without using any gem?

Suppose I have access to an complex object like request

How could I make

request.location.country

to return a mocked value.

I read I can mock geocoder results with gems, but I would like to know a generic way.


Solution

  • Here's how I've been doing it

    foo = Geocoder.search('Paris, TX')
    foo.first.county
    

    I'm using the BingAPI, and to figure out what options I can access on the foo.first object, I take a look at the Geocoder docs:

    http://rdoc.info/github/alexreisner/geocoder/master/Geocoder/Result/Bing