mock_redis 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/lib/mock_redis/set_methods.rb +3 -3
- data/lib/mock_redis/string_methods.rb +8 -0
- data/lib/mock_redis/utility_methods.rb +4 -1
- data/lib/mock_redis/version.rb +1 -1
- data/mock_redis.gemspec +1 -1
- data/spec/commands/hash_operator_spec.rb +21 -0
- data/spec/commands/sdiffstore_spec.rb +8 -1
- data/spec/commands/sinterstore_spec.rb +7 -0
- data/spec/commands/sunionstore_spec.rb +13 -0
- data/spec/commands/zinterstore_spec.rb +8 -0
- data/spec/commands/zunionstore_spec.rb +8 -0
- metadata +22 -18
data/CHANGELOG.md
CHANGED
@@ -22,7 +22,7 @@ class MockRedis
|
|
22
22
|
def sdiffstore(destination, *keys)
|
23
23
|
assert_has_args(keys, 'sdiffstore')
|
24
24
|
with_set_at(destination) do |set|
|
25
|
-
set.
|
25
|
+
set.replace(sdiff(*keys))
|
26
26
|
end
|
27
27
|
scard(destination)
|
28
28
|
end
|
@@ -38,7 +38,7 @@ class MockRedis
|
|
38
38
|
def sinterstore(destination, *keys)
|
39
39
|
assert_has_args(keys, 'sinterstore')
|
40
40
|
with_set_at(destination) do |set|
|
41
|
-
set.
|
41
|
+
set.replace(sinter(*keys))
|
42
42
|
end
|
43
43
|
scard(destination)
|
44
44
|
end
|
@@ -88,7 +88,7 @@ class MockRedis
|
|
88
88
|
def sunionstore(destination, *keys)
|
89
89
|
assert_has_args(keys, 'sunionstore')
|
90
90
|
with_set_at(destination) do |dest_set|
|
91
|
-
dest_set.
|
91
|
+
dest_set.replace(sunion(*keys))
|
92
92
|
end
|
93
93
|
scard(destination)
|
94
94
|
end
|
@@ -24,6 +24,10 @@ class MockRedis
|
|
24
24
|
data[key]
|
25
25
|
end
|
26
26
|
|
27
|
+
def [](key)
|
28
|
+
get(key)
|
29
|
+
end
|
30
|
+
|
27
31
|
def getbit(key, offset)
|
28
32
|
assert_stringy(key)
|
29
33
|
|
@@ -108,6 +112,10 @@ class MockRedis
|
|
108
112
|
'OK'
|
109
113
|
end
|
110
114
|
|
115
|
+
def []=(key, value)
|
116
|
+
set(key, value)
|
117
|
+
end
|
118
|
+
|
111
119
|
def setbit(key, offset, value)
|
112
120
|
assert_stringy(key, "ERR bit is not an integer or out of range")
|
113
121
|
retval = getbit(key, offset)
|
data/lib/mock_redis/version.rb
CHANGED
data/mock_redis.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
s.add_development_dependency "rake", "~> 0.9.2"
|
21
22
|
s.add_development_dependency "redis", "~> 2.2.1"
|
22
23
|
s.add_development_dependency "rspec", "~> 2.6.0"
|
23
|
-
s.add_development_dependency "ZenTest"
|
24
24
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#[](key)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:hash_operator'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns nil for a nonexistent value" do
|
9
|
+
@redises['mock-redis-test:does-not-exist'].should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns a stored string value" do
|
13
|
+
@redises[@key] = 'forsooth'
|
14
|
+
@redises[@key].should == 'forsooth'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "treats integers as strings" do
|
18
|
+
@redises[@key] = 100
|
19
|
+
@redises[@key].should == "100"
|
20
|
+
end
|
21
|
+
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe '#sdiffstore(destination, key [, key, ...])' do
|
4
4
|
before do
|
5
5
|
@numbers = 'mock-redis-test:sdiffstore:numbers'
|
6
|
-
@evens = 'mock-redis-test:sdiffstore:
|
6
|
+
@evens = 'mock-redis-test:sdiffstore:evens'
|
7
7
|
@primes = 'mock-redis-test:sdiffstore:primes'
|
8
8
|
@destination = 'mock-redis-test:sdiffstore:destination'
|
9
9
|
|
@@ -31,6 +31,13 @@ describe '#sdiffstore(destination, key [, key, ...])' do
|
|
31
31
|
@redises.smembers(@destination).should == %w[10 2 4 6 8]
|
32
32
|
end
|
33
33
|
|
34
|
+
it "removes existing elements in destination" do
|
35
|
+
@redises.sadd(@destination, 42)
|
36
|
+
|
37
|
+
@redises.sdiffstore(@destination, @primes)
|
38
|
+
@redises.smembers(@destination).should == %w[2 3 5 7]
|
39
|
+
end
|
40
|
+
|
34
41
|
it "raises an error if given 0 sets" do
|
35
42
|
lambda do
|
36
43
|
@redises.sdiffstore(@destination)
|
@@ -26,6 +26,13 @@ describe '#sinterstore(destination, key [, key, ...])' do
|
|
26
26
|
@redises.get(@destination).should be_nil
|
27
27
|
end
|
28
28
|
|
29
|
+
it "removes existing elements in destination" do
|
30
|
+
@redises.sadd(@destination, 42)
|
31
|
+
|
32
|
+
@redises.sinterstore(@destination, @primes)
|
33
|
+
@redises.smembers(@destination).should == %w[2 3 5 7]
|
34
|
+
end
|
35
|
+
|
29
36
|
it "raises an error if given 0 sets" do
|
30
37
|
lambda do
|
31
38
|
@redises.sinterstore(@destination)
|
@@ -26,6 +26,19 @@ describe '#sunionstore(destination, key [, key, ...])' do
|
|
26
26
|
@redises.get(@destination).should be_nil
|
27
27
|
end
|
28
28
|
|
29
|
+
it "removes existing elements in destination" do
|
30
|
+
@redises.sadd(@destination, 42)
|
31
|
+
|
32
|
+
@redises.sunionstore(@destination, @primes)
|
33
|
+
@redises.smembers(@destination).should == %w[2 3 5 7]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "correctly unions and stores when the destination is empty and is one of the arguments" do
|
37
|
+
@redises.sunionstore(@destination, @destination, @primes)
|
38
|
+
|
39
|
+
@redises.smembers(@destination).should == %w[2 3 5 7]
|
40
|
+
end
|
41
|
+
|
29
42
|
it "raises an error if given 0 sets" do
|
30
43
|
lambda do
|
31
44
|
@redises.sunionstore(@destination)
|
@@ -28,6 +28,14 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
28
28
|
%w[three 6 five 10 seven 14]
|
29
29
|
end
|
30
30
|
|
31
|
+
it "removes existing elements in destination" do
|
32
|
+
@redises.zadd(@dest, 10, 'ten')
|
33
|
+
|
34
|
+
@redises.zinterstore(@dest, [@primes])
|
35
|
+
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
36
|
+
%w[two 2 three 3 five 5 seven 7]
|
37
|
+
end
|
38
|
+
|
31
39
|
it "raises an error if keys is empty" do
|
32
40
|
lambda do
|
33
41
|
@redises.zinterstore(@dest, [])
|
@@ -27,6 +27,14 @@ describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
27
27
|
%w[one 3 three 3 two 4]
|
28
28
|
end
|
29
29
|
|
30
|
+
it "removes existing elements in destination" do
|
31
|
+
@redises.zadd(@dest, 10, 'ten')
|
32
|
+
|
33
|
+
@redises.zunionstore(@dest, [@set1])
|
34
|
+
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
35
|
+
%w[one 1]
|
36
|
+
end
|
37
|
+
|
30
38
|
it "raises an error if keys is empty" do
|
31
39
|
lambda do
|
32
40
|
@redises.zunionstore(@dest, [])
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Samuel Merritt
|
@@ -15,53 +15,55 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-12-16 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: rake
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 63
|
30
30
|
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
31
33
|
- 2
|
32
|
-
|
33
|
-
- 1
|
34
|
-
version: 2.2.1
|
34
|
+
version: 0.9.2
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: redis
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 5
|
46
46
|
segments:
|
47
47
|
- 2
|
48
|
-
-
|
49
|
-
-
|
50
|
-
version: 2.
|
48
|
+
- 2
|
49
|
+
- 1
|
50
|
+
version: 2.2.1
|
51
51
|
type: :development
|
52
52
|
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: rspec
|
55
55
|
prerelease: false
|
56
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
61
|
+
hash: 23
|
62
62
|
segments:
|
63
|
+
- 2
|
64
|
+
- 6
|
63
65
|
- 0
|
64
|
-
version:
|
66
|
+
version: 2.6.0
|
65
67
|
type: :development
|
66
68
|
version_requirements: *id003
|
67
69
|
description: Instantiate one with `redis = MockRedis.new` and treat it like you would a normal Redis object. It supports all the usual Redis operations.
|
@@ -120,6 +122,7 @@ files:
|
|
120
122
|
- spec/commands/getbit_spec.rb
|
121
123
|
- spec/commands/getrange_spec.rb
|
122
124
|
- spec/commands/getset_spec.rb
|
125
|
+
- spec/commands/hash_operator_spec.rb
|
123
126
|
- spec/commands/hdel_spec.rb
|
124
127
|
- spec/commands/hexists_spec.rb
|
125
128
|
- spec/commands/hget_spec.rb
|
@@ -268,6 +271,7 @@ test_files:
|
|
268
271
|
- spec/commands/getbit_spec.rb
|
269
272
|
- spec/commands/getrange_spec.rb
|
270
273
|
- spec/commands/getset_spec.rb
|
274
|
+
- spec/commands/hash_operator_spec.rb
|
271
275
|
- spec/commands/hdel_spec.rb
|
272
276
|
- spec/commands/hexists_spec.rb
|
273
277
|
- spec/commands/hget_spec.rb
|