Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created March 17, 2016 09:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Integralist/72d1f0ab5155c1a27d3f to your computer and use it in GitHub Desktop.
Save Integralist/72d1f0ab5155c1a27d3f 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