title: How to spec operations that rely on Memcached?
body: <p>We have a Rails application that we test with RSpec. We want to spec operations that rely on Memcached. What is the best practice to do so? </p>
  
  <p>I thought of doing this by stubbing all calls to <code>Rails.cache</code>. Is this a good idea?</p>
  
  <p>As per @Pan Thomakos suggestion, I'm adding some additional details about one of the scenarios I'm trying to test:</p>
  
  <p>We have the concept of accounts in our system, therefore on every request we retrieve the current user and the current account. Because there are not many accounts in the system, we keep them all in cache and retrieve them from there.</p>
  
  <pre><code>def self.find_by_slug(slug)  
    Rails.cache.fetch(Account.cache_key_for_slug(slug), :expires_in =&gt; 1.day) { super }  
  end
  </code></pre>
  
  <p>For this reason, caching in this case isn't just a nice to have behavior, but the expected behavior and the thing I want to test. Therefore turning off caching won't do.</p>