Skip to content
Browse files

flush the entire redis database before each example

  • Loading branch information...
1 parent 59148fa commit 83ca3174885abb8da32071660ade7da2d6129f7f William Watson committed
Showing with 39 additions and 31 deletions.
  1. +34 −31 spec/counting_redis_spec.rb
  2. +5 −0 spec/redis_spec.rb
View
65 spec/counting_redis_spec.rb
@@ -5,21 +5,43 @@
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
@@ -27,25 +49,6 @@
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
View
5 spec/redis_spec.rb
@@ -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')

0 comments on commit 83ca317

Please sign in to comment.
Something went wrong with that request. Please try again.