How to stub any instances for a given class using Rspec Mocks
any_instance was recently added to rspec, so your example now works for me as it is with rspec 2.7.
Update for rspec 3:
The new way to do this isallow_any_instance_of(String).to receive(:foo).and_return(1)
Here is more any_instance documentation: https://relishapp.com/rspec/rspec-mocks/docs/working-with-legacy-code/any-instance