From 83ca3174885abb8da32071660ade7da2d6129f7f Mon Sep 17 00:00:00 2001 From: William Watson Date: Fri, 27 Apr 2012 20:55:15 -0400 Subject: [PATCH] flush the entire redis database before each example --- spec/counting_redis_spec.rb | 65 +++++++++++++++++++------------------ spec/redis_spec.rb | 5 +++ 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/spec/counting_redis_spec.rb b/spec/counting_redis_spec.rb index fb32af0..2fb035f 100644 --- a/spec/counting_redis_spec.rb +++ b/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 diff --git a/spec/redis_spec.rb b/spec/redis_spec.rb index 5477ecf..f30610b 100644 --- a/spec/redis_spec.rb +++ b/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')