Skip to content

Commit

Permalink
Get the build automated, so you that before/after start and stop redis
Browse files Browse the repository at this point in the history
  • Loading branch information
rsanheim committed Sep 17, 2009
1 parent 308c4e3 commit 7cf87ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions spec/redis_spec.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/spec_helper'
require 'redis/raketasks'
require 'logger'

class Foo
Expand All @@ -14,10 +15,16 @@ def ==(other)

describe "redis" do
before(:all) do
result = RedisRunner.start_detached
raise("Could not start redis-server, aborting") unless result

# yea, this sucks, but it seems like sometimes we try to connect too quickly w/o it
sleep 1

# use database 15 for testing so we dont accidentally step on you real data
@r = Redis.new :db => 15
@r = Redis.new :db => 15
end

before(:each) do
@r['foo'] = 'bar'
end
Expand All @@ -27,7 +34,11 @@ def ==(other)
end

after(:all) do
@r.quit
begin
@r.quit
ensure
RedisRunner.stop
end
end

it "should be able connect without a timeout" do
Expand Down
5 changes: 5 additions & 0 deletions tasks/redis.tasks.rb
@@ -1,4 +1,5 @@
# Inspired by rabbitmq.rake the Redbox project at http://github.com/rick/redbox/tree/master
require 'rake'
require 'fileutils'
require 'open-uri'

Expand Down Expand Up @@ -27,6 +28,10 @@ def self.start
exec "dtach -A #{dtach_socket} redis-server #{redisconfdir}"
end

def self.start_detached
system "dtach -n #{dtach_socket} redis-server #{redisconfdir}"
end

def self.attach
exec "dtach -a #{dtach_socket}"
end
Expand Down

0 comments on commit 7cf87ac

Please sign in to comment.