juno 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -4
- data/Gemfile +3 -1
- data/README.md +40 -8
- data/benchmarks/run.rb +17 -5
- data/lib/juno/adapters/activerecord.rb +23 -14
- data/lib/juno/adapters/cassandra.rb +11 -0
- data/lib/juno/adapters/couch.rb +9 -0
- data/lib/juno/adapters/datamapper.rb +10 -0
- data/lib/juno/adapters/dbm.rb +8 -0
- data/lib/juno/adapters/file.rb +2 -0
- data/lib/juno/adapters/fog.rb +9 -0
- data/lib/juno/adapters/gdbm.rb +8 -0
- data/lib/juno/adapters/localmemcache.rb +8 -0
- data/lib/juno/adapters/lruhash.rb +8 -0
- data/lib/juno/adapters/memcached_dalli.rb +9 -0
- data/lib/juno/adapters/memcached_native.rb +10 -0
- data/lib/juno/adapters/memory.rb +2 -0
- data/lib/juno/adapters/mongo.rb +11 -0
- data/lib/juno/adapters/null.rb +2 -0
- data/lib/juno/adapters/pstore.rb +9 -2
- data/lib/juno/adapters/redis.rb +5 -0
- data/lib/juno/adapters/riak.rb +9 -0
- data/lib/juno/adapters/sdbm.rb +8 -0
- data/lib/juno/adapters/sequel.rb +10 -0
- data/lib/juno/adapters/sqlite.rb +9 -0
- data/lib/juno/adapters/tokyocabinet.rb +16 -4
- data/lib/juno/adapters/yaml.rb +2 -0
- data/lib/juno/base.rb +1 -0
- data/lib/juno/builder.rb +2 -0
- data/lib/juno/cache.rb +2 -0
- data/lib/juno/expires.rb +1 -0
- data/lib/juno/lock.rb +37 -0
- data/lib/juno/proxy.rb +1 -0
- data/lib/juno/stack.rb +2 -0
- data/lib/juno/transformer.rb +16 -4
- data/lib/juno/version.rb +3 -1
- data/lib/juno.rb +33 -2
- data/spec/adapter_activerecord_spec.rb +20 -34
- data/spec/adapter_cassandra_spec.rb +9 -23
- data/spec/adapter_couch_spec.rb +9 -23
- data/spec/adapter_datamapper_spec.rb +36 -50
- data/spec/adapter_dbm_spec.rb +9 -23
- data/spec/adapter_file_spec.rb +9 -23
- data/spec/adapter_fog_spec.rb +12 -29
- data/spec/adapter_gdbm_spec.rb +9 -23
- data/spec/adapter_localmemcache_spec.rb +9 -23
- data/spec/adapter_lruhash_spec.rb +24 -38
- data/spec/adapter_memcached_dalli_spec.rb +10 -24
- data/spec/adapter_memcached_native_spec.rb +10 -24
- data/spec/adapter_memcached_spec.rb +10 -24
- data/spec/adapter_memory_spec.rb +24 -38
- data/spec/adapter_mongo_spec.rb +9 -23
- data/spec/adapter_pstore_spec.rb +12 -26
- data/spec/adapter_redis_spec.rb +10 -24
- data/spec/adapter_riak_spec.rb +9 -23
- data/spec/adapter_sdbm_spec.rb +9 -23
- data/spec/adapter_sequel_spec.rb +9 -23
- data/spec/adapter_sqlite_spec.rb +9 -23
- data/spec/adapter_tokyocabinet_bdb_spec.rb +13 -0
- data/spec/adapter_tokyocabinet_hdb_spec.rb +13 -0
- data/spec/adapter_yaml_spec.rb +12 -26
- data/spec/cache_file_memory_spec.rb +22 -43
- data/spec/cache_memory_null_spec.rb +13 -34
- data/spec/expires_file_spec.rb +56 -76
- data/spec/expires_memory_spec.rb +35 -54
- data/spec/generate.rb +147 -160
- data/spec/helper.rb +39 -0
- data/spec/junospecs.rb +612 -610
- data/spec/lock_spec.rb +31 -0
- data/spec/null_adapter_spec.rb +15 -29
- data/spec/proxy_expires_memory_spec.rb +37 -58
- data/spec/proxy_redis_spec.rb +13 -33
- data/spec/simple_activerecord_spec.rb +34 -48
- data/spec/simple_activerecord_with_expires_spec.rb +35 -49
- data/spec/simple_cassandra_spec.rb +35 -49
- data/spec/simple_couch_spec.rb +34 -48
- data/spec/simple_couch_with_expires_spec.rb +35 -49
- data/spec/simple_datamapper_spec.rb +34 -48
- data/spec/simple_datamapper_with_expires_spec.rb +35 -49
- data/spec/simple_datamapper_with_repository_spec.rb +34 -48
- data/spec/simple_dbm_spec.rb +34 -48
- data/spec/simple_dbm_with_expires_spec.rb +35 -49
- data/spec/simple_file_spec.rb +34 -48
- data/spec/simple_file_with_expires_spec.rb +35 -49
- data/spec/simple_fog_spec.rb +37 -54
- data/spec/simple_fog_with_expires_spec.rb +39 -57
- data/spec/simple_gdbm_spec.rb +34 -48
- data/spec/simple_gdbm_with_expires_spec.rb +35 -49
- data/spec/simple_hashfile_spec.rb +34 -48
- data/spec/simple_hashfile_with_expires_spec.rb +35 -49
- data/spec/simple_localmemcache_spec.rb +34 -48
- data/spec/simple_localmemcache_with_expires_spec.rb +35 -49
- data/spec/simple_lruhash_spec.rb +34 -48
- data/spec/simple_lruhash_with_expires_spec.rb +35 -49
- data/spec/simple_memcached_dalli_spec.rb +35 -49
- data/spec/simple_memcached_native_spec.rb +35 -49
- data/spec/simple_memcached_spec.rb +35 -49
- data/spec/simple_memory_spec.rb +34 -48
- data/spec/simple_memory_with_expires_spec.rb +35 -49
- data/spec/simple_mongo_spec.rb +34 -48
- data/spec/simple_mongo_with_expires_spec.rb +35 -49
- data/spec/simple_null_spec.rb +25 -39
- data/spec/simple_pstore_spec.rb +34 -48
- data/spec/simple_pstore_with_expires_spec.rb +35 -49
- data/spec/simple_redis_spec.rb +35 -49
- data/spec/simple_riak_spec.rb +34 -48
- data/spec/simple_riak_with_expires_spec.rb +35 -49
- data/spec/simple_sdbm_spec.rb +34 -48
- data/spec/simple_sdbm_with_expires_spec.rb +35 -49
- data/spec/simple_sequel_spec.rb +34 -48
- data/spec/simple_sequel_with_expires_spec.rb +35 -49
- data/spec/simple_sqlite_spec.rb +34 -48
- data/spec/simple_sqlite_with_expires_spec.rb +35 -49
- data/spec/simple_tokyocabinet_spec.rb +34 -48
- data/spec/simple_tokyocabinet_with_expires_spec.rb +35 -49
- data/spec/simple_yaml_spec.rb +34 -48
- data/spec/simple_yaml_with_expires_spec.rb +35 -49
- data/spec/stack_file_memory_spec.rb +15 -38
- data/spec/stack_memory_file_spec.rb +14 -37
- data/spec/transformer_bson_spec.rb +20 -39
- data/spec/transformer_compress_spec.rb +17 -36
- data/spec/transformer_json_spec.rb +20 -39
- data/spec/transformer_marshal_base64_spec.rb +36 -55
- data/spec/transformer_marshal_escape_spec.rb +36 -55
- data/spec/transformer_marshal_md5_spec.rb +36 -55
- data/spec/transformer_marshal_md5_spread_spec.rb +36 -55
- data/spec/transformer_msgpack_spec.rb +20 -39
- data/spec/transformer_ox_spec.rb +40 -0
- data/spec/transformer_yaml_spec.rb +35 -54
- metadata +11 -6
- data/spec/adapter_tokyocabinet_spec.rb +0 -27
- data/spec/simpl_memory_with_expires_spec.rb +0 -53
data/spec/generate.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
ADAPTER_SPECS = [:null_stringkey_stringvalue, :store_stringkey_stringvalue, :returndifferent_stringkey_stringvalue]
|
2
2
|
SIMPLE_SPECS = [:null, :store, :returndifferent, :marshallable_key]
|
3
3
|
EXPIRES_SPECS = SIMPLE_SPECS + [:expires_stringkey_stringvalue]
|
4
|
+
header = "# Generated by #{__FILE__} at #{Time.now.to_s}, #{`git describe --all --long`}"
|
4
5
|
|
5
6
|
TESTS = {
|
6
7
|
'simple_memory' => {
|
@@ -120,17 +121,17 @@ TESTS = {
|
|
120
121
|
'simple_memcached' => {
|
121
122
|
:store => :Memcached,
|
122
123
|
:specs => EXPIRES_SPECS,
|
123
|
-
:options => ':
|
124
|
+
:options => ':namespace => "simple_memcached"'
|
124
125
|
},
|
125
126
|
'simple_memcached_dalli' => {
|
126
127
|
:store => :MemcachedDalli,
|
127
128
|
:specs => EXPIRES_SPECS,
|
128
|
-
:options => ':
|
129
|
+
:options => ':namespace => "simple_memcached_dalli"'
|
129
130
|
},
|
130
131
|
'simple_memcached_native' => {
|
131
132
|
:store => :MemcachedNative,
|
132
133
|
:specs => EXPIRES_SPECS,
|
133
|
-
:options => ':
|
134
|
+
:options => ':namespace => "simple_memcached_native"'
|
134
135
|
},
|
135
136
|
'simple_riak' => {
|
136
137
|
:store => :Riak,
|
@@ -229,16 +230,14 @@ TESTS = {
|
|
229
230
|
:specs => EXPIRES_SPECS
|
230
231
|
},
|
231
232
|
'expires_memory' => {
|
232
|
-
:build => %{
|
233
|
-
Juno.build do
|
233
|
+
:build => %{Juno.build do
|
234
234
|
use :Expires
|
235
235
|
adapter :Memory
|
236
236
|
end},
|
237
237
|
:specs => [:null, :store, :expires]
|
238
238
|
},
|
239
239
|
'expires_file' => {
|
240
|
-
:build => %{
|
241
|
-
Juno.build do
|
240
|
+
:build => %{Juno.build do
|
242
241
|
use :Expires
|
243
242
|
use :Transformer, :key => [:marshal, :escape], :value => :marshal
|
244
243
|
adapter :File, :dir => File.join(make_tempdir, "expires-file")
|
@@ -246,20 +245,19 @@ end},
|
|
246
245
|
:specs => [:null, :store, :expires, :returndifferent, :marshallable_key],
|
247
246
|
:tests => %{
|
248
247
|
it 'should delete expired value in underlying file storage' do
|
249
|
-
|
250
|
-
|
248
|
+
store.store('foo', 'bar', :expires => 2)
|
249
|
+
store['foo'].should == 'bar'
|
251
250
|
sleep 1
|
252
|
-
|
251
|
+
store['foo'].should == 'bar'
|
253
252
|
sleep 2
|
254
|
-
|
255
|
-
|
256
|
-
|
253
|
+
store['foo'].should == nil
|
254
|
+
store.adapter['foo'].should == nil
|
255
|
+
store.adapter.adapter['foo'].should == nil
|
257
256
|
end
|
258
257
|
}
|
259
258
|
},
|
260
259
|
'proxy_redis' => {
|
261
|
-
:build => %{
|
262
|
-
Juno.build do
|
260
|
+
:build => %{Juno.build do
|
263
261
|
use :Proxy
|
264
262
|
use :Proxy
|
265
263
|
adapter :Redis
|
@@ -267,8 +265,7 @@ end},
|
|
267
265
|
:specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
|
268
266
|
},
|
269
267
|
'proxy_expires_memory' => {
|
270
|
-
:build => %{
|
271
|
-
Juno.build do
|
268
|
+
:build => %{Juno.build do
|
272
269
|
use :Proxy
|
273
270
|
use :Expires
|
274
271
|
use :Proxy
|
@@ -277,8 +274,7 @@ end},
|
|
277
274
|
:specs => [:null, :store, :expires]
|
278
275
|
},
|
279
276
|
'cache_file_memory' => {
|
280
|
-
:build => %{
|
281
|
-
Juno.build do
|
277
|
+
:build => %{Juno.build do
|
282
278
|
use(:Cache) do
|
283
279
|
backend { adapter :File, :dir => File.join(make_tempdir, "cache_file_memory") }
|
284
280
|
cache { adapter :Memory }
|
@@ -287,20 +283,19 @@ end},
|
|
287
283
|
:specs => ADAPTER_SPECS,
|
288
284
|
:tests => %{
|
289
285
|
it 'should store loaded values in cache' do
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
286
|
+
store.backend['foo'] = 'bar'
|
287
|
+
store.cache['foo'].should == nil
|
288
|
+
store['foo'].should == 'bar'
|
289
|
+
store.cache['foo'].should == 'bar'
|
290
|
+
store.backend.delete('foo')
|
291
|
+
store['foo'].should == 'bar'
|
292
|
+
store.delete('foo')
|
293
|
+
store['foo'].should == nil
|
298
294
|
end
|
299
295
|
}
|
300
296
|
},
|
301
297
|
'cache_memory_null' => {
|
302
|
-
:build => %{
|
303
|
-
Juno.build do
|
298
|
+
:build => %{Juno.build do
|
304
299
|
use(:Cache) do
|
305
300
|
backend(Juno::Adapters::Memory.new)
|
306
301
|
cache(Juno::Adapters::Null.new)
|
@@ -309,8 +304,7 @@ end},
|
|
309
304
|
:specs => ADAPTER_SPECS
|
310
305
|
},
|
311
306
|
'stack_file_memory' => {
|
312
|
-
:build => %{
|
313
|
-
Juno.build do
|
307
|
+
:build => %{Juno.build do
|
314
308
|
use(:Stack) do
|
315
309
|
add(Juno.new(:Null))
|
316
310
|
add(Juno::Adapters::Null.new)
|
@@ -321,8 +315,7 @@ end},
|
|
321
315
|
:specs => ADAPTER_SPECS
|
322
316
|
},
|
323
317
|
'stack_memory_file' => {
|
324
|
-
:build => %{
|
325
|
-
Juno.build do
|
318
|
+
:build => %{Juno.build do
|
326
319
|
use(:Stack) do
|
327
320
|
add(Juno.new(:Null))
|
328
321
|
add(Juno::Adapters::Null.new)
|
@@ -332,9 +325,15 @@ Juno.build do
|
|
332
325
|
end},
|
333
326
|
:specs => [:null_stringkey_stringvalue, :store_stringkey_stringvalue]
|
334
327
|
},
|
328
|
+
'lock' => {
|
329
|
+
:build => %{Juno.build do
|
330
|
+
use :Lock
|
331
|
+
adapter :Memory
|
332
|
+
end},
|
333
|
+
:specs => [:null, :store]
|
334
|
+
},
|
335
335
|
'transformer_compress' => {
|
336
|
-
:build => %{
|
337
|
-
Juno.build do
|
336
|
+
:build => %{Juno.build do
|
338
337
|
use :Transformer, :value => :compress
|
339
338
|
adapter :Memory
|
340
339
|
end},
|
@@ -342,8 +341,7 @@ end},
|
|
342
341
|
:specs => [:null, :store, :returndifferent]
|
343
342
|
},
|
344
343
|
'transformer_json' => {
|
345
|
-
:build => %{
|
346
|
-
Juno.build do
|
344
|
+
:build => %{Juno.build do
|
347
345
|
use :Transformer, :key => :json, :value => :json
|
348
346
|
adapter :Memory
|
349
347
|
end},
|
@@ -352,8 +350,7 @@ end},
|
|
352
350
|
:specs => [:null, :store, :returndifferent]
|
353
351
|
},
|
354
352
|
'transformer_bson' => {
|
355
|
-
:build => %{
|
356
|
-
Juno.build do
|
353
|
+
:build => %{Juno.build do
|
357
354
|
use :Transformer, :key => :bson, :value => :bson
|
358
355
|
adapter :Memory
|
359
356
|
end},
|
@@ -361,9 +358,15 @@ end},
|
|
361
358
|
:value => %w(Hash String),
|
362
359
|
:specs => [:null, :store, :returndifferent]
|
363
360
|
},
|
361
|
+
'transformer_ox' => {
|
362
|
+
:build => %{Juno.build do
|
363
|
+
use :Transformer, :key => :ox, :value => :ox
|
364
|
+
adapter :Memory
|
365
|
+
end},
|
366
|
+
:specs => [:null, :store, :returndifferent]
|
367
|
+
},
|
364
368
|
# 'transformer_tnet' => {
|
365
|
-
# :build => %{
|
366
|
-
#Juno.build do
|
369
|
+
# :build => %{Juno.build do
|
367
370
|
# use :Transformer, :key => :tnet, :value => :tnet
|
368
371
|
# adapter :Memory
|
369
372
|
#end},
|
@@ -372,8 +375,7 @@ end},
|
|
372
375
|
# :specs => [:null, :store, :returndifferent]
|
373
376
|
# },
|
374
377
|
'transformer_msgpack' => {
|
375
|
-
:build => %{
|
376
|
-
Juno.build do
|
378
|
+
:build => %{Juno.build do
|
377
379
|
use :Transformer, :key => :msgpack, :value => :msgpack
|
378
380
|
adapter :Memory
|
379
381
|
end},
|
@@ -382,40 +384,35 @@ end},
|
|
382
384
|
:specs => [:null, :store, :returndifferent]
|
383
385
|
},
|
384
386
|
'transformer_yaml' => {
|
385
|
-
:build => %{
|
386
|
-
Juno.build do
|
387
|
+
:build => %{Juno.build do
|
387
388
|
use :Transformer, :key => :yaml, :value => :yaml
|
388
389
|
adapter :Memory
|
389
390
|
end},
|
390
391
|
:specs => [:null, :store, :returndifferent]
|
391
392
|
},
|
392
393
|
'transformer_marshal_base64' => {
|
393
|
-
:build => %{
|
394
|
-
Juno.build do
|
394
|
+
:build => %{Juno.build do
|
395
395
|
use :Transformer, :key => [:marshal, :base64], :value => [:marshal, :base64]
|
396
396
|
adapter :Memory
|
397
397
|
end},
|
398
398
|
:specs => [:null, :store, :returndifferent, :marshallable_key]
|
399
399
|
},
|
400
400
|
'transformer_marshal_escape' => {
|
401
|
-
:build => %{
|
402
|
-
Juno.build do
|
401
|
+
:build => %{Juno.build do
|
403
402
|
use :Transformer, :key => [:marshal, :escape], :value => :marshal
|
404
403
|
adapter :Memory
|
405
404
|
end},
|
406
405
|
:specs => [:null, :store, :returndifferent, :marshallable_key]
|
407
406
|
},
|
408
407
|
'transformer_marshal_md5' => {
|
409
|
-
:build => %{
|
410
|
-
Juno.build do
|
408
|
+
:build => %{Juno.build do
|
411
409
|
use :Transformer, :key => [:marshal, :md5], :value => :marshal
|
412
410
|
adapter :Memory
|
413
411
|
end},
|
414
412
|
:specs => [:null, :store, :returndifferent, :marshallable_key]
|
415
413
|
},
|
416
414
|
'transformer_marshal_md5_spread' => {
|
417
|
-
:build => %{
|
418
|
-
Juno.build do
|
415
|
+
:build => %{Juno.build do
|
419
416
|
use :Transformer, :key => [:marshal, :md5, :spread], :value => :marshal
|
420
417
|
adapter :Memory
|
421
418
|
end},
|
@@ -426,9 +423,9 @@ end},
|
|
426
423
|
:specs => ADAPTER_SPECS,
|
427
424
|
:tests => %{
|
428
425
|
it 'updates an existing key/value' do
|
429
|
-
|
430
|
-
|
431
|
-
records =
|
426
|
+
store['foo/bar'] = '1'
|
427
|
+
store['foo/bar'] = '2'
|
428
|
+
records = store.table.find :all, :conditions => { :k => 'foo/bar' }
|
432
429
|
records.count.should == 1
|
433
430
|
end
|
434
431
|
|
@@ -512,15 +509,15 @@ end
|
|
512
509
|
:specs => ADAPTER_SPECS
|
513
510
|
},
|
514
511
|
'adapter_memcached_dalli' => {
|
515
|
-
:build => 'Juno::Adapters::MemcachedDalli.new(:
|
512
|
+
:build => 'Juno::Adapters::MemcachedDalli.new(:namespace => "adapter_memcached_dalli")',
|
516
513
|
:specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
|
517
514
|
},
|
518
515
|
'adapter_memcached_native' => {
|
519
|
-
:build => 'Juno::Adapters::MemcachedNative.new(:
|
516
|
+
:build => 'Juno::Adapters::MemcachedNative.new(:namespace => "adapter_memcached_native")',
|
520
517
|
:specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
|
521
518
|
},
|
522
519
|
'adapter_memcached' => {
|
523
|
-
:build => 'Juno::Adapters::Memcached.new(:
|
520
|
+
:build => 'Juno::Adapters::Memcached.new(:namespace => "adapter_memcached")',
|
524
521
|
:specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
|
525
522
|
},
|
526
523
|
'adapter_memory' => {
|
@@ -564,8 +561,12 @@ end
|
|
564
561
|
:build => 'Juno::Adapters::Sqlite.new(:file => File.join(make_tempdir, "adapter_sqlite"))',
|
565
562
|
:specs => ADAPTER_SPECS
|
566
563
|
},
|
567
|
-
'
|
568
|
-
:build => 'Juno::Adapters::TokyoCabinet.new(:file => File.join(make_tempdir, "
|
564
|
+
'adapter_tokyocabinet_bdb' => {
|
565
|
+
:build => 'Juno::Adapters::TokyoCabinet.new(:file => File.join(make_tempdir, "adapter_tokyocabinet_bdb"), :type => :bdb)',
|
566
|
+
:specs => ADAPTER_SPECS
|
567
|
+
},
|
568
|
+
'adapter_tokyocabinet_hdb' => {
|
569
|
+
:build => 'Juno::Adapters::TokyoCabinet.new(:file => File.join(make_tempdir, "adapter_tokyocabinet_hdb"), :type => :hdb)',
|
569
570
|
:specs => ADAPTER_SPECS
|
570
571
|
},
|
571
572
|
'adapter_yaml' => {
|
@@ -594,163 +595,163 @@ KEYS.each do |key_type, (key1,key2)|
|
|
594
595
|
VALUES.each do |val_type, (val1,val2)|
|
595
596
|
|
596
597
|
code = %{it "reads from keys that are #{key_type}s like a Hash" do
|
597
|
-
|
598
|
-
|
598
|
+
store[#{key1}].should == nil
|
599
|
+
store.load(#{key1}).should == nil
|
599
600
|
end
|
600
601
|
|
601
602
|
it "guarantees that the same #{val_type} value is returned when setting a #{key_type} key" do
|
602
603
|
value = #{val1}
|
603
|
-
(
|
604
|
+
(store[#{key1}] = value).should equal(value)
|
604
605
|
end
|
605
606
|
|
606
607
|
it "returns false from key? if a #{key_type} key is not available" do
|
607
|
-
|
608
|
+
store.key?(#{key1}).should == false
|
608
609
|
end
|
609
610
|
|
610
611
|
it "returns nil from delete if an element for a #{key_type} key does not exist" do
|
611
|
-
|
612
|
+
store.delete(#{key1}).should == nil
|
612
613
|
end
|
613
614
|
|
614
615
|
it "removes all #{key_type} keys from the store with clear" do
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
616
|
+
store[#{key1}] = #{val1}
|
617
|
+
store[#{key2}] = #{val2}
|
618
|
+
store.clear.should equal(store)
|
619
|
+
store.key?(#{key1}).should_not == true
|
620
|
+
store.key?(#{key2}).should_not == true
|
620
621
|
end
|
621
622
|
|
622
623
|
it "fetches a #{key_type} key with a default value with fetch, if the key is not available" do
|
623
|
-
|
624
|
+
store.fetch(#{key1}, #{val1}).should == #{val1}
|
624
625
|
end
|
625
626
|
|
626
627
|
it "fetches a #{key_type} key with a block with fetch, if the key is not available" do
|
627
628
|
key = #{key1}
|
628
629
|
value = #{val1}
|
629
|
-
|
630
|
+
store.fetch(key) do |k|
|
630
631
|
k.should equal(key)
|
631
632
|
value
|
632
633
|
end.should equal(value)
|
633
634
|
end
|
634
635
|
|
635
636
|
it 'should accept options' do
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
637
|
+
store.key?(#{key1}, :option1 => 1).should == false
|
638
|
+
store.load(#{key1}, :option2 => 2).should == nil
|
639
|
+
store.fetch(#{key1}, nil, :option3 => 3).should == nil
|
640
|
+
store.delete(#{key1}, :option4 => 4).should == nil
|
641
|
+
store.clear(:option5 => 5).should equal(store)
|
642
|
+
store.store(#{key1}, #{val1}, :option6 => 6).should == #{val1}
|
642
643
|
end}
|
643
644
|
SPECS["null_#{key_type.downcase}key_#{val_type.downcase}value"] = code
|
644
645
|
|
645
646
|
code = %{it "writes #{val_type} values to keys that are #{key_type}s like a Hash" do
|
646
|
-
|
647
|
-
|
648
|
-
|
647
|
+
store[#{key1}] = #{val1}
|
648
|
+
store[#{key1}].should == #{val1}
|
649
|
+
store.load(#{key1}).should == #{val1}
|
649
650
|
end
|
650
651
|
|
651
652
|
it "returns true from key? if a #{key_type} key is available" do
|
652
|
-
|
653
|
-
|
653
|
+
store[#{key1}] = #{val1}
|
654
|
+
store.key?(#{key1}).should == true
|
654
655
|
end
|
655
656
|
|
656
657
|
it "stores #{val_type} values with #{key_type} keys with #store" do
|
657
658
|
value = #{val1}
|
658
|
-
|
659
|
-
|
660
|
-
|
659
|
+
store.store(#{key1}, value).should equal(value)
|
660
|
+
store[#{key1}].should == #{val1}
|
661
|
+
store.load(#{key1}).should == #{val1}
|
661
662
|
end
|
662
663
|
|
663
664
|
it "removes and returns a #{val_type} element with a #{key_type} key from the backing store via delete if it exists" do
|
664
|
-
|
665
|
-
|
666
|
-
|
665
|
+
store[#{key1}] = #{val1}
|
666
|
+
store.delete(#{key1}).should == #{val1}
|
667
|
+
store.key?(#{key1}).should == false
|
667
668
|
end
|
668
669
|
|
669
670
|
it "overwrites existing #{val_type} values with #{key_type}" do
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
671
|
+
store[#{key1}] = #{val1}
|
672
|
+
store[#{key1}].should == #{val1}
|
673
|
+
store[#{key1}] = #{val2}
|
674
|
+
store[#{key1}].should == #{val2}
|
674
675
|
end
|
675
676
|
|
676
677
|
it "does not run the block if the #{key_type} key is available" do
|
677
|
-
|
678
|
+
store[#{key1}] = #{val1}
|
678
679
|
unaltered = "unaltered"
|
679
|
-
|
680
|
+
store.fetch(#{key1}) { unaltered = "altered" }
|
680
681
|
unaltered.should == "unaltered"
|
681
682
|
end
|
682
683
|
|
683
684
|
it "fetches a #{key_type} key with a default value with fetch, if the key is available" do
|
684
|
-
|
685
|
-
|
685
|
+
store[#{key1}] = #{val1}
|
686
|
+
store.fetch(#{key1}, #{val2}).should == #{val1}
|
686
687
|
end}
|
687
688
|
SPECS["store_#{key_type.downcase}key_#{val_type.downcase}value"] = code
|
688
689
|
|
689
690
|
code = %{it "guarantees that a different #{val_type} value is retrieved from the #{key_type} key" do
|
690
691
|
value = #{val1}
|
691
|
-
|
692
|
-
|
692
|
+
store[#{key1}] = #{val1}
|
693
|
+
store[#{key1}].should_not be_equal(#{val1})
|
693
694
|
end}
|
694
695
|
SPECS["returndifferent_#{key_type.downcase}key_#{val_type.downcase}value"] = code
|
695
696
|
|
696
697
|
code = %{it 'should support expires on store and #[]' do
|
697
|
-
|
698
|
-
|
698
|
+
store.store(#{key1}, #{val1}, :expires => 2)
|
699
|
+
store[#{key1}].should == #{val1}
|
699
700
|
sleep 1
|
700
|
-
|
701
|
+
store[#{key1}].should == #{val1}
|
701
702
|
sleep 2
|
702
|
-
|
703
|
+
store[#{key1}].should == nil
|
703
704
|
end
|
704
705
|
|
705
706
|
it 'should support expires on store and load' do
|
706
|
-
|
707
|
-
|
707
|
+
store.store(#{key1}, #{val1}, :expires => 2)
|
708
|
+
store.load(#{key1}).should == #{val1}
|
708
709
|
sleep 1
|
709
|
-
|
710
|
+
store.load(#{key1}).should == #{val1}
|
710
711
|
sleep 2
|
711
|
-
|
712
|
+
store.load(#{key1}).should == nil
|
712
713
|
end
|
713
714
|
|
714
715
|
it 'should support expires on store and key?' do
|
715
|
-
|
716
|
-
|
716
|
+
store.store(#{key1}, #{val1}, :expires => 2)
|
717
|
+
store.key?(#{key1}).should == true
|
717
718
|
sleep 1
|
718
|
-
|
719
|
+
store.key?(#{key1}).should == true
|
719
720
|
sleep 2
|
720
|
-
|
721
|
+
store.key?(#{key1}).should == false
|
721
722
|
end
|
722
723
|
|
723
724
|
it 'should support updating the expiration time in load' do
|
724
|
-
|
725
|
-
|
725
|
+
store.store(#{key2}, #{val2}, :expires => 2)
|
726
|
+
store[#{key2}].should == #{val2}
|
726
727
|
sleep 1
|
727
|
-
|
728
|
-
|
728
|
+
store.load(#{key2}, :expires => 3).should == #{val2}
|
729
|
+
store[#{key2}].should == #{val2}
|
729
730
|
sleep 1
|
730
|
-
|
731
|
+
store[#{key2}].should == #{val2}
|
731
732
|
sleep 3
|
732
|
-
|
733
|
+
store[#{key2}].should == nil
|
733
734
|
end
|
734
735
|
|
735
736
|
it 'should support updating the expiration time in fetch' do
|
736
|
-
|
737
|
-
|
737
|
+
store.store(#{key1}, #{val1}, :expires => 2)
|
738
|
+
store[#{key1}].should == #{val1}
|
738
739
|
sleep 1
|
739
|
-
|
740
|
-
|
740
|
+
store.fetch(#{key1}, nil, :expires => 3).should == #{val1}
|
741
|
+
store[#{key1}].should == #{val1}
|
741
742
|
sleep 1
|
742
|
-
|
743
|
+
store[#{key1}].should == #{val1}
|
743
744
|
sleep 3
|
744
|
-
|
745
|
+
store[#{key1}].should == nil
|
745
746
|
end
|
746
747
|
|
747
748
|
it 'should respect expires in delete' do
|
748
|
-
|
749
|
-
|
749
|
+
store.store(#{key2}, #{val2}, :expires => 2)
|
750
|
+
store[#{key2}].should == #{val2}
|
750
751
|
sleep 1
|
751
|
-
|
752
|
+
store[#{key2}].should == #{val2}
|
752
753
|
sleep 2
|
753
|
-
|
754
|
+
store.delete(#{key2}).should == nil
|
754
755
|
end}
|
755
756
|
SPECS["expires_#{key_type.downcase}key_#{val_type.downcase}value"] = code
|
756
757
|
|
@@ -759,47 +760,47 @@ end
|
|
759
760
|
|
760
761
|
SPECS["marshallable_key"] = %{it "refuses to #[] from keys that cannot be marshalled" do
|
761
762
|
expect do
|
762
|
-
|
763
|
+
store[Struct.new(:foo).new(:bar)]
|
763
764
|
end.to raise_error(marshal_error)
|
764
765
|
end
|
765
766
|
|
766
767
|
it "refuses to load from keys that cannot be marshalled" do
|
767
768
|
expect do
|
768
|
-
|
769
|
+
store.load(Struct.new(:foo).new(:bar))
|
769
770
|
end.to raise_error(marshal_error)
|
770
771
|
end
|
771
772
|
|
772
773
|
it "refuses to fetch from keys that cannot be marshalled" do
|
773
774
|
expect do
|
774
|
-
|
775
|
+
store.fetch(Struct.new(:foo).new(:bar), true)
|
775
776
|
end.to raise_error(marshal_error)
|
776
777
|
end
|
777
778
|
|
778
779
|
it "refuses to #[]= to keys that cannot be marshalled" do
|
779
780
|
expect do
|
780
|
-
|
781
|
+
store[Struct.new(:foo).new(:bar)] = 'value'
|
781
782
|
end.to raise_error(marshal_error)
|
782
783
|
end
|
783
784
|
|
784
785
|
it "refuses to store to keys that cannot be marshalled" do
|
785
786
|
expect do
|
786
|
-
|
787
|
+
store.store Struct.new(:foo).new(:bar), 'value'
|
787
788
|
end.to raise_error(marshal_error)
|
788
789
|
end
|
789
790
|
|
790
791
|
it "refuses to check for key? if the key cannot be marshalled" do
|
791
792
|
expect do
|
792
|
-
|
793
|
+
store.key? Struct.new(:foo).new(:bar)
|
793
794
|
end.to raise_error(marshal_error)
|
794
795
|
end
|
795
796
|
|
796
797
|
it "refuses to delete a key if the key cannot be marshalled" do
|
797
798
|
expect do
|
798
|
-
|
799
|
+
store.delete Struct.new(:foo).new(:bar)
|
799
800
|
end.to raise_error(marshal_error)
|
800
801
|
end}
|
801
802
|
|
802
|
-
specs_code =
|
803
|
+
specs_code = "#{header}\n"
|
803
804
|
SPECS.each do |key, code|
|
804
805
|
specs_code << "#################### #{key} ####################\n\n" <<
|
805
806
|
"shared_examples_for '#{key}' do\n " << code.gsub("\n", "\n ") << "\nend\n\n"
|
@@ -814,13 +815,13 @@ TESTS.each do |name, options|
|
|
814
815
|
value = [options.delete(:value) || %w(Object String Hash)].flatten
|
815
816
|
|
816
817
|
specs = [options.delete(:specs) || SIMPLE_SPECS].flatten
|
817
|
-
specs_code =
|
818
|
+
specs_code = []
|
818
819
|
specs.each do |s|
|
819
|
-
specs_code << "
|
820
|
+
specs_code << " it_should_behave_like '#{s}'" if SPECS[s.to_s]
|
820
821
|
key.each do |k|
|
821
822
|
value.each do |v|
|
822
823
|
x = "#{s}_#{k.downcase}key_#{v.downcase}value"
|
823
|
-
specs_code << "
|
824
|
+
specs_code << " it_should_behave_like '#{x}'" if SPECS[x]
|
824
825
|
end
|
825
826
|
end
|
826
827
|
end
|
@@ -831,29 +832,15 @@ TESTS.each do |name, options|
|
|
831
832
|
|
832
833
|
build ||= "Juno.new(#{store.inspect}#{opts})"
|
833
834
|
|
834
|
-
code = %{#
|
835
|
-
require 'helper'
|
836
|
-
|
837
|
-
begin
|
838
|
-
#{preamble}#{build}.close
|
839
|
-
|
840
|
-
describe #{name.inspect} do
|
841
|
-
before do
|
842
|
-
@store = #{build}
|
843
|
-
@store.clear
|
844
|
-
end
|
845
|
-
|
846
|
-
after do
|
847
|
-
@store.close.should == nil if @store
|
848
|
-
end
|
835
|
+
code = %{#{header}require 'helper'
|
849
836
|
|
850
|
-
#{
|
837
|
+
describe_juno #{name.inspect} do
|
838
|
+
#{preamble}def new_store
|
839
|
+
#{build.gsub("\n", "\n ")}
|
851
840
|
end
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
puts "Test #{name} not executed: \#{ex.message}"
|
856
|
-
#puts "\#{ex.backtrace.join("\\n")}"
|
841
|
+
|
842
|
+
include_context 'setup_store'
|
843
|
+
#{specs_code.join("\n")}#{options[:tests].to_s.gsub("\n", "\n ")}
|
857
844
|
end
|
858
845
|
}
|
859
846
|
|
data/spec/helper.rb
CHANGED
@@ -37,3 +37,42 @@ def marshal_error
|
|
37
37
|
TypeError
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
class InitializeStore
|
42
|
+
def initialize(&block)
|
43
|
+
instance_eval(&block)
|
44
|
+
store = new_store
|
45
|
+
store['foo'] = 'bar'
|
46
|
+
store.clear
|
47
|
+
store.close
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing(*args)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def describe_juno(name, &block)
|
55
|
+
begin
|
56
|
+
InitializeStore.new(&block)
|
57
|
+
describe(name, &block)
|
58
|
+
rescue LoadError => ex
|
59
|
+
puts "\e[31mTest #{name} not executed: #{ex.message}\e[0m"
|
60
|
+
rescue Exception => ex
|
61
|
+
puts "\e[31mTest #{name} not executed: #{ex.message}\e[0m"
|
62
|
+
puts ex.backtrace.join("\n")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
shared_context 'setup_store' do
|
67
|
+
let(:store) do
|
68
|
+
new_store
|
69
|
+
end
|
70
|
+
|
71
|
+
before do
|
72
|
+
store.clear
|
73
|
+
end
|
74
|
+
|
75
|
+
after do
|
76
|
+
store.close.should == nil if store
|
77
|
+
end
|
78
|
+
end
|