spec/support/redis_mock.rb
def redis_mock(replies = {})
      begin
        pid = fork do
          trap("TERM") { exit }

          RedisMock.start do |command, *args|
            (replies[command.to_sym] || lambda { |*_| "+OK" }).call(*args)
          end
        end

        sleep 1 # Give time for the socket to start listening.

        yield

      ensure
        if pid
          Process.kill("TERM", pid)
          Process.wait(pid)
        end
      end
    end
def redis_mock(replies = {})
      begin
        pid = fork do
          trap("TERM") { exit }

          RedisMock.start do |command, *args|
            (replies[command.to_sym] || lambda { |*_| "+OK" }).call(*args)
          end
        end

        sleep 1 # Give time for the socket to start listening.

        yield

      ensure
        if pid
          Process.kill("TERM", pid)
          Process.wait(pid)
        end
      end
    end
def redis_mock ( replies = { } ) begin pid = fork do trap ( "TERM" ) { exit } RedisMock . start do | command , * args | ( replies [ command . to_sym ] || lambda { | * _ | "+OK" } ) . call ( args ) end end sleep 1 # Give time for the socket to start listening. yield ensure if pid Process . kill ( "TERM" , pid ) Process . wait ( pid ) end end end
Forks the current process and starts a new mock Redis server on
 port 6380.

 The server will reply with a `+OK` to all commands, but you can
 customize it by providing a hash. For example:

     redis_mock(:ping => lambda { "+PONG" }) do
       assert_equal "PONG", Redis.new(:port => 6380).ping
     end
Forks the current process and starts a new mock Redis server on port 6380 .