Skip to content

Instantly share code, notes, and snippets.

@3014zhangshuo
Forked from Integralist/Ruby Mock Redis.rb
Created May 10, 2022 01:26
Show Gist options
  • Save 3014zhangshuo/298226cbe29bc3f07dd9c20e343e87b0 to your computer and use it in GitHub Desktop.
Save 3014zhangshuo/298226cbe29bc3f07dd9c20e343e87b0 to your computer and use it in GitHub Desktop.
Ruby Mock Redis
# in your spec helper...
require "pry"
require "redis"
require "mock_redis"
RSpec.configure do |config|
config.before(:each) do
mock_redis = MockRedis.new
allow(Redis).to receive(:new).and_return(mock_redis)
end
end
# Also you can do...
require 'mock_redis'
>> mr = MockRedis.new
>> mr.set('some key', 'some value')
=> "OK"
>> mr.get('some key')
=> "some value"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment