mock_redis 0.30.0 → 0.33.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: 15bcc9fb58837462df30acd61176547493ce217061459f2c73e134f8ce15c5ab
4
- data.tar.gz: 46df9da818b1b4cdf817a2d8700d6321c182934379974aaa21393bd588b6ab04
3
+ metadata.gz: 764d3b747c037b933788f2d4ef01e581ecb509aa8c3e445d12c27d199d2273fe
4
+ data.tar.gz: 9093a8b7601c57e746dd38d7708c52474df56247ea0910ca4d8d7bcecca9506e
5
5
  SHA512:
6
- metadata.gz: 7322c682d6b702f98afcfd42aac3fe7c6676d63e064d977ddbbfdbaf0f40bca96cd88636e7fd43384dc00455e4421f56555342aabe5707af28ea084587060db9
7
- data.tar.gz: 36fa3abf3f2eef55e305a79ea6010edf90ba561e89b10466942f4f8f587c82cb400d97dae0cd330ff8bb73a494cff5171a8b3ab09485cdf76ae0804e9d1af0bb
6
+ metadata.gz: c7ef20dba317c18d0ab4de7d5d0a87107512cb2398c7d9c549a603a1980fbced844c7b98c547db32fb905a32ed68cdfa25ba9331b03a91512c8c1d1f6d45551a
7
+ data.tar.gz: 29570271c68cf37d7fd09c065cdad79e1ac64e9b1aa3bdb28dbf0d2080983cc758ad4632e13ad132d492dc823afef8dd7a7a9cec14dfbefb6a7e49a840c74c8c
@@ -43,3 +43,21 @@ jobs:
43
43
 
44
44
  - name: Run tests
45
45
  run: bundle exec rspec
46
+
47
+ - name: Code coverage reporting
48
+ uses: coverallsapp/github-action@master
49
+ with:
50
+ github-token: ${{ secrets.github_token }}
51
+ flag-name: ruby${{ matrix.ruby-version }}-${{ matrix.redis-version }}
52
+ parallel: true
53
+
54
+ finish:
55
+ needs: rspec
56
+ runs-on: ubuntu-latest
57
+
58
+ steps:
59
+ - name: Finalize code coverage report
60
+ uses: coverallsapp/github-action@master
61
+ with:
62
+ github-token: ${{ secrets.github_token }}
63
+ parallel-finished: true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.33.0
4
+
5
+ * Add support for `GET` argument to `SET` command
6
+
7
+ ### 0.32.0
8
+
9
+ * Add support for `psetex`
10
+
11
+ ### 0.31.0
12
+
13
+ * Allow `ping` to take argument
14
+ * Raise `CommandError` on `hmget` with empty list of fields
15
+
3
16
  ### 0.30.0
4
17
 
5
18
  * Drop support for Ruby 2.4 and Ruby 2.5 since they are EOL
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ gem 'overcommit', '0.53.0'
9
9
  # Pin tool versions (which are executed by Overcommit) for Travis builds
10
10
  gem 'rubocop', '0.82.0'
11
11
 
12
- gem 'coveralls', require: false
12
+ gem 'simplecov', '~> 0.21.0'
13
+ gem 'simplecov-lcov', '~> 0.8.0'
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # MockRedis
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/mock_redis.svg)](http://badge.fury.io/rb/mock_redis)
4
- [![Build Status](https://travis-ci.org/sds/mock_redis.svg)](https://travis-ci.org/sds/mock_redis)
4
+ ![Build Status](https://github.com/sds/mock_redis/actions/workflows/tests.yml/badge.svg)
5
5
  [![Coverage Status](https://coveralls.io/repos/sds/mock_redis/badge.svg)](https://coveralls.io/r/sds/mock_redis)
6
6
 
7
7
  MockRedis provides the same interface as `redis-rb`, but it stores its
@@ -71,7 +71,7 @@ class MockRedis
71
71
 
72
72
  def del(*keys)
73
73
  keys = keys.flatten.map(&:to_s)
74
- assert_has_args(keys, 'del')
74
+ # assert_has_args(keys, 'del') # no longer errors in redis > v4.5
75
75
 
76
76
  keys.
77
77
  find_all { |key| data[key] }.
@@ -178,8 +178,8 @@ class MockRedis
178
178
  end
179
179
  end
180
180
 
181
- def ping
182
- 'PONG'
181
+ def ping(response = 'PONG')
182
+ response
183
183
  end
184
184
 
185
185
  def quit
@@ -75,8 +75,10 @@ class MockRedis
75
75
  end
76
76
 
77
77
  def hmget(key, *fields)
78
+ fields.flatten!
79
+
78
80
  assert_has_args(fields, 'hmget')
79
- fields.flatten.map { |f| hget(key, f) }
81
+ fields.map { |f| hget(key, f) }
80
82
  end
81
83
 
82
84
  def mapped_hmget(key, *fields)
@@ -206,8 +206,10 @@ class MockRedis
206
206
 
207
207
  # Parameer list required to ensure the ArgumentError is returned correctly
208
208
  # rubocop:disable Metrics/ParameterLists
209
- def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil)
209
+ def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil, get: nil)
210
210
  key = key.to_s
211
+ retval = self.get(key) if get
212
+
211
213
  return_true = false
212
214
  if nx
213
215
  if exists?(key)
@@ -240,7 +242,11 @@ class MockRedis
240
242
  pexpire(key, px)
241
243
  end
242
244
 
243
- return_true ? true : 'OK'
245
+ if get
246
+ retval
247
+ else
248
+ return_true ? true : 'OK'
249
+ end
244
250
  end
245
251
  # rubocop:enable Metrics/ParameterLists
246
252
 
@@ -328,6 +334,16 @@ class MockRedis
328
334
  end
329
335
  end
330
336
 
337
+ def psetex(key, milliseconds, value)
338
+ if milliseconds <= 0
339
+ raise Redis::CommandError, 'ERR invalid expire time in psetex'
340
+ else
341
+ set(key, value)
342
+ pexpire(key, milliseconds)
343
+ 'OK'
344
+ end
345
+ end
346
+
331
347
  def setnx(key, value)
332
348
  if exists?(key)
333
349
  false
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  class MockRedis
5
- VERSION = '0.30.0'
5
+ VERSION = '0.33.0'
6
6
  end
data/mock_redis.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
 
26
26
  s.add_runtime_dependency 'ruby2_keywords'
27
27
 
28
- s.add_development_dependency 'redis', '~> 4.2.0'
28
+ s.add_development_dependency 'redis', '~> 4.5.0'
29
29
  s.add_development_dependency 'rspec', '~> 3.0'
30
30
  s.add_development_dependency 'rspec-its', '~> 1.0'
31
31
  s.add_development_dependency 'timecop', '~> 0.9.1'
@@ -40,7 +40,7 @@ describe '#del(key [, key, ...])' do
40
40
  end
41
41
 
42
42
  it 'raises an error if an empty array is given' do
43
- expect { @redises.del [] }.to raise_error Redis::CommandError
43
+ expect { @redises.del [] }.not_to raise_error Redis::CommandError
44
44
  end
45
45
 
46
46
  it 'removes a stream key' do
@@ -21,7 +21,7 @@ describe '#expire(key, seconds)' do
21
21
 
22
22
  it 'raises an error if seconds is bogus' do
23
23
  lambda do
24
- @redises.expireat(@key, 'a couple minutes or so')
24
+ @redises.expire(@key, 'a couple minutes or so')
25
25
  end.should raise_error(Redis::CommandError)
26
26
  end
27
27
 
@@ -36,5 +36,11 @@ describe '#hmget(key, field [, field, ...])' do
36
36
  end.should raise_error(Redis::CommandError)
37
37
  end
38
38
 
39
+ it 'raises an error if given an empty list of fields' do
40
+ lambda do
41
+ @redises.hmget(@key, [])
42
+ end.should raise_error(Redis::CommandError)
43
+ end
44
+
39
45
  it_should_behave_like 'a hash-only command'
40
46
  end
@@ -30,5 +30,6 @@ describe '#lpop(key)' do
30
30
  @redises.get(@key).should be_nil
31
31
  end
32
32
 
33
+ let(:default_error) { RedisMultiplexer::MismatchedResponse }
33
34
  it_should_behave_like 'a list-only command'
34
35
  end
@@ -21,7 +21,7 @@ describe '#pexpire(key, ms)' do
21
21
 
22
22
  it 'raises an error if ms is bogus' do
23
23
  lambda do
24
- @redises.pexpireat(@key, 'a couple minutes or so')
24
+ @redises.pexpire(@key, 'a couple minutes or so')
25
25
  end.should raise_error(Redis::CommandError)
26
26
  end
27
27
 
@@ -1,7 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe '#ping' do
4
- it "returns 'PONG'" do
4
+ it 'returns "PONG" with no arguments' do
5
5
  @redises.ping.should == 'PONG'
6
6
  end
7
+
8
+ it 'returns the argument' do
9
+ @redises.ping('HELLO').should == 'HELLO'
10
+ end
7
11
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe '#psetex(key, miliseconds, value)' do
4
+ before { @key = 'mock-redis-test:setex' }
5
+
6
+ it "responds with 'OK'" do
7
+ @redises.psetex(@key, 10, 'value').should == 'OK'
8
+ end
9
+
10
+ it 'sets the value' do
11
+ @redises.psetex(@key, 10_000, 'value')
12
+ @redises.get(@key).should == 'value'
13
+ end
14
+
15
+ it 'sets the expiration time' do
16
+ @redises.psetex(@key, 10_000, 'value')
17
+
18
+ # no guarantee these are the same
19
+ @redises.real.ttl(@key).should > 0
20
+ @redises.mock.ttl(@key).should > 0
21
+ end
22
+
23
+ it 'converts time correctly' do
24
+ @redises.psetex(@key, 10_000_000, 'value')
25
+
26
+ @redises.mock.ttl(@key).should > 9_000
27
+ end
28
+
29
+ context 'when expiration time is zero' do
30
+ it 'raises Redis::CommandError' do
31
+ expect do
32
+ @redises.psetex(@key, 0, 'value')
33
+ end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
34
+ end
35
+ end
36
+
37
+ context 'when expiration time is negative' do
38
+ it 'raises Redis::CommandError' do
39
+ expect do
40
+ @redises.psetex(@key, -2, 'value')
41
+ end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
42
+ end
43
+ end
44
+ end
@@ -30,5 +30,6 @@ describe '#rpop(key)' do
30
30
  @redises.get(@key).should be_nil
31
31
  end
32
32
 
33
+ let(:default_error) { RedisMultiplexer::MismatchedResponse }
33
34
  it_should_behave_like 'a list-only command'
34
35
  end
@@ -33,6 +33,21 @@ describe '#set(key, value)' do
33
33
  @redises.set(key, 1, xx: true).should == true
34
34
  end
35
35
 
36
+ it 'accepts GET on a string' do
37
+ @redises.set(key, '1').should == 'OK'
38
+ @redises.set(key, '2', get: true).should == '1'
39
+ @redises.set(key, '3', get: true).should == '2'
40
+ end
41
+
42
+ context 'when set key is not a String' do
43
+ it 'should error with Redis::CommandError' do
44
+ @redises.lpush(key, '1').should == 1
45
+ expect do
46
+ @redises.set(key, '2', get: true)
47
+ end.to raise_error(Redis::CommandError)
48
+ end
49
+ end
50
+
36
51
  it 'sets the ttl to -1' do
37
52
  @redises.set(key, 1)
38
53
  expect(@redises.ttl(key)).to eq(-1)
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,17 @@
1
- if ENV['TRAVIS']
2
- # When running in Travis, report coverage stats to Coveralls.
3
- require 'coveralls'
4
- Coveralls.wear!
5
- else
6
- # Otherwise render coverage information in coverage/index.html and display
7
- # coverage percentage in the console.
8
- require 'simplecov'
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter 'spec/'
4
+
5
+ if ENV['CI']
6
+ require 'simplecov-lcov'
7
+
8
+ SimpleCov::Formatter::LcovFormatter.config do |c|
9
+ c.report_with_single_file = true
10
+ c.single_report_path = 'coverage/lcov.info'
11
+ end
12
+
13
+ formatter SimpleCov::Formatter::LcovFormatter
14
+ end
9
15
  end
10
16
 
11
17
  require 'rspec/its'
@@ -56,7 +62,10 @@ RSpec.configure do |config|
56
62
  # databases mentioned in our tests
57
63
  [1, 0].each do |db|
58
64
  @redises.send_without_checking(:select, db)
59
- @redises.send_without_checking(:keys, 'mock-redis-test:*').each do |key|
65
+ keys = @redises.send_without_checking(:keys, 'mock-redis-test:*')
66
+ next unless keys.is_a?(Enumerable)
67
+
68
+ keys.each do |key|
60
69
  @redises.send_without_checking(:del, key)
61
70
  end
62
71
  end
@@ -8,7 +8,7 @@ shared_examples_for 'does not remove empty strings on error' do
8
8
  @redises.set(key, '')
9
9
  lambda do
10
10
  @redises.send(method, *args)
11
- end.should raise_error(RuntimeError)
11
+ end.should raise_error(defined?(default_error) ? default_error : RuntimeError)
12
12
  @redises.get(key).should == ''
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ shared_examples_for 'a list-only command' do
8
8
  @redises.set(key, 1)
9
9
  lambda do
10
10
  @redises.send(method, *args)
11
- end.should raise_error(RuntimeError)
11
+ end.should raise_error(defined?(default_error) ? default_error : RuntimeError)
12
12
  end
13
13
 
14
14
  it_should_behave_like 'does not remove empty strings on error'
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.30.0
4
+ version: 0.33.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: 2022-02-17 00:00:00.000000000 Z
12
+ date: 2022-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby2_keywords
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 4.2.0
34
+ version: 4.5.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 4.2.0
41
+ version: 4.5.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -211,6 +211,7 @@ files:
211
211
  - spec/commands/pexpireat_spec.rb
212
212
  - spec/commands/ping_spec.rb
213
213
  - spec/commands/pipelined_spec.rb
214
+ - spec/commands/psetex_spec.rb
214
215
  - spec/commands/pttl_spec.rb
215
216
  - spec/commands/quit_spec.rb
216
217
  - spec/commands/randomkey_spec.rb
@@ -397,6 +398,7 @@ test_files:
397
398
  - spec/commands/pexpireat_spec.rb
398
399
  - spec/commands/ping_spec.rb
399
400
  - spec/commands/pipelined_spec.rb
401
+ - spec/commands/psetex_spec.rb
400
402
  - spec/commands/pttl_spec.rb
401
403
  - spec/commands/quit_spec.rb
402
404
  - spec/commands/randomkey_spec.rb