|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require 'spec_helper'
|
| 4 | +require 'redis/multi_connection' |
4 | 5 |
|
5 | 6 | RSpec.shared_examples '#set' do |method_name|
|
6 | 7 | context 'expires_in' do
|
7 | 8 | let(:key) { SecureRandom.uuid }
|
8 | 9 | let(:value) { 'SomeValue' }
|
9 |
| - let(:mock_redis) { instance_double('Redis::MultiConnection') } |
| 10 | + let(:mock_redis) { instance_double('Redis') } |
10 | 11 |
|
11 | 12 | before do
|
12 | 13 | allow(Redis::MultiConnection).to receive(:new).and_return(mock_redis)
|
13 | 14 | end
|
14 | 15 |
|
15 | 16 | it 'will always set a default TTL if one is not provided' do
|
16 |
| - expect_any_instance_of(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
17 |
| - expect_any_instance_of(mock_redis).to receive(:expire).with("test:#{key}", 3_600) |
| 17 | + expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
| 18 | + expect(mock_redis).to receive(:expire).with("test:#{key}", 3_600) |
18 | 19 | subject.public_send(method_name, key, value)
|
19 | 20 | end
|
20 | 21 |
|
21 | 22 | it 'will always set a default TTL if an invalid one is provided' do
|
22 |
| - expect_any_instance_of(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
23 |
| - expect_any_instance_of(mock_redis).to receive(:expire).with("test:#{key}", 3_600) |
| 23 | + expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
| 24 | + expect(mock_redis).to receive(:expire).with("test:#{key}", 3_600) |
24 | 25 | subject.public_send(method_name, key, value, -200)
|
25 | 26 | end
|
26 | 27 |
|
27 | 28 | it 'will always set a default TTL if an invalid one is provided' do
|
28 |
| - expect_any_instance_of(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
29 |
| - expect_any_instance_of(mock_redis).to receive(:expire).with("test:#{key}", 3_600) |
| 29 | + expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
| 30 | + expect(mock_redis).to receive(:expire).with("test:#{key}", 3_600) |
30 | 31 | subject.public_send(method_name, key, value, 0.456)
|
31 | 32 | end
|
32 | 33 |
|
33 | 34 | it 'will always force the TTL to be an integer' do
|
34 |
| - expect_any_instance_of(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
35 |
| - expect_any_instance_of(mock_redis).to receive(:expire).with("test:#{key}", 20) |
| 35 | + expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"") |
| 36 | + expect(mock_redis).to receive(:expire).with("test:#{key}", 20) |
36 | 37 | subject.public_send(method_name, key, value, 20.123)
|
37 | 38 | end
|
38 | 39 | end
|
|
0 commit comments