causes/mock_redis — pull request #19 by yankov (2012-06-23 04:12:49+00:00)
Title: Handle mocks for Redis::Distributed

Redis::Distributed is a standard class from redis-rb that allows to create a connection to a cluster of redis instances. It uses consistent hashing algorithm to route writes and reads for each key to an according redis instance.

The connection is created like this: Redis::Distributed.new(redis_urls). The problem is that when you try to stub Redis.new, so that this connection will use MockRedis instead of the Redis, it fails because MockRedis doesn't have 'options' property (as standard redis object has).

This commits resolve this problem. So by creating stubs like that:

Redis.should_receive(:new).any_number_of_times {|options|
MockRedis.new(options)
}

After when you call Redis::Distributed.new(array_of_redis_urls) that will return connection to a "cluster" of redis mocks.