fakeredis 0.7.0 → 0.9.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/spec/strings_spec.rb CHANGED
@@ -183,6 +183,12 @@ module FakeRedis
183
183
  expect { @client.mget }.to raise_error(Redis::CommandError)
184
184
  end
185
185
 
186
+ it 'raises an argument error when the data is a hash' do
187
+ @client.hincrby("key1", "cont1", 5)
188
+
189
+ expect { @client.mget("key1") }.to raise_error(Redis::CommandError)
190
+ end
191
+
186
192
  it "should set multiple keys to multiple values" do
187
193
  @client.mset(:key1, "value1", :key2, "value2")
188
194
 
@@ -242,9 +248,14 @@ module FakeRedis
242
248
  expect(@client.ttl("key1")).to eq(30)
243
249
  end
244
250
 
251
+ it "should raise an error if a non-integer is provided as the expiration" do
252
+ expect { @client.setex("key1", 1.5, "value1") }.to raise_error(Redis::CommandError)
253
+ expect { @client.set("key1", "value1", ex: 1.5) }.to raise_error(Redis::CommandError)
254
+ end
255
+
245
256
  it "should set the value of a key, only if the key does not exist" do
246
- @client.set("key1", "test value")
247
- @client.setnx("key1", "new value")
257
+ expect(@client.setnx("key1", "test value")).to eq(true)
258
+ expect(@client.setnx("key1", "new value")).to eq(false)
248
259
  @client.setnx("key2", "another value")
249
260
 
250
261
  expect(@client.get("key1")).to eq("test value")
@@ -285,5 +296,34 @@ module FakeRedis
285
296
  expect(@client.bitcount("key1", 1, 1)).to eq(6)
286
297
  expect(@client.bitcount("key1", 0, 1)).to eq(10)
287
298
  end
299
+
300
+ describe "#bitpos" do
301
+ it "should return -1 when there's no key" do
302
+ expect(@client.bitpos("key", 0)).to eq(-1)
303
+ end
304
+
305
+ it "should return -1 for empty key" do
306
+ @client.set("key", "")
307
+ expect(@client.bitpos("key", 0)).to eq(-1)
308
+ end
309
+
310
+ it "should return position of the bit in a string" do
311
+ @client.set("key", "foobar") # 01100110 01101111 01101111
312
+ expect(@client.bitpos("key", 1)).to eq(1)
313
+ end
314
+
315
+ it "should return position of the bit correctly with UTF-8 strings" do
316
+ @client.set("key", "判") # 11100101 10001000 10100100
317
+ expect(@client.bitpos("key", 0)).to eq(3)
318
+ end
319
+
320
+ it "should return position of the bit in a string given a range" do
321
+ @client.set("key", "foobar")
322
+
323
+ expect(@client.bitpos("key", 1, 0)).to eq(1)
324
+ expect(@client.bitpos("key", 1, 1, 2)).to eq(9)
325
+ expect(@client.bitpos("key", 0, 1, -1)).to eq(8)
326
+ end
327
+ end
288
328
  end
289
329
  end
@@ -6,50 +6,50 @@ module FakeRedis
6
6
  before(:each) do
7
7
  @client = Redis.new
8
8
  end
9
-
9
+
10
10
  context "publish" do
11
11
  it "should add to channels" do
12
- @client.publish("channel1", "val1").should be == 0
13
- @client.publish("channel1", "val2").should be == 0
12
+ expect(@client.publish("channel1", "val1")).to eq(0)
13
+ expect(@client.publish("channel1", "val2")).to eq(0)
14
14
  end
15
15
  end
16
-
16
+
17
17
  context "subscribe" do
18
18
  it "should get all messages from a channel" do
19
19
  @client.publish("channel1", "val1")
20
20
  @client.publish("channel1", "val2")
21
21
  @client.publish("channel2", "val3")
22
-
22
+
23
23
  msgs = []
24
24
  subscribe_sent = unsubscribe_sent = false
25
25
  Timeout.timeout(1) do
26
26
  @client.subscribe("channel1") do |on|
27
27
  on.subscribe do |channel|
28
28
  subscribe_sent = true
29
- channel.should be == "channel1"
29
+ expect(channel).to eq("channel1")
30
30
  end
31
-
31
+
32
32
  on.message do |channel,msg|
33
- channel.should be == "channel1"
33
+ expect(channel).to eq("channel1")
34
34
  msgs << msg
35
35
  end
36
-
36
+
37
37
  on.unsubscribe do
38
38
  unsubscribe_sent = true
39
39
  end
40
40
  end
41
41
  end
42
-
43
- msgs.should be == ["val1", "val2"]
44
- subscribe_sent.should
45
- unsubscribe_sent.should
42
+
43
+ expect(msgs).to eq(["val1", "val2"])
44
+ expect(subscribe_sent).to eq(true)
45
+ expect(unsubscribe_sent).to eq(true)
46
46
  end
47
-
47
+
48
48
  it "should get all messages from multiple channels" do
49
49
  @client.publish("channel1", "val1")
50
50
  @client.publish("channel2", "val2")
51
51
  @client.publish("channel2", "val3")
52
-
52
+
53
53
  msgs = []
54
54
  Timeout.timeout(1) do
55
55
  @client.subscribe("channel1", "channel2") do |on|
@@ -58,23 +58,23 @@ module FakeRedis
58
58
  end
59
59
  end
60
60
  end
61
-
62
- msgs[0].should be == ["channel1", "val1"]
63
- msgs[1].should be == ["channel2", "val2"]
64
- msgs[2].should be == ["channel2", "val3"]
61
+
62
+ expect(msgs[0]).to eq(["channel1", "val1"])
63
+ expect(msgs[1]).to eq(["channel2", "val2"])
64
+ expect(msgs[2]).to eq(["channel2", "val3"])
65
65
  end
66
66
  end
67
-
67
+
68
68
  context "unsubscribe" do
69
69
  end
70
-
70
+
71
71
  context "with patterns" do
72
72
  context "psubscribe" do
73
73
  it "should get all messages using pattern" do
74
74
  @client.publish("channel1", "val1")
75
75
  @client.publish("channel1", "val2")
76
76
  @client.publish("channel2", "val3")
77
-
77
+
78
78
  msgs = []
79
79
  subscribe_sent = unsubscribe_sent = false
80
80
  Timeout.timeout(1) do
@@ -82,26 +82,26 @@ module FakeRedis
82
82
  on.psubscribe do |channel|
83
83
  subscribe_sent = true
84
84
  end
85
-
85
+
86
86
  on.pmessage do |pattern,channel,msg|
87
- pattern.should be == "channel*"
87
+ expect(pattern).to eq("channel*")
88
88
  msgs << msg
89
89
  end
90
-
90
+
91
91
  on.punsubscribe do
92
92
  unsubscribe_sent = true
93
93
  end
94
94
  end
95
95
  end
96
-
97
- msgs.should be == ["val1", "val2", "val3"]
98
- subscribe_sent.should
99
- unsubscribe_sent.should
96
+
97
+ expect(msgs).to eq(["val1", "val2", "val3"])
98
+ expect(subscribe_sent).to eq(true)
99
+ expect(unsubscribe_sent).to eq(true)
100
100
  end
101
101
  end
102
-
102
+
103
103
  context "punsubscribe" do
104
104
  end
105
105
  end
106
106
  end
107
- end
107
+ end
@@ -1,11 +1,11 @@
1
1
  shared_examples_for "a bitwise operation" do |operator|
2
2
  it 'raises an argument error when not passed any source keys' do
3
- lambda { @client.bitop(operator, "destkey") }.should raise_error(Redis::CommandError)
3
+ expect { @client.bitop(operator, "destkey") }.to raise_error(Redis::CommandError)
4
4
  end
5
5
 
6
6
  it "should not create destination key if nothing found" do
7
- @client.bitop(operator, "dest1", "nothing_here1").should be == 0
8
- @client.exists("dest1").should be false
7
+ expect(@client.bitop(operator, "dest1", "nothing_here1")).to eq(0)
8
+ expect(@client.exists?("dest1")).to eq(false)
9
9
  end
10
10
 
11
11
  it "should accept operator as a case-insensitive symbol" do
@@ -13,8 +13,8 @@ shared_examples_for "a bitwise operation" do |operator|
13
13
  @client.bitop(operator.to_s.downcase.to_sym, "dest1", "key1")
14
14
  @client.bitop(operator.to_s.upcase.to_sym, "dest2", "key1")
15
15
 
16
- @client.get("dest1").should be == "foobar"
17
- @client.get("dest2").should be == "foobar"
16
+ expect(@client.get("dest1")).to eq("foobar")
17
+ expect(@client.get("dest2")).to eq("foobar")
18
18
  end
19
19
 
20
20
  it "should accept operator as a case-insensitive string" do
@@ -22,30 +22,30 @@ shared_examples_for "a bitwise operation" do |operator|
22
22
  @client.bitop(operator.to_s.downcase, "dest1", "key1")
23
23
  @client.bitop(operator.to_s.upcase, "dest2", "key1")
24
24
 
25
- @client.get("dest1").should be == "foobar"
26
- @client.get("dest2").should be == "foobar"
25
+ expect(@client.get("dest1")).to eq("foobar")
26
+ expect(@client.get("dest2")).to eq("foobar")
27
27
  end
28
28
 
29
29
  it "should copy original string for single key" do
30
30
  @client.set("key1", "foobar")
31
31
  @client.bitop(operator, "dest1", "key1")
32
32
 
33
- @client.get("dest1").should be == "foobar"
33
+ expect(@client.get("dest1")).to eq("foobar")
34
34
  end
35
35
 
36
36
  it "should copy original string for single key" do
37
37
  @client.set("key1", "foobar")
38
38
  @client.bitop(operator, "dest1", "key1")
39
39
 
40
- @client.get("dest1").should be == "foobar"
40
+ expect(@client.get("dest1")).to eq("foobar")
41
41
  end
42
42
 
43
43
  it "should return length of the string stored in the destination key" do
44
44
  @client.set("key1", "foobar")
45
45
  @client.set("key2", "baz")
46
46
 
47
- @client.bitop(operator, "dest1", "key1").should be == 6
48
- @client.bitop(operator, "dest2", "key2").should be == 3
47
+ expect(@client.bitop(operator, "dest1", "key1")).to eq(6)
48
+ expect(@client.bitop(operator, "dest2", "key2")).to eq(3)
49
49
  end
50
50
 
51
51
  it "should overwrite previous value with new one" do
@@ -54,6 +54,6 @@ shared_examples_for "a bitwise operation" do |operator|
54
54
  @client.bitop(operator, "dest1", "key1")
55
55
  @client.bitop(operator, "dest1", "key2")
56
56
 
57
- @client.get("dest1").should be == "baz"
57
+ expect(@client.get("dest1")).to eq("baz")
58
58
  end
59
59
  end
@@ -85,7 +85,20 @@ module FakeRedis
85
85
  it "returns true if the nested hash command succeeds" do
86
86
  responses = @client.multi { |multi| multi.hset('hash', 'key', 'value') }
87
87
 
88
- expect(responses[0]).to eq(true)
88
+ expect(responses[0]).to eq(1)
89
+ end
90
+ end
91
+
92
+ context 'executing set commands in a block' do
93
+ it "returns commands' responses for nested commands" do
94
+ @client.sadd('set', 'member1')
95
+
96
+ responses = @client.multi do |multi|
97
+ multi.sadd('set', 'member1')
98
+ multi.sadd('set', 'member2')
99
+ end
100
+
101
+ expect(responses).to eq([false, true])
89
102
  end
90
103
  end
91
104
  end
metadata CHANGED
@@ -1,49 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeredis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Iguaran
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-04 00:00:00.000000000 Z
11
+ date: 2023-04-15 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
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '3.2'
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '5.0'
19
+ version: '4.8'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '3.2'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '5.0'
26
+ version: '4.8'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rspec
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '3.0'
33
+ version: '3'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '3.0'
40
+ version: '3'
47
41
  description: Fake (In-memory) driver for redis-rb. Useful for testing environment
48
42
  and machines without Redis.
49
43
  email:
@@ -52,19 +46,21 @@ executables: []
52
46
  extensions: []
53
47
  extra_rdoc_files: []
54
48
  files:
49
+ - ".github/workflows/codeql.yml"
50
+ - ".github/workflows/ruby.yml"
55
51
  - ".gitignore"
56
- - ".travis.yml"
57
52
  - Gemfile
58
53
  - LICENSE
59
54
  - README.md
60
55
  - Rakefile
61
56
  - fakeredis.gemspec
62
- - gemfiles/redisrb-master.gemfile
63
57
  - lib/fake_redis.rb
64
58
  - lib/fakeredis.rb
65
59
  - lib/fakeredis/bitop_command.rb
66
60
  - lib/fakeredis/command_executor.rb
67
61
  - lib/fakeredis/expiring_hash.rb
62
+ - lib/fakeredis/geo_commands.rb
63
+ - lib/fakeredis/geo_set.rb
68
64
  - lib/fakeredis/minitest.rb
69
65
  - lib/fakeredis/rspec.rb
70
66
  - lib/fakeredis/sort_method.rb
@@ -79,7 +75,9 @@ files:
79
75
  - spec/compatibility_spec.rb
80
76
  - spec/connection_spec.rb
81
77
  - spec/fakeredis_spec.rb
78
+ - spec/geo_set_spec.rb
82
79
  - spec/hashes_spec.rb
80
+ - spec/hyper_log_logs_spec.rb
83
81
  - spec/keys_spec.rb
84
82
  - spec/lists_spec.rb
85
83
  - spec/memory_spec.rb
@@ -99,7 +97,7 @@ homepage: https://guilleiguaran.github.com/fakeredis
99
97
  licenses:
100
98
  - MIT
101
99
  metadata: {}
102
- post_install_message:
100
+ post_install_message:
103
101
  rdoc_options: []
104
102
  require_paths:
105
103
  - lib
@@ -114,9 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
112
  - !ruby/object:Gem::Version
115
113
  version: '0'
116
114
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.6.11
119
- signing_key:
115
+ rubygems_version: 3.4.1
116
+ signing_key:
120
117
  specification_version: 4
121
118
  summary: Fake (In-memory) driver for redis-rb.
122
119
  test_files:
@@ -125,7 +122,9 @@ test_files:
125
122
  - spec/compatibility_spec.rb
126
123
  - spec/connection_spec.rb
127
124
  - spec/fakeredis_spec.rb
125
+ - spec/geo_set_spec.rb
128
126
  - spec/hashes_spec.rb
127
+ - spec/hyper_log_logs_spec.rb
129
128
  - spec/keys_spec.rb
130
129
  - spec/lists_spec.rb
131
130
  - spec/memory_spec.rb
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- # Use the faster container based infrastructure
4
- # http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/
5
- sudo: false
6
-
7
- rvm:
8
- - 2.2
9
- - 2.3.6
10
- - 2.4
11
- - 2.5
12
- - ruby-head
13
- - jruby
14
- - rbx-2
15
-
16
- gemfile:
17
- - Gemfile
18
- - gemfiles/redisrb-master.gemfile
19
-
20
- matrix:
21
- allow_failures:
22
- - rvm: rbx-2
@@ -1,14 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'rake'
4
- gem 'rdoc'
5
- gem "redis", github: "redis/redis-rb"
6
-
7
- platforms :rbx do
8
- gem 'racc'
9
- gem 'rubysl', '~> 2.0'
10
- gem 'psych'
11
- end
12
-
13
- # Specify your gem's dependencies in fakeredis.gemspec
14
- gemspec :path => ".."