Skip to content

Commit

Permalink
flush the entire redis database before each example
Browse files Browse the repository at this point in the history
  • Loading branch information
William Watson committed Apr 28, 2012
1 parent 59148fa commit 83ca317
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
65 changes: 34 additions & 31 deletions spec/counting_redis_spec.rb
Expand Up @@ -5,47 +5,50 @@
describe CountingRedis do

context "use Redis for storage" do
it "should store data in Redis" do
bf = CountingRedis.new

bf.insert(:abcd)
bf.insert('test')
bf.include?('test').should be_true
bf.key?('test').should be_true

bf.include?('test', 'test2').should be_false
bf.include?('test', 'abcd').should be_true
context "a default CountingRedis instance" do
let(:bf) { CountingRedis.new }

before do
# clear all redis databases
bf.instance_variable_get(:@db).flushall
end

it "should store data in Redis" do
bf.insert(:abcd)
bf.insert('test')
bf.include?('test').should be_true
bf.key?('test').should be_true

bf.include?('test', 'test2').should be_false
bf.include?('test', 'abcd').should be_true
end

it "should delete keys from Redis" do
bf.insert('test')
bf.include?('test').should be_true

bf.delete('test')
bf.include?('test').should be_false
end

it "should output current stats" do
bf.insert('test')
bf.size.should == 4
lambda { bf.stats }.should_not raise_error
end
end

it "should accept a TTL value for a key" do
bf = CountingRedis.new(:ttl => 1)

bf.instance_variable_get(:@db).flushall

bf.insert('test')
bf.include?('test').should be_true

sleep(2)
bf.include?('test').should be_false
end

it "should delete keys from Redis" do
bf = CountingRedis.new

bf.insert('test')
bf.include?('test').should be_true

bf.delete('test')
bf.include?('test').should be_false
end

it "should output current stats" do
bf = CountingRedis.new
bf.clear

bf.insert('test')
bf.size.should == 4
lambda { bf.stats }.should_not raise_error
end

it "should connect to remote redis server" do
lambda { CountingRedis.new }.should_not raise_error
end
Expand Down
5 changes: 5 additions & 0 deletions spec/redis_spec.rb
Expand Up @@ -5,6 +5,11 @@
context "use Redis bitstring for storage" do
let(:bf) { BloomFilter::Redis.new }

before do
# clear all redis databases
bf.instance_variable_get(:@db).flushall
end

it "should store data in Redis" do
bf.insert(:abcd)
bf.insert('test')
Expand Down

0 comments on commit 83ca317

Please sign in to comment.