title: Writing tests with RSpec for Redis with Rails
body: <p>I have a model class that caches data in redis. The first time I call a method on the model, it computes a JSON/Hash value and stores it in Redis. Under certain circumstances I 'flush' that data and it gets recomputed on the next call.</p>
  <p>Here's the code snippet similar to the one I use to store the data in Redis:</p>
  <pre><code>def cache_data
    self.data_values = data_to_cache
    REDIS.set(redis_key,ActiveSupport::JSON.encode(self.data_values))
    REDIS.get(redis_key) 
  end
  
  def data_to_cache
    # generate a hash of values to return
  end
  </code></pre>
  <p>How should I unit test this code? I use RSpec and Capybara. I also use Cucumber and Capabara for integration testing if that helps.</p>