title: How to stub any instances for a given class using Rspec Mocks
body: <p>The following code raises an error: <code>undefined method 'any_instance' for String:Class</code></p>
  
  <pre><code>require 'rspec'
  
  RSpec.configure do |config|
    config.mock_with :rspec
  end
  
  describe String do
    it 'stubs' do
      String.any_instance.stub(:foo).and_return(1)
      ''.foo.should eq(1)
    end
  end
  </code></pre>
  
  <p>How can I include the Mocks module into the Class or Object class?</p>