Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #15 from billywatson/clear_redis_before_every_test

Clear redis before every test
  • Loading branch information...
commit 846a687ff3a6b1ce87b3cd1475eb707de1210546 2 parents 3cc543a + 83393b3
@igrigorik authored
View
2  .gitignore
@@ -1,6 +1,8 @@
*.o
*.bundle
*.swp
+.rvmrc
+.DS_Store
ext/Makefile
lib/cbloomfilter.so
tmp
View
4 lib/bloomfilter/native.rb
@@ -45,7 +45,7 @@ def set_bits
# Computes the intersection of two Bloom filters.
# It assumes that both filters have the same size -
- # if this is not true +ArgumentError+ is raised.
+ # if this is not true +BloomFilter::ConfigurationMismatch+ is raised.
def &(o)
raise BloomFilter::ConfigurationMismatch.new unless same_parameters?(o)
result = self.class.new
@@ -55,7 +55,7 @@ def &(o)
# Computes the union of two Bloom filters.
# It assumes that both filters have the same size -
- # if this is not true +ArgumentError+ is raised.
+ # if this is not true +BloomFilter::ConfigurationMismatch+ is raised.
def |(o)
raise BloomFilter::ConfigurationMismatch.new unless same_parameters?(o)
result = self.class.new
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
4 spec/native_spec.rb
@@ -23,7 +23,7 @@
end
context "behave like a bloomfilter" do
- it "should test set memerbship" do
+ it "should test set membership" do
bf = Native.new(:size => 100, :hashes => 2, :seed => 1, :bucket => 3, :raise => false)
bf.insert("test")
bf.insert("test1")
@@ -103,7 +103,7 @@
bf2 = Native.new(:size => 20)
bf2.insert("test")
- proc {bf1 | bf2}.should raise_error(ArgumentError)
+ proc {bf1 | bf2}.should raise_error(BloomFilter::ConfigurationMismatch)
end
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')
Please sign in to comment.
Something went wrong with that request. Please try again.