mock_redis 0.29.0 → 0.31.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: a2607bfdcb34be30d5f98395241f578ca9980f73b1d2f1ac37fa3a1baa736ba1
4
- data.tar.gz: 7b4c15ece6a897bfa29c86512f9364b73b03eed78dc4764e4c542a056ec5c472
3
+ metadata.gz: 2870385004370b0471f3cf495184d8e11f138e0cb13b9bef9bd43ed7ce2b35ff
4
+ data.tar.gz: 75475cf000d2075ad2565440aea2521fa1034248726b5070ff149d9518c00c3a
5
5
  SHA512:
6
- metadata.gz: 28d6b6302b703e48245d3bb0e2511d446c5a58bd3620eabbfa806f1c58835b48ac4f2082961a8e1110fca1b1246cc1b9c06cb590d8e8eb53facb2716e98fec9f
7
- data.tar.gz: 2d749de988854e1bb5ff64e38f596d1f0efa508e2e78ab90980f86d217e791be617851bc0aaa8593a0497c233258256544e95fe86bc50ff784140a6a63b83e9b
6
+ metadata.gz: 6e6f75b19c46fd81ef553dfe1af1f32b2dceb13e4b660835cd58b1760fa8445c09c2ef26bf67cf64adcf87e196de24798333350e0a07ca0fac39939e296659e4
7
+ data.tar.gz: 77c2c5fc3f67f654d402161541b1527c6779859a0ec6e61a5fb6048b7abfcab50728ba2c25617a2adf303b22a23e662a8f2ee7236085db02682e0e8ca690438a
@@ -0,0 +1,31 @@
1
+ name: Lint
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ overcommit:
10
+ timeout-minutes: 10
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1.97.0
18
+ with:
19
+ ruby-version: 2.7
20
+
21
+ - name: Install dependencies
22
+ run: bundle install
23
+
24
+ - name: Prepare environment
25
+ run: |
26
+ git config --local user.email "gh-actions@example.com"
27
+ git config --local user.name "GitHub Actions"
28
+ bundle exec overcommit --sign
29
+
30
+ - name: Run pre-commit checks
31
+ run: bundle exec overcommit --run
@@ -0,0 +1,63 @@
1
+ name: Tests
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ rspec:
10
+ timeout-minutes: 10
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby-version:
16
+ - '2.6'
17
+ - '2.7'
18
+ - '3.0'
19
+ redis-version:
20
+ - '6.2'
21
+
22
+ services:
23
+ redis:
24
+ image: redis:${{ matrix.redis-version }}-alpine
25
+ options: >-
26
+ --health-cmd "redis-cli ping"
27
+ --health-interval 10s
28
+ --health-timeout 5s
29
+ --health-retries 5
30
+ ports:
31
+ - 6379:6379
32
+
33
+ steps:
34
+ - uses: actions/checkout@v2
35
+
36
+ - name: Set up Ruby ${{ matrix.ruby-version }}
37
+ uses: ruby/setup-ruby@v1.97.0
38
+ with:
39
+ ruby-version: ${{ matrix.ruby-version }}
40
+
41
+ - name: Install dependencies
42
+ run: bundle install
43
+
44
+ - name: Run tests
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,15 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.31.0
4
+
5
+ * Allow `ping` to take argument
6
+ * Raise `CommandError` on `hmget` with empty list of fields
7
+
8
+ ### 0.30.0
9
+
10
+ * Drop support for Ruby 2.4 and Ruby 2.5 since they are EOL
11
+ * Fix `expire` to to raise error on invalid integer
12
+
3
13
  ### 0.29.0
4
14
 
5
15
  * Add support for `logger` option ([#211](https://github.com/sds/mock_redis/pull/211))
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
@@ -10,9 +10,9 @@ for use in tests.
10
10
 
11
11
  ## Requirements
12
12
 
13
- * Ruby 2.4+
13
+ Ruby 2.6+
14
14
 
15
- The current implementation is tested against **Redis 6**. Older versions may work, but can also return different results or not support some commands.
15
+ The current implementation is tested against Redis 6.2. Older versions may work, but can also return different results or not support some commands.
16
16
 
17
17
  ## Getting Started
18
18
 
@@ -86,27 +86,27 @@ class MockRedis
86
86
  end
87
87
 
88
88
  def expire(key, seconds)
89
+ assert_valid_integer(seconds)
90
+
89
91
  pexpire(key, seconds.to_i * 1000)
90
92
  end
91
93
 
92
94
  def pexpire(key, ms)
95
+ assert_valid_integer(ms)
96
+
93
97
  now, miliseconds = @base.now
94
98
  now_ms = (now * 1000) + miliseconds
95
99
  pexpireat(key, now_ms + ms.to_i)
96
100
  end
97
101
 
98
102
  def expireat(key, timestamp)
99
- unless looks_like_integer?(timestamp.to_s)
100
- raise Redis::CommandError, 'ERR value is not an integer or out of range'
101
- end
103
+ assert_valid_integer(timestamp)
102
104
 
103
105
  pexpireat(key, timestamp.to_i * 1000)
104
106
  end
105
107
 
106
108
  def pexpireat(key, timestamp_ms)
107
- unless looks_like_integer?(timestamp_ms.to_s)
108
- raise Redis::CommandError, 'ERR value is not an integer or out of range'
109
- end
109
+ assert_valid_integer(timestamp_ms)
110
110
 
111
111
  if exists?(key)
112
112
  timestamp = Rational(timestamp_ms.to_i, 1000)
@@ -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
@@ -280,6 +280,13 @@ class MockRedis
280
280
 
281
281
  private
282
282
 
283
+ def assert_valid_integer(integer)
284
+ unless looks_like_integer?(integer.to_s)
285
+ raise Redis::CommandError, 'ERR value is not an integer or out of range'
286
+ end
287
+ integer
288
+ end
289
+
283
290
  def assert_valid_timeout(timeout)
284
291
  if !looks_like_integer?(timeout.to_s)
285
292
  raise Redis::CommandError, 'ERR timeout is not an integer or out of range'
@@ -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)
@@ -49,15 +49,15 @@ class MockRedis
49
49
  opts = options opts_in, ['count']
50
50
  start_id = MockRedis::Stream::Id.new(start)
51
51
  finish_id = MockRedis::Stream::Id.new(finish, sequence: Float::INFINITY)
52
- if start_id.exclusive
53
- items = members
54
- .select { |m| (start_id < m[0]) && (finish_id >= m[0]) }
55
- .map { |m| [m[0].to_s, m[1]] }
56
- else
57
- items = members
58
- .select { |m| (start_id <= m[0]) && (finish_id >= m[0]) }
59
- .map { |m| [m[0].to_s, m[1]] }
60
- end
52
+ items = if start_id.exclusive
53
+ members
54
+ .select { |m| (start_id < m[0]) && (finish_id >= m[0]) }
55
+ .map { |m| [m[0].to_s, m[1]] }
56
+ else
57
+ members
58
+ .select { |m| (start_id <= m[0]) && (finish_id >= m[0]) }
59
+ .map { |m| [m[0].to_s, m[1]] }
60
+ end
61
61
  items.reverse! if reversed
62
62
  return items.first(opts['count'].to_i) if opts.key?('count')
63
63
  items
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  class MockRedis
5
- VERSION = '0.29.0'
5
+ VERSION = '0.31.0'
6
6
  end
data/lib/mock_redis.rb CHANGED
@@ -167,7 +167,9 @@ class MockRedis
167
167
  t1 = Time.now
168
168
  yield
169
169
  ensure
170
- logger.debug("[MockRedis] call_time=%0.2f ms" % ((Time.now - t1) * 1000)) if t1
170
+ if t1
171
+ logger.debug(format('[MockRedis] call_time=%<time>0.2f ms', time: ((Time.now - t1) * 1000)))
172
+ end
171
173
  end
172
174
  end
173
175
  end
@@ -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
@@ -35,7 +35,7 @@ describe '#hset(key, field)' do
35
35
  end
36
36
 
37
37
  it 'stores fields sent in a hash' do
38
- @redises.hset(@key, {'k1' => 'v1', 'k2' => 'v2'}).should == 2
38
+ @redises.hset(@key, { 'k1' => 'v1', 'k2' => 'v2' }).should == 2
39
39
  end
40
40
 
41
41
  it_should_behave_like 'a hash-only command'
@@ -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
@@ -15,7 +15,7 @@ describe '#xadd("mystream", { f1: "v1", f2: "v2" }, id: "0-0", maxlen: 1000, app
15
15
  it 'returns an id based on the timestamp' do
16
16
  t = Time.now.to_i
17
17
  id = @redises.xadd(@key, { key: 'value' })
18
- expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}\d{3}-0/)
18
+ expect(id).to match(/#{t}\d{3}-0/)
19
19
  end
20
20
 
21
21
  it 'adds data with symbols' do
@@ -87,7 +87,7 @@ describe MockRedis do
87
87
  logger = double('Logger', debug?: true, debug: nil)
88
88
  mock_redis = MockRedis.new(logger: logger)
89
89
  expect(logger).to receive(:debug).with(/command=HMGET args="hash" "key1" "key2"/)
90
- mock_redis.hmget("hash", "key1", "key2")
90
+ mock_redis.hmget('hash', 'key1', 'key2')
91
91
  end
92
92
  end
93
93
  end
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'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  - Samuel Merritt
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-12 00:00:00.000000000 Z
12
+ date: 2022-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby2_keywords
@@ -89,6 +89,8 @@ executables: []
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
+ - ".github/workflows/lint.yml"
93
+ - ".github/workflows/tests.yml"
92
94
  - ".gitignore"
93
95
  - ".mailmap"
94
96
  - ".overcommit.yml"
@@ -96,7 +98,6 @@ files:
96
98
  - ".rubocop.yml"
97
99
  - ".rubocop_todo.yml"
98
100
  - ".simplecov"
99
- - ".travis.yml"
100
101
  - CHANGELOG.md
101
102
  - Gemfile
102
103
  - LICENSE.md
@@ -295,7 +296,7 @@ homepage: https://github.com/sds/mock_redis
295
296
  licenses:
296
297
  - MIT
297
298
  metadata: {}
298
- post_install_message:
299
+ post_install_message:
299
300
  rdoc_options: []
300
301
  require_paths:
301
302
  - lib
@@ -310,8 +311,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
310
311
  - !ruby/object:Gem::Version
311
312
  version: '0'
312
313
  requirements: []
313
- rubygems_version: 3.1.4
314
- signing_key:
314
+ rubygems_version: 3.1.6
315
+ signing_key:
315
316
  specification_version: 4
316
317
  summary: Redis mock that just lives in memory; useful for testing.
317
318
  test_files:
data/.travis.yml DELETED
@@ -1,33 +0,0 @@
1
- language: ruby
2
-
3
- cache: bundler
4
-
5
- addons:
6
- apt:
7
- packages:
8
- - redis-server
9
-
10
- services:
11
- - redis-server
12
-
13
- before_install:
14
- - sudo sed -e 's/^bind.*/bind 127.0.0.1/' /etc/redis/redis.conf > redis.conf
15
- - sudo mv redis.conf /etc/redis
16
- - sudo service redis-server start
17
- - echo PING | nc localhost 6379
18
-
19
- rvm:
20
- - 2.4
21
- - 2.5
22
- - 2.6
23
- - 2.7
24
-
25
- before_script:
26
- - git config --local user.email "travis@travis.ci"
27
- - git config --local user.name "Travis CI"
28
-
29
- script:
30
- - redis-cli --version
31
- - bundle exec rspec
32
- - bundle exec overcommit --sign
33
- - bundle exec overcommit --run