How to create a stub that applies to all spec files in RSpec

Viewed 4991

I'm wanting to know if there is an easy way to include a stub in all of my spec files. I'm using the Geocoder gem and when I run my RSpec tests I don't want it attempting to download the location information.

I've found the following solution which works perfectly. However, I don't want to write the same three lines in every spec file.

before(:each) do
  User.any_instance.stub(:geocode) { [1,1] }
end

Is it possible to put something in my spec_helper.rb file?

1 Answers
Related