spec/spec_helper.rb in redis-objects-1.2.1 vs spec/spec_helper.rb in redis-objects-1.3.0

- old
+ new

@@ -21,29 +21,38 @@ REDIS_HOST = ENV['REDIS_HOST'] || 'localhost' REDIS_PID = 'redis.pid' # can't be absolute REDIS_DUMP = 'redis.rdb' # can't be absolute REDIS_RUNDIR = File.dirname(__FILE__) -if !(defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby") - describe 'redis-server' do - it "starting redis-server on #{REDIS_HOST}:#{REDIS_PORT}" do - fork_pid = fork do - system "cd #{REDIS_RUNDIR} && (echo port #{REDIS_PORT}; echo logfile /dev/null; echo daemonize yes; echo pidfile #{REDIS_PID}; echo dbfilename #{REDIS_DUMP}; echo databases 32) | #{REDIS_BIN} -" - end - fork_pid.should > 0 - sleep 2 - end +def start_redis + puts "=> Starting redis-server on #{REDIS_HOST}:#{REDIS_PORT}" + fork_pid = fork do + system "cd #{REDIS_RUNDIR} && (echo port #{REDIS_PORT}; " + + "echo logfile /dev/null; echo daemonize yes; " + + "echo pidfile #{REDIS_PID}; echo dbfilename #{REDIS_DUMP}; " + + "echo databases 32) | #{REDIS_BIN} -" end + fork_pid.should > 0 + sleep 2 +end +def kill_redis + pidfile = File.expand_path REDIS_PID, REDIS_RUNDIR + rdbfile = File.expand_path REDIS_DUMP, REDIS_RUNDIR + pid = File.read(pidfile).to_i + puts "=> Killing #{REDIS_BIN} with pid #{pid}" + Process.kill "TERM", pid + Process.kill "KILL", pid + File.unlink pidfile + File.unlink rdbfile if File.exists? rdbfile +end + +# Start redis-server except under JRuby +unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" + start_redis + at_exit do - pidfile = File.expand_path REDIS_PID, REDIS_RUNDIR - rdbfile = File.expand_path REDIS_DUMP, REDIS_RUNDIR - pid = File.read(pidfile).to_i - puts "=> Killing #{REDIS_BIN} with pid #{pid}" - Process.kill "TERM", pid - Process.kill "KILL", pid - File.unlink pidfile - File.unlink rdbfile if File.exists? rdbfile + kill_redis end end def raises_exception(&block) e = nil