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
  response.stubs(:body).returns(@xml)
  stub_google_call(address,response)
end

def stub_google_call(address,response)
url = "http://maps.google.com/maps/geo? q = #{Geokit ::Inflector ::url_escape (address)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8" Geokit ::Geocoders ::GoogleGeocoder .stubs(:call_geocoder_service).with(url).returns(response)
end


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

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to