Permalink
Browse files

Split mock server #new and #start

  • Loading branch information...
1 parent 6a5da03 commit c6ae34b8e3b6c5ba17837811aad51e0fbf5e3b7c @pietern pietern committed Mar 14, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 test/redis_mock.rb
View
@@ -7,6 +7,9 @@ class Server
def initialize(port, &block)
@server = TCPServer.new("127.0.0.1", port)
@server.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
+ end
+
+ def start(&block)
@thread = Thread.new { run(&block) }
end
@@ -75,8 +78,10 @@ module Helper
# end
#
def redis_mock(replies = {})
+ server = Server.new(MOCK_PORT)
+
begin
- server = Server.new(MOCK_PORT) do |command, *args|
+ server.start do |command, *args|
(replies[command.to_sym] || lambda { |*_| "+OK" }).call(*args)
end

0 comments on commit c6ae34b

Please sign in to comment.