fakeredis 0.7.0 → 0.8.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.
@@ -243,8 +243,8 @@ module FakeRedis
243
243
  end
244
244
 
245
245
  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")
246
+ expect(@client.setnx("key1", "test value")).to eq(true)
247
+ expect(@client.setnx("key1", "new value")).to eq(false)
248
248
  @client.setnx("key2", "another value")
249
249
 
250
250
  expect(@client.get("key1")).to eq("test value")
@@ -285,5 +285,34 @@ module FakeRedis
285
285
  expect(@client.bitcount("key1", 1, 1)).to eq(6)
286
286
  expect(@client.bitcount("key1", 0, 1)).to eq(10)
287
287
  end
288
+
289
+ describe "#bitpos" do
290
+ it "should return -1 when there's no key" do
291
+ expect(@client.bitpos("key", 0)).to eq(-1)
292
+ end
293
+
294
+ it "should return -1 for empty key" do
295
+ @client.set("key", "")
296
+ expect(@client.bitpos("key", 0)).to eq(-1)
297
+ end
298
+
299
+ it "should return position of the bit in a string" do
300
+ @client.set("key", "foobar") # 01100110 01101111 01101111
301
+ expect(@client.bitpos("key", 1)).to eq(1)
302
+ end
303
+
304
+ it "should return position of the bit correctly with UTF-8 strings" do
305
+ @client.set("key", "判") # 11100101 10001000 10100100
306
+ expect(@client.bitpos("key", 0)).to eq(3)
307
+ end
308
+
309
+ it "should return position of the bit in a string given a range" do
310
+ @client.set("key", "foobar")
311
+
312
+ expect(@client.bitpos("key", 1, 0)).to eq(1)
313
+ expect(@client.bitpos("key", 1, 1, 2)).to eq(9)
314
+ expect(@client.bitpos("key", 0, 1, -1)).to eq(8)
315
+ end
316
+ end
288
317
  end
289
318
  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
@@ -88,5 +88,18 @@ module FakeRedis
88
88
  expect(responses[0]).to eq(true)
89
89
  end
90
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])
102
+ end
103
+ end
91
104
  end
92
105
  end
metadata CHANGED
@@ -1,35 +1,29 @@
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.8.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: 2018-02-04 00:00:00.000000000 Z
11
+ date: 2020-03-04 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.1'
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.1'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rspec
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,12 +53,13 @@ files:
59
53
  - README.md
60
54
  - Rakefile
61
55
  - fakeredis.gemspec
62
- - gemfiles/redisrb-master.gemfile
63
56
  - lib/fake_redis.rb
64
57
  - lib/fakeredis.rb
65
58
  - lib/fakeredis/bitop_command.rb
66
59
  - lib/fakeredis/command_executor.rb
67
60
  - lib/fakeredis/expiring_hash.rb
61
+ - lib/fakeredis/geo_commands.rb
62
+ - lib/fakeredis/geo_set.rb
68
63
  - lib/fakeredis/minitest.rb
69
64
  - lib/fakeredis/rspec.rb
70
65
  - lib/fakeredis/sort_method.rb
@@ -79,7 +74,9 @@ files:
79
74
  - spec/compatibility_spec.rb
80
75
  - spec/connection_spec.rb
81
76
  - spec/fakeredis_spec.rb
77
+ - spec/geo_set_spec.rb
82
78
  - spec/hashes_spec.rb
79
+ - spec/hyper_log_logs_spec.rb
83
80
  - spec/keys_spec.rb
84
81
  - spec/lists_spec.rb
85
82
  - spec/memory_spec.rb
@@ -114,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
111
  - !ruby/object:Gem::Version
115
112
  version: '0'
116
113
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.6.11
114
+ rubygems_version: 3.0.3
119
115
  signing_key:
120
116
  specification_version: 4
121
117
  summary: Fake (In-memory) driver for redis-rb.
@@ -125,7 +121,9 @@ test_files:
125
121
  - spec/compatibility_spec.rb
126
122
  - spec/connection_spec.rb
127
123
  - spec/fakeredis_spec.rb
124
+ - spec/geo_set_spec.rb
128
125
  - spec/hashes_spec.rb
126
+ - spec/hyper_log_logs_spec.rb
129
127
  - spec/keys_spec.rb
130
128
  - spec/lists_spec.rb
131
129
  - spec/memory_spec.rb
@@ -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 => ".."