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