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.
Here's the code snippet similar to the one I use to store the data in Redis:
def cache_data self.data_values = data_to_cache REDIS.set(redis_key,ActiveSupport::JSON.encode(self.data_values)) REDIS.get(redis_key) enddef data_to_cache # generate a hash of values to returnend
How should I unit test this code? I use RSpec and Capybara. I also use Cucumber and Capabara for integration testing if that helps.