fakeredis 0.3.2 → 0.3.3

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/spec/spec_helper.rb CHANGED
@@ -2,4 +2,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'fakeredis'
5
+ require "fakeredis/rspec"
5
6
 
7
+ def fakeredis?
8
+ true
9
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ # Remove memory so we test against actual redis
4
+ Redis::Connection.drivers.pop
5
+
6
+ RSpec.configure do |config|
7
+ config.before(:each) do
8
+ Redis.new.flushdb
9
+ end
10
+ end
11
+
12
+ def fakeredis?
13
+ false
14
+ end
data/spec/strings_spec.rb CHANGED
@@ -11,89 +11,121 @@ module FakeRedis
11
11
  @client.set("key1", "Hello")
12
12
  @client.append("key1", " World")
13
13
 
14
- @client.get("key1").should == "Hello World"
14
+ @client.get("key1").should be == "Hello World"
15
15
  end
16
16
 
17
17
  it "should decrement the integer value of a key by one" do
18
18
  @client.set("counter", "1")
19
19
  @client.decr("counter")
20
20
 
21
- @client.get("counter").should == "0"
21
+ @client.get("counter").should be == "0"
22
22
  end
23
23
 
24
24
  it "should decrement the integer value of a key by the given number" do
25
25
  @client.set("counter", "10")
26
26
  @client.decrby("counter", "5")
27
27
 
28
- @client.get("counter").should == "5"
28
+ @client.get("counter").should be == "5"
29
29
  end
30
30
 
31
31
  it "should get the value of a key" do
32
- @client.get("key2").should == nil
32
+ @client.get("key2").should be == nil
33
33
  end
34
34
 
35
35
  it "should returns the bit value at offset in the string value stored at key" do
36
36
  @client.set("key1", "a")
37
37
 
38
- @client.getbit("key1", 1).should == 1
39
- @client.getbit("key1", 2).should == 1
40
- @client.getbit("key1", 3).should == 0
41
- @client.getbit("key1", 4).should == 0
42
- @client.getbit("key1", 5).should == 0
43
- @client.getbit("key1", 6).should == 0
44
- @client.getbit("key1", 7).should == 1
38
+ @client.getbit("key1", 1).should be == 1
39
+ @client.getbit("key1", 2).should be == 1
40
+ @client.getbit("key1", 3).should be == 0
41
+ @client.getbit("key1", 4).should be == 0
42
+ @client.getbit("key1", 5).should be == 0
43
+ @client.getbit("key1", 6).should be == 0
44
+ @client.getbit("key1", 7).should be == 1
45
45
  end
46
46
 
47
47
  it "should allow direct bit manipulation even if the string isn't set" do
48
48
  @client.setbit("key1", 10, 1)
49
- @client.getbit("key1", 10).should == 1
49
+ @client.getbit("key1", 10).should be == 1
50
50
  end
51
51
 
52
52
  it "should get a substring of the string stored at a key" do
53
53
  @client.set("key1", "This a message")
54
54
 
55
- @client.getrange("key1", 0, 3).should == "This"
56
- @client.substr("key1", 0, 3).should == "This"
55
+ @client.getrange("key1", 0, 3).should be == "This"
56
+ @client.substr("key1", 0, 3).should be == "This"
57
57
  end
58
58
 
59
59
  it "should set the string value of a key and return its old value" do
60
60
  @client.set("key1","value1")
61
61
 
62
- @client.getset("key1", "value2").should == "value1"
63
- @client.get("key1").should == "value2"
62
+ @client.getset("key1", "value2").should be == "value1"
63
+ @client.get("key1").should be == "value2"
64
64
  end
65
65
 
66
66
  it "should return nil for #getset if the key does not exist when setting" do
67
- @client.getset("key1", "value1").should == nil
68
- @client.get("key1").should == "value1"
67
+ @client.getset("key1", "value1").should be_nil
68
+ @client.get("key1").should be == "value1"
69
69
  end
70
70
 
71
71
  it "should increment the integer value of a key by one" do
72
72
  @client.set("counter", "1")
73
- @client.incr("counter").should == 2
73
+ @client.incr("counter").should be == 2
74
74
 
75
- @client.get("counter").should == "2"
75
+ @client.get("counter").should be == "2"
76
+ end
77
+
78
+ it "should not change the expire value of the key during incr" do
79
+ @client.set("counter", "1")
80
+ @client.expire("counter", 600).should be_true
81
+ @client.ttl("counter").should be == 600
82
+ @client.incr("counter").should be == 2
83
+ @client.ttl("counter").should be == 600
76
84
  end
77
85
 
78
86
  it "should decrement the integer value of a key by one" do
79
87
  @client.set("counter", "1")
80
- @client.decr("counter").should == 0
88
+ @client.decr("counter").should be == 0
89
+
90
+ @client.get("counter").should be == "0"
91
+ end
81
92
 
82
- @client.get("counter").should == "0"
93
+ it "should not change the expire value of the key during decr" do
94
+ @client.set("counter", "2")
95
+ @client.expire("counter", 600).should be_true
96
+ @client.ttl("counter").should be == 600
97
+ @client.decr("counter").should be == 1
98
+ @client.ttl("counter").should be == 600
83
99
  end
84
100
 
85
101
  it "should increment the integer value of a key by the given number" do
86
102
  @client.set("counter", "10")
87
- @client.incrby("counter", "5").should == 15
88
- @client.incrby("counter", 2).should == 17
89
- @client.get("counter").should == "17"
103
+ @client.incrby("counter", "5").should be == 15
104
+ @client.incrby("counter", 2).should be == 17
105
+ @client.get("counter").should be == "17"
106
+ end
107
+
108
+ it "should not change the expire value of the key during incrby" do
109
+ @client.set("counter", "1")
110
+ @client.expire("counter", 600).should be_true
111
+ @client.ttl("counter").should be == 600
112
+ @client.incrby("counter", "5").should be == 6
113
+ @client.ttl("counter").should be == 600
90
114
  end
91
115
 
92
116
  it "should decrement the integer value of a key by the given number" do
93
117
  @client.set("counter", "10")
94
- @client.decrby("counter", "5").should == 5
95
- @client.decrby("counter", 2).should == 3
96
- @client.get("counter").should == "3"
118
+ @client.decrby("counter", "5").should be == 5
119
+ @client.decrby("counter", 2).should be == 3
120
+ @client.get("counter").should be == "3"
121
+ end
122
+
123
+ it "should not change the expire value of the key during decrby" do
124
+ @client.set("counter", "8")
125
+ @client.expire("counter", 600).should be_true
126
+ @client.ttl("counter").should be == 600
127
+ @client.decrby("counter", "3").should be == 5
128
+ @client.ttl("counter").should be == 600
97
129
  end
98
130
 
99
131
  it "should get the values of all the given keys" do
@@ -101,48 +133,63 @@ module FakeRedis
101
133
  @client.set("key2", "value2")
102
134
  @client.set("key3", "value3")
103
135
 
104
- @client.mget("key1", "key2", "key3").should == ["value1", "value2", "value3"]
136
+ @client.mget("key1", "key2", "key3").should be == ["value1", "value2", "value3"]
105
137
  end
106
138
 
107
- it 'raises an argument error when not passed any fields' do
139
+ it "raises an argument error when not passed any fields" do
108
140
  @client.set("key3", "value3")
109
141
 
110
- lambda { @client.mget }.should raise_error(ArgumentError)
142
+ lambda { @client.mget }.should raise_error(RuntimeError, "ERR wrong number of arguments for 'mget' command")
111
143
  end
112
144
 
113
145
  it "should set multiple keys to multiple values" do
114
146
  @client.mset(:key1, "value1", :key2, "value2")
115
147
 
116
- @client.get("key1").should == "value1"
117
- @client.get("key2").should == "value2"
148
+ @client.get("key1").should be == "value1"
149
+ @client.get("key2").should be == "value2"
118
150
  end
119
151
 
120
152
  it "should set multiple keys to multiple values, only if none of the keys exist" do
121
- @client.msetnx(:key1, "value1", :key2, "value2")
122
- @client.msetnx(:key1, "value3", :key2, "value4")
153
+ @client.msetnx(:key1, "value1", :key2, "value2").should be == 1
154
+ @client.msetnx(:key1, "value3", :key2, "value4").should be == 0
155
+
156
+ @client.get("key1").should be == "value1"
157
+ @client.get("key2").should be == "value2"
158
+ end
159
+
160
+ it "should set multiple keys to multiple values with a hash" do
161
+ @client.mapped_mset(:key1 => "value1", :key2 => "value2")
162
+
163
+ @client.get("key1").should be == "value1"
164
+ @client.get("key2").should be == "value2"
165
+ end
166
+
167
+ it "should set multiple keys to multiple values with a hash, only if none of the keys exist" do
168
+ @client.mapped_msetnx(:key1 => "value1", :key2 => "value2").should be == 1
169
+ @client.mapped_msetnx(:key1 => "value3", :key2 => "value4").should be == 0
123
170
 
124
- @client.get("key1").should == "value1"
125
- @client.get("key2").should == "value2"
171
+ @client.get("key1").should be == "value1"
172
+ @client.get("key2").should be == "value2"
126
173
  end
127
174
 
128
175
  it "should set the string value of a key" do
129
176
  @client.set("key1", "1")
130
177
 
131
- @client.get("key1").should == "1"
178
+ @client.get("key1").should be == "1"
132
179
  end
133
180
 
134
181
  it "should sets or clears the bit at offset in the string value stored at key" do
135
182
  @client.set("key1", "abc")
136
183
  @client.setbit("key1", 11, 1)
137
184
 
138
- @client.get("key1").should == "arc"
185
+ @client.get("key1").should be == "arc"
139
186
  end
140
187
 
141
188
  it "should set the value and expiration of a key" do
142
189
  @client.setex("key1", 30, "value1")
143
190
 
144
- @client.get("key1").should == "value1"
145
- @client.ttl("key1").should == 30
191
+ @client.get("key1").should be == "value1"
192
+ @client.ttl("key1").should be == 30
146
193
  end
147
194
 
148
195
  it "should set the value of a key, only if the key does not exist" do
@@ -150,21 +197,21 @@ module FakeRedis
150
197
  @client.setnx("key1", "new value")
151
198
  @client.setnx("key2", "another value")
152
199
 
153
- @client.get("key1").should == "test value"
154
- @client.get("key2").should == "another value"
200
+ @client.get("key1").should be == "test value"
201
+ @client.get("key2").should be == "another value"
155
202
  end
156
203
 
157
204
  it "should overwrite part of a string at key starting at the specified offset" do
158
205
  @client.set("key1", "Hello World")
159
206
  @client.setrange("key1", 6, "Redis")
160
207
 
161
- @client.get("key1").should == "Hello Redis"
208
+ @client.get("key1").should be == "Hello Redis"
162
209
  end
163
210
 
164
211
  it "should get the length of the value stored in a key" do
165
212
  @client.set("key1", "abc")
166
213
 
167
- @client.strlen("key1").should == 3
214
+ @client.strlen("key1").should be == 3
168
215
  end
169
216
 
170
217
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeredis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-02 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -59,9 +59,14 @@ files:
59
59
  - README.md
60
60
  - Rakefile
61
61
  - fakeredis.gemspec
62
+ - lib/fake_redis.rb
62
63
  - lib/fakeredis.rb
64
+ - lib/fakeredis/expiring_hash.rb
63
65
  - lib/fakeredis/rspec.rb
66
+ - lib/fakeredis/sorted_set_argument_handler.rb
67
+ - lib/fakeredis/sorted_set_store.rb
64
68
  - lib/fakeredis/version.rb
69
+ - lib/fakeredis/zset.rb
65
70
  - lib/redis/connection/memory.rb
66
71
  - spec/compatibility_spec.rb
67
72
  - spec/connection_spec.rb
@@ -72,10 +77,12 @@ files:
72
77
  - spec/sets_spec.rb
73
78
  - spec/sorted_sets_spec.rb
74
79
  - spec/spec_helper.rb
80
+ - spec/spec_helper_live_redis.rb
75
81
  - spec/strings_spec.rb
76
82
  - spec/transactions_spec.rb
77
- homepage: https://github.com/guilleiguaran/fakeredis
78
- licenses: []
83
+ homepage: https://guilleiguaran.github.com/fakeredis
84
+ licenses:
85
+ - MIT
79
86
  post_install_message:
80
87
  rdoc_options: []
81
88
  require_paths:
@@ -93,8 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
100
  - !ruby/object:Gem::Version
94
101
  version: '0'
95
102
  requirements: []
96
- rubyforge_project: fakeredis
97
- rubygems_version: 1.8.24
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.23
98
105
  signing_key:
99
106
  specification_version: 3
100
107
  summary: Fake (In-memory) driver for redis-rb.
@@ -108,6 +115,6 @@ test_files:
108
115
  - spec/sets_spec.rb
109
116
  - spec/sorted_sets_spec.rb
110
117
  - spec/spec_helper.rb
118
+ - spec/spec_helper_live_redis.rb
111
119
  - spec/strings_spec.rb
112
120
  - spec/transactions_spec.rb
113
- has_rdoc: