fakeredis 0.4.3 → 0.5.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.
@@ -164,6 +164,9 @@ module FakeRedis
164
164
 
165
165
  @client.zrangebyscore("key", 0, 100).should be == ["one", "two", "three"]
166
166
  @client.zrangebyscore("key", 1, 2).should be == ["one", "two"]
167
+ @client.zrangebyscore("key", 1, '(2').should be == ['one']
168
+ @client.zrangebyscore("key", '(1', 2).should be == ['two']
169
+ @client.zrangebyscore("key", '(1', '(2').should be == []
167
170
  @client.zrangebyscore("key", 0, 100, :withscores => true).should be == [["one", 1], ["two", 2], ["three", 3]]
168
171
  @client.zrangebyscore("key", 1, 2, :with_scores => true).should be == [["one", 1], ["two", 2]]
169
172
  @client.zrangebyscore("key", 0, 100, :limit => [0, 1]).should be == ["one"]
@@ -172,6 +175,8 @@ module FakeRedis
172
175
  @client.zrangebyscore("key", '-inf', '+inf').should be == ["one", "two", "three"]
173
176
  @client.zrangebyscore("key", 2, '+inf').should be == ["two", "three"]
174
177
  @client.zrangebyscore("key", '-inf', 2).should be == ['one', "two"]
178
+
179
+ @client.zrangebyscore("badkey", 1, 2).should be == []
175
180
  end
176
181
 
177
182
  it "should return a reversed range of members in a sorted set, by score" do
@@ -333,6 +338,10 @@ module FakeRedis
333
338
  @client.zremrangebyrank("key", 25, -1).should be == 0
334
339
  @client.zcard('key').should be == 3
335
340
  end
341
+
342
+ it "should return 0 if the key didn't exist" do
343
+ @client.zremrangebyrank("key", 0, 1).should be == 0
344
+ end
336
345
  end
337
346
 
338
347
  describe "#zunionstore" do
@@ -4,6 +4,25 @@ require 'rspec'
4
4
  require 'fakeredis'
5
5
  require "fakeredis/rspec"
6
6
 
7
+ require "support/shared_examples/sortable"
8
+
9
+ RSpec.configure do |config|
10
+ # replaces -b -fdoc --color in .rspec
11
+ config.color = true
12
+ config.default_formatter = "doc"
13
+ config.backtrace_exclusion_patterns = []
14
+
15
+ config.mock_with :rspec do |c|
16
+ # TODO: upgrade should syntax to expect syntax
17
+ c.syntax = [:should, :expect]
18
+ end
19
+
20
+ config.expect_with :rspec do |c|
21
+ # TODO: upgrade should syntax to expect syntax
22
+ c.syntax = [:should, :expect]
23
+ end
24
+ end
25
+
7
26
  def fakeredis?
8
27
  true
9
28
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module FakeRedis
@@ -49,6 +51,30 @@ module FakeRedis
49
51
  @client.getbit("key1", 10).should be == 1
50
52
  end
51
53
 
54
+ context 'when a bit is previously set to 0' do
55
+ before { @client.setbit("key1", 10, 0) }
56
+
57
+ it 'setting it to 1 returns 0' do
58
+ expect(@client.setbit("key1", 10, 1)).to eql 0
59
+ end
60
+
61
+ it 'setting it to 0 returns 0' do
62
+ expect(@client.setbit("key1", 10, 0)).to eql 0
63
+ end
64
+ end
65
+
66
+ context 'when a bit is previously set to 1' do
67
+ before { @client.setbit("key1", 10, 1) }
68
+
69
+ it 'setting it to 0 returns 1' do
70
+ expect(@client.setbit("key1", 10, 0)).to eql 1
71
+ end
72
+
73
+ it 'setting it to 1 returns 1' do
74
+ expect(@client.setbit("key1", 10, 1)).to eql 1
75
+ end
76
+ end
77
+
52
78
  it "should get a substring of the string stored at a key" do
53
79
  @client.set("key1", "This a message")
54
80
 
@@ -77,7 +103,7 @@ module FakeRedis
77
103
 
78
104
  it "should not change the expire value of the key during incr" do
79
105
  @client.set("counter", "1")
80
- @client.expire("counter", 600).should be_true
106
+ @client.expire("counter", 600).should be true
81
107
  @client.ttl("counter").should be == 600
82
108
  @client.incr("counter").should be == 2
83
109
  @client.ttl("counter").should be == 600
@@ -92,7 +118,7 @@ module FakeRedis
92
118
 
93
119
  it "should not change the expire value of the key during decr" do
94
120
  @client.set("counter", "2")
95
- @client.expire("counter", 600).should be_true
121
+ @client.expire("counter", 600).should be true
96
122
  @client.ttl("counter").should be == 600
97
123
  @client.decr("counter").should be == 1
98
124
  @client.ttl("counter").should be == 600
@@ -107,7 +133,7 @@ module FakeRedis
107
133
 
108
134
  it "should not change the expire value of the key during incrby" do
109
135
  @client.set("counter", "1")
110
- @client.expire("counter", 600).should be_true
136
+ @client.expire("counter", 600).should be true
111
137
  @client.ttl("counter").should be == 600
112
138
  @client.incrby("counter", "5").should be == 6
113
139
  @client.ttl("counter").should be == 600
@@ -122,7 +148,7 @@ module FakeRedis
122
148
 
123
149
  it "should not change the expire value of the key during decrby" do
124
150
  @client.set("counter", "8")
125
- @client.expire("counter", 600).should be_true
151
+ @client.expire("counter", 600).should be true
126
152
  @client.ttl("counter").should be == 600
127
153
  @client.decrby("counter", "3").should be == 5
128
154
  @client.ttl("counter").should be == 600
@@ -232,5 +258,27 @@ module FakeRedis
232
258
  @client.strlen("key1").should be == 3
233
259
  end
234
260
 
261
+ it "should return 0 bits when there's no key" do
262
+ @client.bitcount("key1").should be == 0
263
+ end
264
+
265
+ it "should count the number of bits of a string" do
266
+ @client.set("key1", "foobar")
267
+ @client.bitcount("key1").should be == 26
268
+ end
269
+
270
+ it "should count correctly with UTF-8 strings" do
271
+ @client.set("key1", '判')
272
+ @client.bitcount("key1").should be == 10
273
+ end
274
+
275
+ it "should count the number of bits of a string given a range" do
276
+ @client.set("key1", "foobar")
277
+
278
+ @client.bitcount("key1", 0, 0).should be == 4
279
+ @client.bitcount("key1", 1, 1).should be == 6
280
+ @client.bitcount("key1", 0, 1).should be == 10
281
+ end
282
+
235
283
  end
236
284
  end
@@ -0,0 +1,69 @@
1
+ shared_examples_for "a sortable" do
2
+ it 'returns empty array on nil' do
3
+ @client.sort(nil).should == []
4
+ end
5
+
6
+ context 'ordering' do
7
+ it 'orders ascending by default' do
8
+ @client.sort(@key).should == ['1', '2']
9
+ end
10
+
11
+ it 'orders by ascending when specified' do
12
+ @client.sort(@key, :order => "ASC").should == ['1', '2']
13
+ end
14
+
15
+ it 'orders by descending when specified' do
16
+ @client.sort(@key, :order => "DESC").should == ['2', '1']
17
+ end
18
+
19
+ it "orders by ascending when alpha is specified" do
20
+ @client.sort(@key, :order => "ALPHA").should == ["1", "2"]
21
+ end
22
+ end
23
+
24
+ context 'projections' do
25
+ it 'projects element when :get is "#"' do
26
+ @client.sort(@key, :get => '#').should == ['1', '2']
27
+ end
28
+
29
+ it 'projects through a key pattern' do
30
+ @client.sort(@key, :get => 'fake-redis-test:values_*').should == ['a', 'b']
31
+ end
32
+
33
+ it 'projects through a key pattern and reflects element' do
34
+ @client.sort(@key, :get => ['#', 'fake-redis-test:values_*']).should == [['1', 'a'], ['2', 'b']]
35
+ end
36
+
37
+ it 'projects through a hash key pattern' do
38
+ @client.sort(@key, :get => 'fake-redis-test:hash_*->key').should == ['x', 'y']
39
+ end
40
+ end
41
+
42
+ context 'weights' do
43
+ it 'weights by projecting through a key pattern' do
44
+ @client.sort(@key, :by => "fake-redis-test:weight_*").should == ['2', '1']
45
+ end
46
+
47
+ it 'weights by projecting through a key pattern and a specific order' do
48
+ @client.sort(@key, :order => "DESC", :by => "fake-redis-test:weight_*").should == ['1', '2']
49
+ end
50
+ end
51
+
52
+ context 'limit' do
53
+ it 'only returns requested window in the enumerable' do
54
+ @client.sort(@key, :limit => [0, 1]).should == ['1']
55
+ end
56
+ end
57
+
58
+ context 'store' do
59
+ it 'stores into another key' do
60
+ @client.sort(@key, :store => "fake-redis-test:some_bucket").should == 2
61
+ @client.lrange("fake-redis-test:some_bucket", 0, -1).should == ['1', '2']
62
+ end
63
+
64
+ it "stores into another key with other options specified" do
65
+ @client.sort(@key, :store => "fake-redis-test:some_bucket", :by => "fake-redis-test:weight_*").should == 2
66
+ @client.lrange("fake-redis-test:some_bucket", 0, -1).should == ['2', '1']
67
+ end
68
+ end
69
+ end
@@ -2,18 +2,83 @@ require 'spec_helper'
2
2
 
3
3
  module FakeRedis
4
4
  describe "TransactionsMethods" do
5
- before(:each) do
5
+ before(:all) do
6
6
  @client = Redis.new
7
7
  end
8
8
 
9
- it "should mark the start of a transaction block" do
10
- transaction = @client.multi do
11
- @client.set("key1", "1")
12
- @client.set("key2", "2")
13
- @client.mget("key1", "key2")
9
+ before(:each) do
10
+ @client.discard rescue nil
11
+ end
12
+
13
+ context '#multi' do
14
+ it "should respond with 'OK'" do
15
+ @client.multi.should == 'OK'
16
+ end
17
+
18
+ it "should forbid nesting" do
19
+ @client.multi
20
+ lambda{@client.multi}.should raise_error(Redis::CommandError)
21
+ end
22
+
23
+ it "should mark the start of a transaction block" do
24
+ transaction = @client.multi do |multi|
25
+ multi.set("key1", "1")
26
+ multi.set("key2", "2")
27
+ multi.expire("key1", 123)
28
+ multi.mget("key1", "key2")
29
+ end
30
+
31
+ transaction.should be == ["OK", "OK", true, ["1", "2"]]
32
+ end
33
+ end
34
+
35
+ context '#discard' do
36
+ it "should responde with 'OK' after #multi" do
37
+ @client.multi
38
+ @client.discard.should == 'OK'
14
39
  end
15
40
 
16
- transaction.should be == ["OK", "OK", ["1", "2"]]
41
+ it "can't be run outside of #multi/#exec" do
42
+ lambda{@client.discard}.should raise_error(Redis::CommandError)
43
+ end
44
+ end
45
+
46
+ context '#exec' do
47
+ it "can't be run outside of #multi" do
48
+ lambda{@client.exec}.should raise_error(Redis::CommandError)
49
+ end
50
+ end
51
+
52
+ context 'saving up commands for later' do
53
+ before(:each) do
54
+ @client.multi
55
+ @string = 'fake-redis-test:string'
56
+ @list = 'fake-redis-test:list'
57
+ end
58
+
59
+ it "makes commands respond with 'QUEUED'" do
60
+ @client.set(@string, 'string').should == 'QUEUED'
61
+ @client.lpush(@list, 'list').should == 'QUEUED'
62
+ end
63
+
64
+ it "gives you the commands' responses when you call #exec" do
65
+ @client.set(@string, 'string')
66
+ @client.lpush(@list, 'list')
67
+ @client.lpush(@list, 'list')
68
+
69
+ @client.exec.should == ['OK', 1, 2]
70
+ end
71
+
72
+ it "does not raise exceptions, but rather puts them in #exec's response" do
73
+ @client.set(@string, 'string')
74
+ @client.lpush(@string, 'oops!')
75
+ @client.lpush(@list, 'list')
76
+
77
+ responses = @client.exec
78
+ responses[0].should == 'OK'
79
+ responses[1].should be_a(RuntimeError)
80
+ responses[2].should == 1
81
+ end
17
82
  end
18
83
  end
19
84
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeredis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Iguaran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-14 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0
33
+ version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0
40
+ version: '3.0'
41
41
  description: Fake (In-memory) driver for redis-rb. Useful for testing environment
42
42
  and machines without Redis.
43
43
  email:
@@ -46,9 +46,8 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
50
- - .rspec
51
- - .travis.yml
49
+ - ".gitignore"
50
+ - ".travis.yml"
52
51
  - Gemfile
53
52
  - LICENSE
54
53
  - README.md
@@ -56,10 +55,13 @@ files:
56
55
  - fakeredis.gemspec
57
56
  - lib/fake_redis.rb
58
57
  - lib/fakeredis.rb
58
+ - lib/fakeredis/command_executor.rb
59
59
  - lib/fakeredis/expiring_hash.rb
60
60
  - lib/fakeredis/rspec.rb
61
+ - lib/fakeredis/sort_method.rb
61
62
  - lib/fakeredis/sorted_set_argument_handler.rb
62
63
  - lib/fakeredis/sorted_set_store.rb
64
+ - lib/fakeredis/transaction_commands.rb
63
65
  - lib/fakeredis/version.rb
64
66
  - lib/fakeredis/zset.rb
65
67
  - lib/redis/connection/memory.rb
@@ -68,12 +70,15 @@ files:
68
70
  - spec/hashes_spec.rb
69
71
  - spec/keys_spec.rb
70
72
  - spec/lists_spec.rb
73
+ - spec/memory_spec.rb
71
74
  - spec/server_spec.rb
72
75
  - spec/sets_spec.rb
76
+ - spec/sort_method_spec.rb
73
77
  - spec/sorted_sets_spec.rb
74
78
  - spec/spec_helper.rb
75
79
  - spec/spec_helper_live_redis.rb
76
80
  - spec/strings_spec.rb
81
+ - spec/support/shared_examples/sortable.rb
77
82
  - spec/transactions_spec.rb
78
83
  - spec/upcase_method_name_spec.rb
79
84
  homepage: https://guilleiguaran.github.com/fakeredis
@@ -86,17 +91,17 @@ require_paths:
86
91
  - lib
87
92
  required_ruby_version: !ruby/object:Gem::Requirement
88
93
  requirements:
89
- - - '>='
94
+ - - ">="
90
95
  - !ruby/object:Gem::Version
91
96
  version: '0'
92
97
  required_rubygems_version: !ruby/object:Gem::Requirement
93
98
  requirements:
94
- - - '>='
99
+ - - ">="
95
100
  - !ruby/object:Gem::Version
96
101
  version: '0'
97
102
  requirements: []
98
103
  rubyforge_project:
99
- rubygems_version: 2.0.14
104
+ rubygems_version: 2.2.0
100
105
  signing_key:
101
106
  specification_version: 4
102
107
  summary: Fake (In-memory) driver for redis-rb.
@@ -106,11 +111,14 @@ test_files:
106
111
  - spec/hashes_spec.rb
107
112
  - spec/keys_spec.rb
108
113
  - spec/lists_spec.rb
114
+ - spec/memory_spec.rb
109
115
  - spec/server_spec.rb
110
116
  - spec/sets_spec.rb
117
+ - spec/sort_method_spec.rb
111
118
  - spec/sorted_sets_spec.rb
112
119
  - spec/spec_helper.rb
113
120
  - spec/spec_helper_live_redis.rb
114
121
  - spec/strings_spec.rb
122
+ - spec/support/shared_examples/sortable.rb
115
123
  - spec/transactions_spec.rb
116
124
  - spec/upcase_method_name_spec.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- -b -fn --color