mock_redis 0.28.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dc2b4dd866fe426a0ee5b767bc46668c1ccb515f0b927feeac129b47f28a4a6
4
- data.tar.gz: cccf8ea1f98f9376afadcc57738eef1578bd07166b08bb5a11eb6c3410412f23
3
+ metadata.gz: a2607bfdcb34be30d5f98395241f578ca9980f73b1d2f1ac37fa3a1baa736ba1
4
+ data.tar.gz: 7b4c15ece6a897bfa29c86512f9364b73b03eed78dc4764e4c542a056ec5c472
5
5
  SHA512:
6
- metadata.gz: f8827a5223d959f27d33223904f0cdf705dfa280da700733ea83cb581ddc89ca3e427af39ec247ea05ebb79ecb9fe58ba3e8f2f1b7fd62204aacc65025f010cf
7
- data.tar.gz: e1e3115c5577f1e22249f3c6b9fb3b82ac1be4b8a4967824cbea5f56ce35efec15154d1f9871de5ba3abc337cbe6d38c9d93787150c8e3262ba30b395bcb58b4
6
+ metadata.gz: 28d6b6302b703e48245d3bb0e2511d446c5a58bd3620eabbfa806f1c58835b48ac4f2082961a8e1110fca1b1246cc1b9c06cb590d8e8eb53facb2716e98fec9f
7
+ data.tar.gz: 2d749de988854e1bb5ff64e38f596d1f0efa508e2e78ab90980f86d217e791be617851bc0aaa8593a0497c233258256544e95fe86bc50ff784140a6a63b83e9b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.29.0
4
+
5
+ * Add support for `logger` option ([#211](https://github.com/sds/mock_redis/pull/211))
6
+ * Fix `zadd` to not perform conditional type conversion ([#214](https://github.com/sds/mock_redis/pull/214))
7
+ * Fix `hdel` to raise error when called with empty array ([#215](https://github.com/sds/mock_redis/pull/215))
8
+
3
9
  ### 0.28.0
4
10
 
5
11
  * Fix `hmset` exception ([#206](https://github.com/sds/mock_redis/pull/206))
data/README.md CHANGED
@@ -12,7 +12,7 @@ for use in tests.
12
12
 
13
13
  * Ruby 2.4+
14
14
 
15
- The current implementation is tested against **Redis 5**. Older versions may work, but can also return different results or not support some commands.
15
+ The current implementation is tested against **Redis 6**. Older versions may work, but can also return different results or not support some commands.
16
16
 
17
17
  ## Getting Started
18
18
 
data/lib/mock_redis.rb CHANGED
@@ -22,6 +22,7 @@ class MockRedis
22
22
  :path => nil,
23
23
  :timeout => 5.0,
24
24
  :password => nil,
25
+ :logger => nil,
25
26
  :db => 0,
26
27
  :time_class => Time,
27
28
  }.freeze
@@ -65,6 +66,10 @@ class MockRedis
65
66
  options[:db]
66
67
  end
67
68
 
69
+ def logger
70
+ options[:logger]
71
+ end
72
+
68
73
  def time_at(timestamp)
69
74
  options[:time_class].at(timestamp)
70
75
  end
@@ -86,7 +91,9 @@ class MockRedis
86
91
  end
87
92
 
88
93
  ruby2_keywords def method_missing(method, *args, &block)
89
- @db.send(method, *args, &block)
94
+ logging([[method, *args]]) do
95
+ @db.send(method, *args, &block)
96
+ end
90
97
  end
91
98
 
92
99
  def initialize_copy(source)
@@ -139,4 +146,28 @@ class MockRedis
139
146
 
140
147
  options
141
148
  end
149
+
150
+ def logging(commands)
151
+ return yield unless logger&.debug?
152
+
153
+ begin
154
+ commands.each do |name, *args|
155
+ logged_args = args.map do |a|
156
+ if a.respond_to?(:inspect) then a.inspect
157
+ elsif a.respond_to?(:to_s) then a.to_s
158
+ else
159
+ # handle poorly-behaved descendants of BasicObject
160
+ klass = a.instance_exec { (class << self; self end).superclass }
161
+ "\#<#{klass}:#{a.__id__}>"
162
+ end
163
+ end
164
+ logger.debug("[MockRedis] command=#{name.to_s.upcase} args=#{logged_args.join(' ')}")
165
+ end
166
+
167
+ t1 = Time.now
168
+ yield
169
+ ensure
170
+ logger.debug("[MockRedis] call_time=%0.2f ms" % ((Time.now - t1) * 1000)) if t1
171
+ end
172
+ end
142
173
  end
@@ -10,6 +10,11 @@ class MockRedis
10
10
  with_hash_at(key) do |hash|
11
11
  orig_size = hash.size
12
12
  fields = Array(fields).flatten.map(&:to_s)
13
+
14
+ if fields.empty?
15
+ raise Redis::CommandError, "ERR wrong number of arguments for 'hdel' command"
16
+ end
17
+
13
18
  hash.delete_if { |k, _v| fields.include?(k) }
14
19
  orig_size - hash.size
15
20
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  class MockRedis
5
- VERSION = '0.28.0'
5
+ VERSION = '0.29.0'
6
6
  end
@@ -23,12 +23,7 @@ class MockRedis
23
23
 
24
24
  def add(score, member)
25
25
  members.add(member)
26
- scores[member] =
27
- if score.to_f.to_i == score.to_f
28
- score.to_f.to_i
29
- else
30
- score.to_f
31
- end
26
+ scores[member] = score.to_f
32
27
  self
33
28
  end
34
29
 
@@ -66,5 +66,12 @@ describe '#hdel(key, field)' do
66
66
  @redises.get(@key).should be_nil
67
67
  end
68
68
 
69
+ it 'raises error if an empty array is passed' do
70
+ expect { @redises.hdel(@key, []) }.to raise_error(
71
+ Redis::CommandError,
72
+ "ERR wrong number of arguments for 'hdel' command"
73
+ )
74
+ end
75
+
69
76
  it_should_behave_like 'a hash-only command'
70
77
  end
@@ -23,6 +23,12 @@ describe '#zadd(key, score, member)' do
23
23
  @redises.zrange(@key, 0, -1).should == [member.to_s]
24
24
  end
25
25
 
26
+ it 'allows scores to be set to Float::INFINITY' do
27
+ member = '1'
28
+ @redises.zadd(@key, Float::INFINITY, member)
29
+ @redises.zrange(@key, 0, -1).should == [member]
30
+ end
31
+
26
32
  it 'updates the score' do
27
33
  @redises.zadd(@key, 1, 'foo')
28
34
  @redises.zadd(@key, 2, 'foo')
@@ -81,4 +81,13 @@ describe MockRedis do
81
81
  end
82
82
  end
83
83
  end
84
+
85
+ describe 'supplying a logger' do
86
+ it 'logs redis commands' do
87
+ logger = double('Logger', debug?: true, debug: nil)
88
+ mock_redis = MockRedis.new(logger: logger)
89
+ expect(logger).to receive(:debug).with(/command=HMGET args="hash" "key1" "key2"/)
90
+ mock_redis.hmget("hash", "key1", "key2")
91
+ end
92
+ end
84
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.0
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-01 00:00:00.000000000 Z
12
+ date: 2021-08-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby2_keywords