|
43 | 43 | arg = 'an argument' |
44 | 44 | expect(cacheable_object).to receive(cacheable_method_inner).with(arg) |
45 | 45 |
|
46 | | - cacheable_object.send(cacheable_method, arg) |
| 46 | + expect { cacheable_object.send(cacheable_method, arg) }.to output.to_stderr |
47 | 47 | end |
48 | 48 |
|
49 | 49 | it 'creates a method that can skip the cache' do |
|
223 | 223 | .to change { described_class.cache_adapter.exist?(key) }.from(false).to(true) |
224 | 224 | end |
225 | 225 |
|
226 | | - it 'does not use the arguments to the method to determine the cache key' do |
227 | | - args = [1] |
228 | | - expect(cacheable_object.cacheable_method_key_format(*args)).to eq([cacheable_method]) |
| 226 | + it 'does not use positional arguments in the cache key and warns' do |
| 227 | + cache_key = nil |
| 228 | + expect { cache_key = cacheable_object.cacheable_method_key_format(1) } |
| 229 | + .to output(/default key format.*arguments are NOT included/i).to_stderr |
| 230 | + expect(cache_key).to eq([cacheable_method]) |
| 231 | + end |
| 232 | + |
| 233 | + it 'does not use keyword arguments in the cache key and warns' do |
| 234 | + cache_key = nil |
| 235 | + expect { cache_key = cacheable_object.cacheable_method_key_format(foo: 1) } |
| 236 | + .to output(/default key format.*arguments are NOT included/i).to_stderr |
| 237 | + expect(cache_key).to eq([cacheable_method]) |
| 238 | + end |
| 239 | + |
| 240 | + it 'only warns once per method' do |
| 241 | + expect { cacheable_object.cacheable_method_key_format(1) } |
| 242 | + .to output(/default key format/i).to_stderr |
| 243 | + expect { cacheable_object.cacheable_method_key_format(2) }.not_to output.to_stderr |
| 244 | + end |
| 245 | + |
| 246 | + it 'does not warn when called without arguments' do |
| 247 | + expect { cacheable_object.cacheable_method_key_format }.not_to output.to_stderr |
229 | 248 | end |
230 | 249 |
|
231 | 250 | it 'uses different keys for different cached values' do |
|
244 | 263 | expect(cacheable_object).to receive(inner_method).with(arg1).once.and_call_original |
245 | 264 | expect(cacheable_object).to receive(inner_method).with(arg2).once.and_call_original |
246 | 265 |
|
247 | | - 2.times { expect(cacheable_object.send(cacheable_method, arg1)).to include(arg1) } |
248 | | - 2.times { expect(cacheable_object.send(another_cacheable_method, arg2)).to include(arg2) } |
| 266 | + expect do |
| 267 | + 2.times { expect(cacheable_object.send(cacheable_method, arg1)).to include(arg1) } |
| 268 | + 2.times { expect(cacheable_object.send(another_cacheable_method, arg2)).to include(arg2) } |
| 269 | + end.to output.to_stderr |
249 | 270 | end |
250 | 271 |
|
251 | 272 | it 'uses the value of `cache_key` if the method is defined instead of the class' do |
|
0 commit comments