[rspec-users] Mocking a 3rd party call, but with a few exceptions

Christopher Bailey chris at cobaltedge.com
Fri Sep 5 17:15:00 EDT 2008

I use geocoding in our app, and it permeates most of the core functionality.
 Because it makes a call out to Google or Yahoo or what not to do the
geocoding, I'd like to mock this for the bulk of my tests, except for the
few tests that actually do stuff where they need the real data.  I had
started wrapping all my specs with the equivalent (but a DRY form) of:
GeoInfo = Struct.new(:lat, :lng, :success)
describe "with fake geocoding" do
  before(:all) do
    fake_geocode = GeoInfo.new(123.456, 789.012, true)


  # bulk of tests are here

describe ... #other tests that want real geocoding here

But, that just seems like a poor way to do it.  I'm wondering, how can I
make GeoKit::Geocoders::MultiGeocoder fake by default, and then in the few
cases where I want it to be real, "un-stub" it or whatever you'd call it?

Christopher Bailey
Cobalt Edge LLC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080905/6acf585f/attachment.html>

More information about the rspec-users mailing list