[rspec-users] cucumber - when to stub/mock

Mike Doel mike at mikedoel.com
Mon May 4 01:42:56 EDT 2009

On May 4, 2009, at 1:28 AM, aslak hellesoy wrote:

> Is there a good rule of thumb for when you make exceptions to the  
> 'no stubbing' philosophy of Cucumber?
> This is the rule of thumb: http://wiki.github.com/aslakhellesoy/cucumber/mocking-and-stubbing-with-cucumber

I'm in a similar boat as Matt.  My app does geocoding using Andre  
Lewis' excellent geokit gem (and the Rails plugin).  That stuff hits  
web-based geocoders (Google in my case).  I also scrape other web sites.

So, in order to make my testing executable without a net connection  
and avoid extra traffic on other folks' sites from my tests, I stub  
out the actual net call with code like this:

def stub_geocode_lookup(address,datafile)
   @xml = File.read(RAILS_ROOT + "/spec/fixtures/geocodes/" + datafile)
   response = MockSuccess.new

def stub_google_call(address,response)
   url = "http://maps.google.com/maps/geo? 

I also make use of FakeWeb in a couple places to do a similar thing  
for the scraping of sites.  I have a rake task that grabs fresh  
versions of the pages I'm going to scrape and deposits it into my spec/ 
fixtures directory.  If I run that every couple of days, I reduce my  
risk of having my fixture data diverge too far from what the  
production app actually sees.

Mike Doel

More information about the rspec-users mailing list