juno 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. data/README.md +2 -277
  2. data/juno.gemspec +6 -5
  3. data/lib/juno.rb +3 -122
  4. metadata +23 -307
  5. data/.gitignore +0 -6
  6. data/.travis.yml +0 -30
  7. data/Gemfile +0 -56
  8. data/LICENSE +0 -20
  9. data/Rakefile +0 -33
  10. data/SPEC.md +0 -71
  11. data/benchmarks/run.rb +0 -180
  12. data/lib/juno/adapters/activerecord.rb +0 -74
  13. data/lib/juno/adapters/cassandra.rb +0 -89
  14. data/lib/juno/adapters/cookie.rb +0 -35
  15. data/lib/juno/adapters/couch.rb +0 -57
  16. data/lib/juno/adapters/datamapper.rb +0 -76
  17. data/lib/juno/adapters/dbm.rb +0 -25
  18. data/lib/juno/adapters/file.rb +0 -60
  19. data/lib/juno/adapters/fog.rb +0 -51
  20. data/lib/juno/adapters/gdbm.rb +0 -25
  21. data/lib/juno/adapters/hbase.rb +0 -64
  22. data/lib/juno/adapters/leveldb.rb +0 -35
  23. data/lib/juno/adapters/localmemcache.rb +0 -26
  24. data/lib/juno/adapters/lruhash.rb +0 -83
  25. data/lib/juno/adapters/memcached.rb +0 -11
  26. data/lib/juno/adapters/memcached_dalli.rb +0 -51
  27. data/lib/juno/adapters/memcached_native.rb +0 -52
  28. data/lib/juno/adapters/memory.rb +0 -32
  29. data/lib/juno/adapters/mongo.rb +0 -50
  30. data/lib/juno/adapters/null.rb +0 -30
  31. data/lib/juno/adapters/pstore.rb +0 -58
  32. data/lib/juno/adapters/redis.rb +0 -56
  33. data/lib/juno/adapters/riak.rb +0 -57
  34. data/lib/juno/adapters/sdbm.rb +0 -35
  35. data/lib/juno/adapters/sequel.rb +0 -67
  36. data/lib/juno/adapters/sqlite.rb +0 -61
  37. data/lib/juno/adapters/tokyocabinet.rb +0 -41
  38. data/lib/juno/adapters/yaml.rb +0 -15
  39. data/lib/juno/base.rb +0 -62
  40. data/lib/juno/builder.rb +0 -39
  41. data/lib/juno/cache.rb +0 -78
  42. data/lib/juno/expires.rb +0 -47
  43. data/lib/juno/lock.rb +0 -44
  44. data/lib/juno/logger.rb +0 -86
  45. data/lib/juno/proxy.rb +0 -72
  46. data/lib/juno/stack.rb +0 -72
  47. data/lib/juno/transformer.rb +0 -176
  48. data/lib/juno/version.rb +0 -5
  49. data/lib/rack/cache/juno.rb +0 -93
  50. data/lib/rack/juno_cookies.rb +0 -64
  51. data/lib/rack/session/juno.rb +0 -63
  52. data/spec/generate.rb +0 -1068
  53. data/spec/helper.rb +0 -78
  54. data/spec/juno/adapter_activerecord_spec.rb +0 -27
  55. data/spec/juno/adapter_cassandra_spec.rb +0 -13
  56. data/spec/juno/adapter_cookie_spec.rb +0 -13
  57. data/spec/juno/adapter_couch_spec.rb +0 -13
  58. data/spec/juno/adapter_datamapper_spec.rb +0 -44
  59. data/spec/juno/adapter_dbm_spec.rb +0 -13
  60. data/spec/juno/adapter_file_spec.rb +0 -13
  61. data/spec/juno/adapter_fog_spec.rb +0 -18
  62. data/spec/juno/adapter_gdbm_spec.rb +0 -13
  63. data/spec/juno/adapter_hbase_spec.rb +0 -13
  64. data/spec/juno/adapter_leveldb_spec.rb +0 -13
  65. data/spec/juno/adapter_localmemcache_spec.rb +0 -13
  66. data/spec/juno/adapter_lruhash_spec.rb +0 -26
  67. data/spec/juno/adapter_memcached_dalli_spec.rb +0 -14
  68. data/spec/juno/adapter_memcached_native_spec.rb +0 -14
  69. data/spec/juno/adapter_memcached_spec.rb +0 -14
  70. data/spec/juno/adapter_memory_spec.rb +0 -34
  71. data/spec/juno/adapter_mongo_spec.rb +0 -13
  72. data/spec/juno/adapter_pstore_spec.rb +0 -16
  73. data/spec/juno/adapter_redis_spec.rb +0 -14
  74. data/spec/juno/adapter_riak_spec.rb +0 -17
  75. data/spec/juno/adapter_sdbm_spec.rb +0 -13
  76. data/spec/juno/adapter_sequel_spec.rb +0 -13
  77. data/spec/juno/adapter_sqlite_spec.rb +0 -13
  78. data/spec/juno/adapter_tokyocabinet_bdb_spec.rb +0 -13
  79. data/spec/juno/adapter_tokyocabinet_hdb_spec.rb +0 -13
  80. data/spec/juno/adapter_yaml_spec.rb +0 -16
  81. data/spec/juno/cache_file_memory_spec.rb +0 -29
  82. data/spec/juno/cache_memory_null_spec.rb +0 -18
  83. data/spec/juno/expires_file_spec.rb +0 -71
  84. data/spec/juno/expires_memory_spec.rb +0 -49
  85. data/spec/juno/lock_spec.rb +0 -37
  86. data/spec/juno/null_adapter_spec.rb +0 -22
  87. data/spec/juno/proxy_expires_memory_spec.rb +0 -51
  88. data/spec/juno/proxy_redis_spec.rb +0 -18
  89. data/spec/juno/simple_activerecord_spec.rb +0 -45
  90. data/spec/juno/simple_activerecord_with_expires_spec.rb +0 -46
  91. data/spec/juno/simple_cassandra_spec.rb +0 -46
  92. data/spec/juno/simple_couch_spec.rb +0 -45
  93. data/spec/juno/simple_couch_with_expires_spec.rb +0 -46
  94. data/spec/juno/simple_datamapper_spec.rb +0 -47
  95. data/spec/juno/simple_datamapper_with_expires_spec.rb +0 -48
  96. data/spec/juno/simple_datamapper_with_repository_spec.rb +0 -47
  97. data/spec/juno/simple_dbm_spec.rb +0 -45
  98. data/spec/juno/simple_dbm_with_expires_spec.rb +0 -46
  99. data/spec/juno/simple_file_spec.rb +0 -45
  100. data/spec/juno/simple_file_with_expires_spec.rb +0 -46
  101. data/spec/juno/simple_fog_spec.rb +0 -50
  102. data/spec/juno/simple_fog_with_expires_spec.rb +0 -52
  103. data/spec/juno/simple_gdbm_spec.rb +0 -45
  104. data/spec/juno/simple_gdbm_with_expires_spec.rb +0 -46
  105. data/spec/juno/simple_hashfile_spec.rb +0 -45
  106. data/spec/juno/simple_hashfile_with_expires_spec.rb +0 -46
  107. data/spec/juno/simple_hbase_spec.rb +0 -45
  108. data/spec/juno/simple_hbase_with_expires_spec.rb +0 -46
  109. data/spec/juno/simple_leveldb_spec.rb +0 -45
  110. data/spec/juno/simple_leveldb_with_expires_spec.rb +0 -46
  111. data/spec/juno/simple_localmemcache_spec.rb +0 -45
  112. data/spec/juno/simple_localmemcache_with_expires_spec.rb +0 -46
  113. data/spec/juno/simple_lruhash_spec.rb +0 -45
  114. data/spec/juno/simple_lruhash_with_expires_spec.rb +0 -46
  115. data/spec/juno/simple_memcached_dalli_spec.rb +0 -46
  116. data/spec/juno/simple_memcached_native_spec.rb +0 -46
  117. data/spec/juno/simple_memcached_spec.rb +0 -46
  118. data/spec/juno/simple_memory_spec.rb +0 -45
  119. data/spec/juno/simple_memory_with_compress_spec.rb +0 -45
  120. data/spec/juno/simple_memory_with_expires_spec.rb +0 -46
  121. data/spec/juno/simple_memory_with_json_key_serializer_spec.rb +0 -32
  122. data/spec/juno/simple_memory_with_json_md5_key_serializer_spec.rb +0 -32
  123. data/spec/juno/simple_memory_with_json_serializer_spec.rb +0 -22
  124. data/spec/juno/simple_memory_with_json_value_serializer_spec.rb +0 -29
  125. data/spec/juno/simple_memory_with_prefix_spec.rb +0 -45
  126. data/spec/juno/simple_memory_with_quicklz_compress_spec.rb +0 -45
  127. data/spec/juno/simple_mongo_spec.rb +0 -45
  128. data/spec/juno/simple_mongo_with_expires_spec.rb +0 -46
  129. data/spec/juno/simple_null_spec.rb +0 -32
  130. data/spec/juno/simple_pstore_spec.rb +0 -45
  131. data/spec/juno/simple_pstore_with_expires_spec.rb +0 -46
  132. data/spec/juno/simple_redis_spec.rb +0 -46
  133. data/spec/juno/simple_riak_spec.rb +0 -49
  134. data/spec/juno/simple_riak_with_expires_spec.rb +0 -50
  135. data/spec/juno/simple_sdbm_spec.rb +0 -45
  136. data/spec/juno/simple_sdbm_with_expires_spec.rb +0 -46
  137. data/spec/juno/simple_sequel_spec.rb +0 -45
  138. data/spec/juno/simple_sequel_with_expires_spec.rb +0 -46
  139. data/spec/juno/simple_sqlite_spec.rb +0 -45
  140. data/spec/juno/simple_sqlite_with_expires_spec.rb +0 -46
  141. data/spec/juno/simple_tokyocabinet_spec.rb +0 -45
  142. data/spec/juno/simple_tokyocabinet_with_expires_spec.rb +0 -46
  143. data/spec/juno/simple_yaml_spec.rb +0 -44
  144. data/spec/juno/simple_yaml_with_expires_spec.rb +0 -45
  145. data/spec/juno/stack_file_memory_spec.rb +0 -20
  146. data/spec/juno/stack_memory_file_spec.rb +0 -19
  147. data/spec/juno/transformer_bencode_spec.rb +0 -25
  148. data/spec/juno/transformer_bert_spec.rb +0 -25
  149. data/spec/juno/transformer_bson_spec.rb +0 -25
  150. data/spec/juno/transformer_bzip2_spec.rb +0 -22
  151. data/spec/juno/transformer_json_spec.rb +0 -25
  152. data/spec/juno/transformer_lzma_spec.rb +0 -22
  153. data/spec/juno/transformer_lzo_spec.rb +0 -22
  154. data/spec/juno/transformer_marshal_base64_spec.rb +0 -48
  155. data/spec/juno/transformer_marshal_escape_spec.rb +0 -48
  156. data/spec/juno/transformer_marshal_hmac_spec.rb +0 -48
  157. data/spec/juno/transformer_marshal_md5_spec.rb +0 -48
  158. data/spec/juno/transformer_marshal_md5_spread_spec.rb +0 -48
  159. data/spec/juno/transformer_marshal_prefix_spec.rb +0 -48
  160. data/spec/juno/transformer_marshal_rmd160_spec.rb +0 -48
  161. data/spec/juno/transformer_marshal_sha1_spec.rb +0 -48
  162. data/spec/juno/transformer_marshal_sha256_spec.rb +0 -48
  163. data/spec/juno/transformer_marshal_sha384_spec.rb +0 -48
  164. data/spec/juno/transformer_marshal_sha512_spec.rb +0 -48
  165. data/spec/juno/transformer_marshal_uuencode_spec.rb +0 -48
  166. data/spec/juno/transformer_msgpack_spec.rb +0 -25
  167. data/spec/juno/transformer_ox_spec.rb +0 -46
  168. data/spec/juno/transformer_quicklz_spec.rb +0 -22
  169. data/spec/juno/transformer_snappy_spec.rb +0 -22
  170. data/spec/juno/transformer_tnet_spec.rb +0 -25
  171. data/spec/juno/transformer_yaml_spec.rb +0 -46
  172. data/spec/juno/transformer_zlib_spec.rb +0 -22
  173. data/spec/junospecs.rb +0 -2284
  174. data/spec/rack/cache_juno_spec.rb +0 -355
  175. data/spec/rack/juno_cookies_spec.rb +0 -81
  176. data/spec/rack/session_juno_spec.rb +0 -305
@@ -1,25 +0,0 @@
1
- # Generated by generate.rb
2
- require 'helper'
3
-
4
- describe_juno "transformer_msgpack" do
5
- def new_store
6
- Juno.build do
7
- use :Transformer, :key => :msgpack, :value => :msgpack
8
- adapter :Memory
9
- end
10
- end
11
-
12
- include_context 'setup_store'
13
- it_should_behave_like 'null_hashkey_hashvalue'
14
- it_should_behave_like 'null_hashkey_stringvalue'
15
- it_should_behave_like 'null_stringkey_hashvalue'
16
- it_should_behave_like 'null_stringkey_stringvalue'
17
- it_should_behave_like 'store_hashkey_hashvalue'
18
- it_should_behave_like 'store_hashkey_stringvalue'
19
- it_should_behave_like 'store_stringkey_hashvalue'
20
- it_should_behave_like 'store_stringkey_stringvalue'
21
- it_should_behave_like 'returndifferent_hashkey_hashvalue'
22
- it_should_behave_like 'returndifferent_hashkey_stringvalue'
23
- it_should_behave_like 'returndifferent_stringkey_hashvalue'
24
- it_should_behave_like 'returndifferent_stringkey_stringvalue'
25
- end
@@ -1,46 +0,0 @@
1
- # Generated by generate.rb
2
- require 'helper'
3
-
4
- describe_juno "transformer_ox" do
5
- def new_store
6
- Juno.build do
7
- use :Transformer, :key => :ox, :value => :ox
8
- adapter :Memory
9
- end
10
- end
11
-
12
- include_context 'setup_store'
13
- it_should_behave_like 'null_objectkey_objectvalue'
14
- it_should_behave_like 'null_objectkey_stringvalue'
15
- it_should_behave_like 'null_objectkey_hashvalue'
16
- it_should_behave_like 'null_objectkey_booleanvalue'
17
- it_should_behave_like 'null_stringkey_objectvalue'
18
- it_should_behave_like 'null_stringkey_stringvalue'
19
- it_should_behave_like 'null_stringkey_hashvalue'
20
- it_should_behave_like 'null_stringkey_booleanvalue'
21
- it_should_behave_like 'null_hashkey_objectvalue'
22
- it_should_behave_like 'null_hashkey_stringvalue'
23
- it_should_behave_like 'null_hashkey_hashvalue'
24
- it_should_behave_like 'null_hashkey_booleanvalue'
25
- it_should_behave_like 'store_objectkey_objectvalue'
26
- it_should_behave_like 'store_objectkey_stringvalue'
27
- it_should_behave_like 'store_objectkey_hashvalue'
28
- it_should_behave_like 'store_objectkey_booleanvalue'
29
- it_should_behave_like 'store_stringkey_objectvalue'
30
- it_should_behave_like 'store_stringkey_stringvalue'
31
- it_should_behave_like 'store_stringkey_hashvalue'
32
- it_should_behave_like 'store_stringkey_booleanvalue'
33
- it_should_behave_like 'store_hashkey_objectvalue'
34
- it_should_behave_like 'store_hashkey_stringvalue'
35
- it_should_behave_like 'store_hashkey_hashvalue'
36
- it_should_behave_like 'store_hashkey_booleanvalue'
37
- it_should_behave_like 'returndifferent_objectkey_objectvalue'
38
- it_should_behave_like 'returndifferent_objectkey_stringvalue'
39
- it_should_behave_like 'returndifferent_objectkey_hashvalue'
40
- it_should_behave_like 'returndifferent_stringkey_objectvalue'
41
- it_should_behave_like 'returndifferent_stringkey_stringvalue'
42
- it_should_behave_like 'returndifferent_stringkey_hashvalue'
43
- it_should_behave_like 'returndifferent_hashkey_objectvalue'
44
- it_should_behave_like 'returndifferent_hashkey_stringvalue'
45
- it_should_behave_like 'returndifferent_hashkey_hashvalue'
46
- end
@@ -1,22 +0,0 @@
1
- # Generated by generate.rb
2
- require 'helper'
3
-
4
- describe_juno "transformer_quicklz" do
5
- def new_store
6
- Juno.build do
7
- use :Transformer, :value => :quicklz
8
- adapter :Memory
9
- end
10
- end
11
-
12
- include_context 'setup_store'
13
- it_should_behave_like 'null_objectkey_stringvalue'
14
- it_should_behave_like 'null_stringkey_stringvalue'
15
- it_should_behave_like 'null_hashkey_stringvalue'
16
- it_should_behave_like 'store_objectkey_stringvalue'
17
- it_should_behave_like 'store_stringkey_stringvalue'
18
- it_should_behave_like 'store_hashkey_stringvalue'
19
- it_should_behave_like 'returndifferent_objectkey_stringvalue'
20
- it_should_behave_like 'returndifferent_stringkey_stringvalue'
21
- it_should_behave_like 'returndifferent_hashkey_stringvalue'
22
- end
@@ -1,22 +0,0 @@
1
- # Generated by generate.rb
2
- require 'helper'
3
-
4
- describe_juno "transformer_snappy" do
5
- def new_store
6
- Juno.build do
7
- use :Transformer, :value => :snappy
8
- adapter :Memory
9
- end
10
- end
11
-
12
- include_context 'setup_store'
13
- it_should_behave_like 'null_objectkey_stringvalue'
14
- it_should_behave_like 'null_stringkey_stringvalue'
15
- it_should_behave_like 'null_hashkey_stringvalue'
16
- it_should_behave_like 'store_objectkey_stringvalue'
17
- it_should_behave_like 'store_stringkey_stringvalue'
18
- it_should_behave_like 'store_hashkey_stringvalue'
19
- it_should_behave_like 'returndifferent_objectkey_stringvalue'
20
- it_should_behave_like 'returndifferent_stringkey_stringvalue'
21
- it_should_behave_like 'returndifferent_hashkey_stringvalue'
22
- end
@@ -1,25 +0,0 @@
1
- # Generated by generate.rb
2
- require 'helper'
3
-
4
- describe_juno "transformer_tnet" do
5
- def new_store
6
- Juno.build do
7
- use :Transformer, :key => :tnet, :value => :tnet
8
- adapter :Memory
9
- end
10
- end
11
-
12
- include_context 'setup_store'
13
- it_should_behave_like 'null_hashkey_hashvalue'
14
- it_should_behave_like 'null_hashkey_stringvalue'
15
- it_should_behave_like 'null_stringkey_hashvalue'
16
- it_should_behave_like 'null_stringkey_stringvalue'
17
- it_should_behave_like 'store_hashkey_hashvalue'
18
- it_should_behave_like 'store_hashkey_stringvalue'
19
- it_should_behave_like 'store_stringkey_hashvalue'
20
- it_should_behave_like 'store_stringkey_stringvalue'
21
- it_should_behave_like 'returndifferent_hashkey_hashvalue'
22
- it_should_behave_like 'returndifferent_hashkey_stringvalue'
23
- it_should_behave_like 'returndifferent_stringkey_hashvalue'
24
- it_should_behave_like 'returndifferent_stringkey_stringvalue'
25
- end
@@ -1,46 +0,0 @@
1
- # Generated by generate.rb
2
- require 'helper'
3
-
4
- describe_juno "transformer_yaml" do
5
- def new_store
6
- Juno.build do
7
- use :Transformer, :key => :yaml, :value => :yaml
8
- adapter :Memory
9
- end
10
- end
11
-
12
- include_context 'setup_store'
13
- it_should_behave_like 'null_objectkey_objectvalue'
14
- it_should_behave_like 'null_objectkey_stringvalue'
15
- it_should_behave_like 'null_objectkey_hashvalue'
16
- it_should_behave_like 'null_objectkey_booleanvalue'
17
- it_should_behave_like 'null_stringkey_objectvalue'
18
- it_should_behave_like 'null_stringkey_stringvalue'
19
- it_should_behave_like 'null_stringkey_hashvalue'
20
- it_should_behave_like 'null_stringkey_booleanvalue'
21
- it_should_behave_like 'null_hashkey_objectvalue'
22
- it_should_behave_like 'null_hashkey_stringvalue'
23
- it_should_behave_like 'null_hashkey_hashvalue'
24
- it_should_behave_like 'null_hashkey_booleanvalue'
25
- it_should_behave_like 'store_objectkey_objectvalue'
26
- it_should_behave_like 'store_objectkey_stringvalue'
27
- it_should_behave_like 'store_objectkey_hashvalue'
28
- it_should_behave_like 'store_objectkey_booleanvalue'
29
- it_should_behave_like 'store_stringkey_objectvalue'
30
- it_should_behave_like 'store_stringkey_stringvalue'
31
- it_should_behave_like 'store_stringkey_hashvalue'
32
- it_should_behave_like 'store_stringkey_booleanvalue'
33
- it_should_behave_like 'store_hashkey_objectvalue'
34
- it_should_behave_like 'store_hashkey_stringvalue'
35
- it_should_behave_like 'store_hashkey_hashvalue'
36
- it_should_behave_like 'store_hashkey_booleanvalue'
37
- it_should_behave_like 'returndifferent_objectkey_objectvalue'
38
- it_should_behave_like 'returndifferent_objectkey_stringvalue'
39
- it_should_behave_like 'returndifferent_objectkey_hashvalue'
40
- it_should_behave_like 'returndifferent_stringkey_objectvalue'
41
- it_should_behave_like 'returndifferent_stringkey_stringvalue'
42
- it_should_behave_like 'returndifferent_stringkey_hashvalue'
43
- it_should_behave_like 'returndifferent_hashkey_objectvalue'
44
- it_should_behave_like 'returndifferent_hashkey_stringvalue'
45
- it_should_behave_like 'returndifferent_hashkey_hashvalue'
46
- end
@@ -1,22 +0,0 @@
1
- # Generated by generate.rb
2
- require 'helper'
3
-
4
- describe_juno "transformer_zlib" do
5
- def new_store
6
- Juno.build do
7
- use :Transformer, :value => :zlib
8
- adapter :Memory
9
- end
10
- end
11
-
12
- include_context 'setup_store'
13
- it_should_behave_like 'null_objectkey_stringvalue'
14
- it_should_behave_like 'null_stringkey_stringvalue'
15
- it_should_behave_like 'null_hashkey_stringvalue'
16
- it_should_behave_like 'store_objectkey_stringvalue'
17
- it_should_behave_like 'store_stringkey_stringvalue'
18
- it_should_behave_like 'store_hashkey_stringvalue'
19
- it_should_behave_like 'returndifferent_objectkey_stringvalue'
20
- it_should_behave_like 'returndifferent_stringkey_stringvalue'
21
- it_should_behave_like 'returndifferent_hashkey_stringvalue'
22
- end
data/spec/junospecs.rb DELETED
@@ -1,2284 +0,0 @@
1
- # Generated by generate.rb
2
-
3
- #################### null_stringkey_booleanvalue ####################
4
-
5
- shared_examples_for 'null_stringkey_booleanvalue' do
6
- it "reads from keys that are Strings like a Hash" do
7
- store["strkey1"].should == nil
8
- store.load("strkey1").should == nil
9
- end
10
-
11
- it "guarantees that the same Boolean value is returned when setting a String key" do
12
- value = true
13
- (store["strkey1"] = value).should equal(value)
14
- end
15
-
16
- it "returns false from key? if a String key is not available" do
17
- store.key?("strkey1").should == false
18
- end
19
-
20
- it "returns nil from delete if an element for a String key does not exist" do
21
- store.delete("strkey1").should == nil
22
- end
23
-
24
- it "removes all String keys from the store with clear" do
25
- store["strkey1"] = true
26
- store["strkey2"] = false
27
- store.clear.should equal(store)
28
- store.key?("strkey1").should_not == true
29
- store.key?("strkey2").should_not == true
30
- end
31
-
32
- it "fetches a String key with a default value with fetch, if the key is not available" do
33
- store.fetch("strkey1", true).should == true
34
- end
35
-
36
- it "fetches a String key with a block with fetch, if the key is not available" do
37
- key = "strkey1"
38
- value = true
39
- store.fetch(key) do |k|
40
- k.should equal(key)
41
- value
42
- end.should equal(value)
43
- end
44
-
45
- it 'should accept options' do
46
- store.key?("strkey1", :option1 => 1).should == false
47
- store.load("strkey1", :option2 => 2).should == nil
48
- store.fetch("strkey1", 42, :option3 => 3).should == 42
49
- store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
50
- store.delete("strkey1", :option4 => 4).should == nil
51
- store.clear(:option5 => 5).should equal(store)
52
- store.store("strkey1", true, :option6 => 6).should == true
53
- end
54
- end
55
-
56
- #################### store_stringkey_booleanvalue ####################
57
-
58
- shared_examples_for 'store_stringkey_booleanvalue' do
59
- it "writes Boolean values to keys that are Strings like a Hash" do
60
- store["strkey1"] = true
61
- store["strkey1"].should == true
62
- store.load("strkey1").should == true
63
- end
64
-
65
- it "returns true from key? if a String key is available" do
66
- store["strkey1"] = true
67
- store.key?("strkey1").should == true
68
- store["strkey2"] = false
69
- store.key?("strkey2").should == true
70
- end
71
-
72
- it "stores Boolean values with String keys with #store" do
73
- value = true
74
- store.store("strkey1", value).should equal(value)
75
- store["strkey1"].should == true
76
- store.load("strkey1").should == true
77
- end
78
-
79
- it "removes and returns a Boolean element with a String key from the backing store via delete if it exists" do
80
- store["strkey1"] = true
81
- store.delete("strkey1").should == true
82
- store.key?("strkey1").should == false
83
- end
84
-
85
- it "overwrites existing Boolean values with String" do
86
- store["strkey1"] = true
87
- store["strkey1"].should == true
88
- store["strkey1"] = false
89
- store["strkey1"].should == false
90
- end
91
-
92
- it "does not run the block if the String key is available" do
93
- store["strkey1"] = true
94
- unaltered = "unaltered"
95
- store.fetch("strkey1") { unaltered = "altered" }
96
- unaltered.should == "unaltered"
97
- end
98
-
99
- it "fetches a String key with a default value with fetch, if the key is available" do
100
- store["strkey1"] = true
101
- store.fetch("strkey1", false).should == true
102
- end
103
- end
104
-
105
- #################### expires_stringkey_booleanvalue ####################
106
-
107
- shared_examples_for 'expires_stringkey_booleanvalue' do
108
- it 'should support expires on store and #[]' do
109
- store.store("strkey1", true, :expires => 2)
110
- store["strkey1"].should == true
111
- sleep 1
112
- store["strkey1"].should == true
113
- sleep 2
114
- store["strkey1"].should == nil
115
- end
116
-
117
- it 'should support expires on store and load' do
118
- store.store("strkey1", true, :expires => 2)
119
- store.load("strkey1").should == true
120
- sleep 1
121
- store.load("strkey1").should == true
122
- sleep 2
123
- store.load("strkey1").should == nil
124
- end
125
-
126
- it 'should support expires on store and key?' do
127
- store.store("strkey1", true, :expires => 2)
128
- store.key?("strkey1").should == true
129
- sleep 1
130
- store.key?("strkey1").should == true
131
- sleep 2
132
- store.key?("strkey1").should == false
133
- end
134
-
135
- it 'should support updating the expiration time in load' do
136
- store.store("strkey2", false, :expires => 2)
137
- store["strkey2"].should == false
138
- sleep 1
139
- store.load("strkey2", :expires => 3).should == false
140
- store["strkey2"].should == false
141
- sleep 1
142
- store["strkey2"].should == false
143
- sleep 3
144
- store["strkey2"].should == nil
145
- end
146
-
147
- it 'should support updating the expiration time in key?' do
148
- store.store("strkey2", false, :expires => 2)
149
- store["strkey2"].should == false
150
- sleep 1
151
- store.key?("strkey2", :expires => 3).should be_true
152
- store["strkey2"].should == false
153
- sleep 1
154
- store["strkey2"].should == false
155
- sleep 3
156
- store["strkey2"].should == nil
157
- end
158
-
159
- it 'should support updating the expiration time in fetch' do
160
- store.store("strkey1", true, :expires => 2)
161
- store["strkey1"].should == true
162
- sleep 1
163
- store.fetch("strkey1", nil, :expires => 3).should == true
164
- store["strkey1"].should == true
165
- sleep 1
166
- store["strkey1"].should == true
167
- sleep 3
168
- store["strkey1"].should == nil
169
- end
170
-
171
- it 'should respect expires in delete' do
172
- store.store("strkey2", false, :expires => 2)
173
- store["strkey2"].should == false
174
- sleep 1
175
- store["strkey2"].should == false
176
- sleep 2
177
- store.delete("strkey2").should == nil
178
- end
179
- end
180
-
181
- #################### null_stringkey_stringvalue ####################
182
-
183
- shared_examples_for 'null_stringkey_stringvalue' do
184
- it "reads from keys that are Strings like a Hash" do
185
- store["strkey1"].should == nil
186
- store.load("strkey1").should == nil
187
- end
188
-
189
- it "guarantees that the same String value is returned when setting a String key" do
190
- value = "strval1"
191
- (store["strkey1"] = value).should equal(value)
192
- end
193
-
194
- it "returns false from key? if a String key is not available" do
195
- store.key?("strkey1").should == false
196
- end
197
-
198
- it "returns nil from delete if an element for a String key does not exist" do
199
- store.delete("strkey1").should == nil
200
- end
201
-
202
- it "removes all String keys from the store with clear" do
203
- store["strkey1"] = "strval1"
204
- store["strkey2"] = "strval2"
205
- store.clear.should equal(store)
206
- store.key?("strkey1").should_not == true
207
- store.key?("strkey2").should_not == true
208
- end
209
-
210
- it "fetches a String key with a default value with fetch, if the key is not available" do
211
- store.fetch("strkey1", "strval1").should == "strval1"
212
- end
213
-
214
- it "fetches a String key with a block with fetch, if the key is not available" do
215
- key = "strkey1"
216
- value = "strval1"
217
- store.fetch(key) do |k|
218
- k.should equal(key)
219
- value
220
- end.should equal(value)
221
- end
222
-
223
- it 'should accept options' do
224
- store.key?("strkey1", :option1 => 1).should == false
225
- store.load("strkey1", :option2 => 2).should == nil
226
- store.fetch("strkey1", 42, :option3 => 3).should == 42
227
- store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
228
- store.delete("strkey1", :option4 => 4).should == nil
229
- store.clear(:option5 => 5).should equal(store)
230
- store.store("strkey1", "strval1", :option6 => 6).should == "strval1"
231
- end
232
- end
233
-
234
- #################### store_stringkey_stringvalue ####################
235
-
236
- shared_examples_for 'store_stringkey_stringvalue' do
237
- it "writes String values to keys that are Strings like a Hash" do
238
- store["strkey1"] = "strval1"
239
- store["strkey1"].should == "strval1"
240
- store.load("strkey1").should == "strval1"
241
- end
242
-
243
- it "returns true from key? if a String key is available" do
244
- store["strkey1"] = "strval1"
245
- store.key?("strkey1").should == true
246
- store["strkey2"] = "strval2"
247
- store.key?("strkey2").should == true
248
- end
249
-
250
- it "stores String values with String keys with #store" do
251
- value = "strval1"
252
- store.store("strkey1", value).should equal(value)
253
- store["strkey1"].should == "strval1"
254
- store.load("strkey1").should == "strval1"
255
- end
256
-
257
- it "removes and returns a String element with a String key from the backing store via delete if it exists" do
258
- store["strkey1"] = "strval1"
259
- store.delete("strkey1").should == "strval1"
260
- store.key?("strkey1").should == false
261
- end
262
-
263
- it "overwrites existing String values with String" do
264
- store["strkey1"] = "strval1"
265
- store["strkey1"].should == "strval1"
266
- store["strkey1"] = "strval2"
267
- store["strkey1"].should == "strval2"
268
- end
269
-
270
- it "does not run the block if the String key is available" do
271
- store["strkey1"] = "strval1"
272
- unaltered = "unaltered"
273
- store.fetch("strkey1") { unaltered = "altered" }
274
- unaltered.should == "unaltered"
275
- end
276
-
277
- it "fetches a String key with a default value with fetch, if the key is available" do
278
- store["strkey1"] = "strval1"
279
- store.fetch("strkey1", "strval2").should == "strval1"
280
- end
281
- end
282
-
283
- #################### returndifferent_stringkey_stringvalue ####################
284
-
285
- shared_examples_for 'returndifferent_stringkey_stringvalue' do
286
- it "guarantees that a different String value is retrieved from the String key" do
287
- value = "strval1"
288
- store["strkey1"] = "strval1"
289
- store["strkey1"].should_not be_equal("strval1")
290
- end
291
- end
292
-
293
- #################### expires_stringkey_stringvalue ####################
294
-
295
- shared_examples_for 'expires_stringkey_stringvalue' do
296
- it 'should support expires on store and #[]' do
297
- store.store("strkey1", "strval1", :expires => 2)
298
- store["strkey1"].should == "strval1"
299
- sleep 1
300
- store["strkey1"].should == "strval1"
301
- sleep 2
302
- store["strkey1"].should == nil
303
- end
304
-
305
- it 'should support expires on store and load' do
306
- store.store("strkey1", "strval1", :expires => 2)
307
- store.load("strkey1").should == "strval1"
308
- sleep 1
309
- store.load("strkey1").should == "strval1"
310
- sleep 2
311
- store.load("strkey1").should == nil
312
- end
313
-
314
- it 'should support expires on store and key?' do
315
- store.store("strkey1", "strval1", :expires => 2)
316
- store.key?("strkey1").should == true
317
- sleep 1
318
- store.key?("strkey1").should == true
319
- sleep 2
320
- store.key?("strkey1").should == false
321
- end
322
-
323
- it 'should support updating the expiration time in load' do
324
- store.store("strkey2", "strval2", :expires => 2)
325
- store["strkey2"].should == "strval2"
326
- sleep 1
327
- store.load("strkey2", :expires => 3).should == "strval2"
328
- store["strkey2"].should == "strval2"
329
- sleep 1
330
- store["strkey2"].should == "strval2"
331
- sleep 3
332
- store["strkey2"].should == nil
333
- end
334
-
335
- it 'should support updating the expiration time in key?' do
336
- store.store("strkey2", "strval2", :expires => 2)
337
- store["strkey2"].should == "strval2"
338
- sleep 1
339
- store.key?("strkey2", :expires => 3).should be_true
340
- store["strkey2"].should == "strval2"
341
- sleep 1
342
- store["strkey2"].should == "strval2"
343
- sleep 3
344
- store["strkey2"].should == nil
345
- end
346
-
347
- it 'should support updating the expiration time in fetch' do
348
- store.store("strkey1", "strval1", :expires => 2)
349
- store["strkey1"].should == "strval1"
350
- sleep 1
351
- store.fetch("strkey1", nil, :expires => 3).should == "strval1"
352
- store["strkey1"].should == "strval1"
353
- sleep 1
354
- store["strkey1"].should == "strval1"
355
- sleep 3
356
- store["strkey1"].should == nil
357
- end
358
-
359
- it 'should respect expires in delete' do
360
- store.store("strkey2", "strval2", :expires => 2)
361
- store["strkey2"].should == "strval2"
362
- sleep 1
363
- store["strkey2"].should == "strval2"
364
- sleep 2
365
- store.delete("strkey2").should == nil
366
- end
367
- end
368
-
369
- #################### null_stringkey_hashvalue ####################
370
-
371
- shared_examples_for 'null_stringkey_hashvalue' do
372
- it "reads from keys that are Strings like a Hash" do
373
- store["strkey1"].should == nil
374
- store.load("strkey1").should == nil
375
- end
376
-
377
- it "guarantees that the same Hash value is returned when setting a String key" do
378
- value = {"hashval1"=>["array1", 1]}
379
- (store["strkey1"] = value).should equal(value)
380
- end
381
-
382
- it "returns false from key? if a String key is not available" do
383
- store.key?("strkey1").should == false
384
- end
385
-
386
- it "returns nil from delete if an element for a String key does not exist" do
387
- store.delete("strkey1").should == nil
388
- end
389
-
390
- it "removes all String keys from the store with clear" do
391
- store["strkey1"] = {"hashval1"=>["array1", 1]}
392
- store["strkey2"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
393
- store.clear.should equal(store)
394
- store.key?("strkey1").should_not == true
395
- store.key?("strkey2").should_not == true
396
- end
397
-
398
- it "fetches a String key with a default value with fetch, if the key is not available" do
399
- store.fetch("strkey1", {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
400
- end
401
-
402
- it "fetches a String key with a block with fetch, if the key is not available" do
403
- key = "strkey1"
404
- value = {"hashval1"=>["array1", 1]}
405
- store.fetch(key) do |k|
406
- k.should equal(key)
407
- value
408
- end.should equal(value)
409
- end
410
-
411
- it 'should accept options' do
412
- store.key?("strkey1", :option1 => 1).should == false
413
- store.load("strkey1", :option2 => 2).should == nil
414
- store.fetch("strkey1", 42, :option3 => 3).should == 42
415
- store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
416
- store.delete("strkey1", :option4 => 4).should == nil
417
- store.clear(:option5 => 5).should equal(store)
418
- store.store("strkey1", {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
419
- end
420
- end
421
-
422
- #################### store_stringkey_hashvalue ####################
423
-
424
- shared_examples_for 'store_stringkey_hashvalue' do
425
- it "writes Hash values to keys that are Strings like a Hash" do
426
- store["strkey1"] = {"hashval1"=>["array1", 1]}
427
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
428
- store.load("strkey1").should == {"hashval1"=>["array1", 1]}
429
- end
430
-
431
- it "returns true from key? if a String key is available" do
432
- store["strkey1"] = {"hashval1"=>["array1", 1]}
433
- store.key?("strkey1").should == true
434
- store["strkey2"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
435
- store.key?("strkey2").should == true
436
- end
437
-
438
- it "stores Hash values with String keys with #store" do
439
- value = {"hashval1"=>["array1", 1]}
440
- store.store("strkey1", value).should equal(value)
441
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
442
- store.load("strkey1").should == {"hashval1"=>["array1", 1]}
443
- end
444
-
445
- it "removes and returns a Hash element with a String key from the backing store via delete if it exists" do
446
- store["strkey1"] = {"hashval1"=>["array1", 1]}
447
- store.delete("strkey1").should == {"hashval1"=>["array1", 1]}
448
- store.key?("strkey1").should == false
449
- end
450
-
451
- it "overwrites existing Hash values with String" do
452
- store["strkey1"] = {"hashval1"=>["array1", 1]}
453
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
454
- store["strkey1"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
455
- store["strkey1"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
456
- end
457
-
458
- it "does not run the block if the String key is available" do
459
- store["strkey1"] = {"hashval1"=>["array1", 1]}
460
- unaltered = "unaltered"
461
- store.fetch("strkey1") { unaltered = "altered" }
462
- unaltered.should == "unaltered"
463
- end
464
-
465
- it "fetches a String key with a default value with fetch, if the key is available" do
466
- store["strkey1"] = {"hashval1"=>["array1", 1]}
467
- store.fetch("strkey1", {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
468
- end
469
- end
470
-
471
- #################### returndifferent_stringkey_hashvalue ####################
472
-
473
- shared_examples_for 'returndifferent_stringkey_hashvalue' do
474
- it "guarantees that a different Hash value is retrieved from the String key" do
475
- value = {"hashval1"=>["array1", 1]}
476
- store["strkey1"] = {"hashval1"=>["array1", 1]}
477
- store["strkey1"].should_not be_equal({"hashval1"=>["array1", 1]})
478
- end
479
- end
480
-
481
- #################### expires_stringkey_hashvalue ####################
482
-
483
- shared_examples_for 'expires_stringkey_hashvalue' do
484
- it 'should support expires on store and #[]' do
485
- store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
486
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
487
- sleep 1
488
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
489
- sleep 2
490
- store["strkey1"].should == nil
491
- end
492
-
493
- it 'should support expires on store and load' do
494
- store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
495
- store.load("strkey1").should == {"hashval1"=>["array1", 1]}
496
- sleep 1
497
- store.load("strkey1").should == {"hashval1"=>["array1", 1]}
498
- sleep 2
499
- store.load("strkey1").should == nil
500
- end
501
-
502
- it 'should support expires on store and key?' do
503
- store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
504
- store.key?("strkey1").should == true
505
- sleep 1
506
- store.key?("strkey1").should == true
507
- sleep 2
508
- store.key?("strkey1").should == false
509
- end
510
-
511
- it 'should support updating the expiration time in load' do
512
- store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
513
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
514
- sleep 1
515
- store.load("strkey2", :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
516
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
517
- sleep 1
518
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
519
- sleep 3
520
- store["strkey2"].should == nil
521
- end
522
-
523
- it 'should support updating the expiration time in key?' do
524
- store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
525
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
526
- sleep 1
527
- store.key?("strkey2", :expires => 3).should be_true
528
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
529
- sleep 1
530
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
531
- sleep 3
532
- store["strkey2"].should == nil
533
- end
534
-
535
- it 'should support updating the expiration time in fetch' do
536
- store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
537
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
538
- sleep 1
539
- store.fetch("strkey1", nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
540
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
541
- sleep 1
542
- store["strkey1"].should == {"hashval1"=>["array1", 1]}
543
- sleep 3
544
- store["strkey1"].should == nil
545
- end
546
-
547
- it 'should respect expires in delete' do
548
- store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
549
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
550
- sleep 1
551
- store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
552
- sleep 2
553
- store.delete("strkey2").should == nil
554
- end
555
- end
556
-
557
- #################### null_stringkey_objectvalue ####################
558
-
559
- shared_examples_for 'null_stringkey_objectvalue' do
560
- it "reads from keys that are Strings like a Hash" do
561
- store["strkey1"].should == nil
562
- store.load("strkey1").should == nil
563
- end
564
-
565
- it "guarantees that the same Object value is returned when setting a String key" do
566
- value = Value.new(:objval1)
567
- (store["strkey1"] = value).should equal(value)
568
- end
569
-
570
- it "returns false from key? if a String key is not available" do
571
- store.key?("strkey1").should == false
572
- end
573
-
574
- it "returns nil from delete if an element for a String key does not exist" do
575
- store.delete("strkey1").should == nil
576
- end
577
-
578
- it "removes all String keys from the store with clear" do
579
- store["strkey1"] = Value.new(:objval1)
580
- store["strkey2"] = Value.new(:objval2)
581
- store.clear.should equal(store)
582
- store.key?("strkey1").should_not == true
583
- store.key?("strkey2").should_not == true
584
- end
585
-
586
- it "fetches a String key with a default value with fetch, if the key is not available" do
587
- store.fetch("strkey1", Value.new(:objval1)).should == Value.new(:objval1)
588
- end
589
-
590
- it "fetches a String key with a block with fetch, if the key is not available" do
591
- key = "strkey1"
592
- value = Value.new(:objval1)
593
- store.fetch(key) do |k|
594
- k.should equal(key)
595
- value
596
- end.should equal(value)
597
- end
598
-
599
- it 'should accept options' do
600
- store.key?("strkey1", :option1 => 1).should == false
601
- store.load("strkey1", :option2 => 2).should == nil
602
- store.fetch("strkey1", 42, :option3 => 3).should == 42
603
- store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
604
- store.delete("strkey1", :option4 => 4).should == nil
605
- store.clear(:option5 => 5).should equal(store)
606
- store.store("strkey1", Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
607
- end
608
- end
609
-
610
- #################### store_stringkey_objectvalue ####################
611
-
612
- shared_examples_for 'store_stringkey_objectvalue' do
613
- it "writes Object values to keys that are Strings like a Hash" do
614
- store["strkey1"] = Value.new(:objval1)
615
- store["strkey1"].should == Value.new(:objval1)
616
- store.load("strkey1").should == Value.new(:objval1)
617
- end
618
-
619
- it "returns true from key? if a String key is available" do
620
- store["strkey1"] = Value.new(:objval1)
621
- store.key?("strkey1").should == true
622
- store["strkey2"] = Value.new(:objval2)
623
- store.key?("strkey2").should == true
624
- end
625
-
626
- it "stores Object values with String keys with #store" do
627
- value = Value.new(:objval1)
628
- store.store("strkey1", value).should equal(value)
629
- store["strkey1"].should == Value.new(:objval1)
630
- store.load("strkey1").should == Value.new(:objval1)
631
- end
632
-
633
- it "removes and returns a Object element with a String key from the backing store via delete if it exists" do
634
- store["strkey1"] = Value.new(:objval1)
635
- store.delete("strkey1").should == Value.new(:objval1)
636
- store.key?("strkey1").should == false
637
- end
638
-
639
- it "overwrites existing Object values with String" do
640
- store["strkey1"] = Value.new(:objval1)
641
- store["strkey1"].should == Value.new(:objval1)
642
- store["strkey1"] = Value.new(:objval2)
643
- store["strkey1"].should == Value.new(:objval2)
644
- end
645
-
646
- it "does not run the block if the String key is available" do
647
- store["strkey1"] = Value.new(:objval1)
648
- unaltered = "unaltered"
649
- store.fetch("strkey1") { unaltered = "altered" }
650
- unaltered.should == "unaltered"
651
- end
652
-
653
- it "fetches a String key with a default value with fetch, if the key is available" do
654
- store["strkey1"] = Value.new(:objval1)
655
- store.fetch("strkey1", Value.new(:objval2)).should == Value.new(:objval1)
656
- end
657
- end
658
-
659
- #################### returndifferent_stringkey_objectvalue ####################
660
-
661
- shared_examples_for 'returndifferent_stringkey_objectvalue' do
662
- it "guarantees that a different Object value is retrieved from the String key" do
663
- value = Value.new(:objval1)
664
- store["strkey1"] = Value.new(:objval1)
665
- store["strkey1"].should_not be_equal(Value.new(:objval1))
666
- end
667
- end
668
-
669
- #################### expires_stringkey_objectvalue ####################
670
-
671
- shared_examples_for 'expires_stringkey_objectvalue' do
672
- it 'should support expires on store and #[]' do
673
- store.store("strkey1", Value.new(:objval1), :expires => 2)
674
- store["strkey1"].should == Value.new(:objval1)
675
- sleep 1
676
- store["strkey1"].should == Value.new(:objval1)
677
- sleep 2
678
- store["strkey1"].should == nil
679
- end
680
-
681
- it 'should support expires on store and load' do
682
- store.store("strkey1", Value.new(:objval1), :expires => 2)
683
- store.load("strkey1").should == Value.new(:objval1)
684
- sleep 1
685
- store.load("strkey1").should == Value.new(:objval1)
686
- sleep 2
687
- store.load("strkey1").should == nil
688
- end
689
-
690
- it 'should support expires on store and key?' do
691
- store.store("strkey1", Value.new(:objval1), :expires => 2)
692
- store.key?("strkey1").should == true
693
- sleep 1
694
- store.key?("strkey1").should == true
695
- sleep 2
696
- store.key?("strkey1").should == false
697
- end
698
-
699
- it 'should support updating the expiration time in load' do
700
- store.store("strkey2", Value.new(:objval2), :expires => 2)
701
- store["strkey2"].should == Value.new(:objval2)
702
- sleep 1
703
- store.load("strkey2", :expires => 3).should == Value.new(:objval2)
704
- store["strkey2"].should == Value.new(:objval2)
705
- sleep 1
706
- store["strkey2"].should == Value.new(:objval2)
707
- sleep 3
708
- store["strkey2"].should == nil
709
- end
710
-
711
- it 'should support updating the expiration time in key?' do
712
- store.store("strkey2", Value.new(:objval2), :expires => 2)
713
- store["strkey2"].should == Value.new(:objval2)
714
- sleep 1
715
- store.key?("strkey2", :expires => 3).should be_true
716
- store["strkey2"].should == Value.new(:objval2)
717
- sleep 1
718
- store["strkey2"].should == Value.new(:objval2)
719
- sleep 3
720
- store["strkey2"].should == nil
721
- end
722
-
723
- it 'should support updating the expiration time in fetch' do
724
- store.store("strkey1", Value.new(:objval1), :expires => 2)
725
- store["strkey1"].should == Value.new(:objval1)
726
- sleep 1
727
- store.fetch("strkey1", nil, :expires => 3).should == Value.new(:objval1)
728
- store["strkey1"].should == Value.new(:objval1)
729
- sleep 1
730
- store["strkey1"].should == Value.new(:objval1)
731
- sleep 3
732
- store["strkey1"].should == nil
733
- end
734
-
735
- it 'should respect expires in delete' do
736
- store.store("strkey2", Value.new(:objval2), :expires => 2)
737
- store["strkey2"].should == Value.new(:objval2)
738
- sleep 1
739
- store["strkey2"].should == Value.new(:objval2)
740
- sleep 2
741
- store.delete("strkey2").should == nil
742
- end
743
- end
744
-
745
- #################### null_objectkey_booleanvalue ####################
746
-
747
- shared_examples_for 'null_objectkey_booleanvalue' do
748
- it "reads from keys that are Objects like a Hash" do
749
- store[Value.new(:objkey1)].should == nil
750
- store.load(Value.new(:objkey1)).should == nil
751
- end
752
-
753
- it "guarantees that the same Boolean value is returned when setting a Object key" do
754
- value = true
755
- (store[Value.new(:objkey1)] = value).should equal(value)
756
- end
757
-
758
- it "returns false from key? if a Object key is not available" do
759
- store.key?(Value.new(:objkey1)).should == false
760
- end
761
-
762
- it "returns nil from delete if an element for a Object key does not exist" do
763
- store.delete(Value.new(:objkey1)).should == nil
764
- end
765
-
766
- it "removes all Object keys from the store with clear" do
767
- store[Value.new(:objkey1)] = true
768
- store[Value.new(:objkey2)] = false
769
- store.clear.should equal(store)
770
- store.key?(Value.new(:objkey1)).should_not == true
771
- store.key?(Value.new(:objkey2)).should_not == true
772
- end
773
-
774
- it "fetches a Object key with a default value with fetch, if the key is not available" do
775
- store.fetch(Value.new(:objkey1), true).should == true
776
- end
777
-
778
- it "fetches a Object key with a block with fetch, if the key is not available" do
779
- key = Value.new(:objkey1)
780
- value = true
781
- store.fetch(key) do |k|
782
- k.should equal(key)
783
- value
784
- end.should equal(value)
785
- end
786
-
787
- it 'should accept options' do
788
- store.key?(Value.new(:objkey1), :option1 => 1).should == false
789
- store.load(Value.new(:objkey1), :option2 => 2).should == nil
790
- store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
791
- store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
792
- store.delete(Value.new(:objkey1), :option4 => 4).should == nil
793
- store.clear(:option5 => 5).should equal(store)
794
- store.store(Value.new(:objkey1), true, :option6 => 6).should == true
795
- end
796
- end
797
-
798
- #################### store_objectkey_booleanvalue ####################
799
-
800
- shared_examples_for 'store_objectkey_booleanvalue' do
801
- it "writes Boolean values to keys that are Objects like a Hash" do
802
- store[Value.new(:objkey1)] = true
803
- store[Value.new(:objkey1)].should == true
804
- store.load(Value.new(:objkey1)).should == true
805
- end
806
-
807
- it "returns true from key? if a Object key is available" do
808
- store[Value.new(:objkey1)] = true
809
- store.key?(Value.new(:objkey1)).should == true
810
- store[Value.new(:objkey2)] = false
811
- store.key?(Value.new(:objkey2)).should == true
812
- end
813
-
814
- it "stores Boolean values with Object keys with #store" do
815
- value = true
816
- store.store(Value.new(:objkey1), value).should equal(value)
817
- store[Value.new(:objkey1)].should == true
818
- store.load(Value.new(:objkey1)).should == true
819
- end
820
-
821
- it "removes and returns a Boolean element with a Object key from the backing store via delete if it exists" do
822
- store[Value.new(:objkey1)] = true
823
- store.delete(Value.new(:objkey1)).should == true
824
- store.key?(Value.new(:objkey1)).should == false
825
- end
826
-
827
- it "overwrites existing Boolean values with Object" do
828
- store[Value.new(:objkey1)] = true
829
- store[Value.new(:objkey1)].should == true
830
- store[Value.new(:objkey1)] = false
831
- store[Value.new(:objkey1)].should == false
832
- end
833
-
834
- it "does not run the block if the Object key is available" do
835
- store[Value.new(:objkey1)] = true
836
- unaltered = "unaltered"
837
- store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
838
- unaltered.should == "unaltered"
839
- end
840
-
841
- it "fetches a Object key with a default value with fetch, if the key is available" do
842
- store[Value.new(:objkey1)] = true
843
- store.fetch(Value.new(:objkey1), false).should == true
844
- end
845
- end
846
-
847
- #################### expires_objectkey_booleanvalue ####################
848
-
849
- shared_examples_for 'expires_objectkey_booleanvalue' do
850
- it 'should support expires on store and #[]' do
851
- store.store(Value.new(:objkey1), true, :expires => 2)
852
- store[Value.new(:objkey1)].should == true
853
- sleep 1
854
- store[Value.new(:objkey1)].should == true
855
- sleep 2
856
- store[Value.new(:objkey1)].should == nil
857
- end
858
-
859
- it 'should support expires on store and load' do
860
- store.store(Value.new(:objkey1), true, :expires => 2)
861
- store.load(Value.new(:objkey1)).should == true
862
- sleep 1
863
- store.load(Value.new(:objkey1)).should == true
864
- sleep 2
865
- store.load(Value.new(:objkey1)).should == nil
866
- end
867
-
868
- it 'should support expires on store and key?' do
869
- store.store(Value.new(:objkey1), true, :expires => 2)
870
- store.key?(Value.new(:objkey1)).should == true
871
- sleep 1
872
- store.key?(Value.new(:objkey1)).should == true
873
- sleep 2
874
- store.key?(Value.new(:objkey1)).should == false
875
- end
876
-
877
- it 'should support updating the expiration time in load' do
878
- store.store(Value.new(:objkey2), false, :expires => 2)
879
- store[Value.new(:objkey2)].should == false
880
- sleep 1
881
- store.load(Value.new(:objkey2), :expires => 3).should == false
882
- store[Value.new(:objkey2)].should == false
883
- sleep 1
884
- store[Value.new(:objkey2)].should == false
885
- sleep 3
886
- store[Value.new(:objkey2)].should == nil
887
- end
888
-
889
- it 'should support updating the expiration time in key?' do
890
- store.store(Value.new(:objkey2), false, :expires => 2)
891
- store[Value.new(:objkey2)].should == false
892
- sleep 1
893
- store.key?(Value.new(:objkey2), :expires => 3).should be_true
894
- store[Value.new(:objkey2)].should == false
895
- sleep 1
896
- store[Value.new(:objkey2)].should == false
897
- sleep 3
898
- store[Value.new(:objkey2)].should == nil
899
- end
900
-
901
- it 'should support updating the expiration time in fetch' do
902
- store.store(Value.new(:objkey1), true, :expires => 2)
903
- store[Value.new(:objkey1)].should == true
904
- sleep 1
905
- store.fetch(Value.new(:objkey1), nil, :expires => 3).should == true
906
- store[Value.new(:objkey1)].should == true
907
- sleep 1
908
- store[Value.new(:objkey1)].should == true
909
- sleep 3
910
- store[Value.new(:objkey1)].should == nil
911
- end
912
-
913
- it 'should respect expires in delete' do
914
- store.store(Value.new(:objkey2), false, :expires => 2)
915
- store[Value.new(:objkey2)].should == false
916
- sleep 1
917
- store[Value.new(:objkey2)].should == false
918
- sleep 2
919
- store.delete(Value.new(:objkey2)).should == nil
920
- end
921
- end
922
-
923
- #################### null_objectkey_stringvalue ####################
924
-
925
- shared_examples_for 'null_objectkey_stringvalue' do
926
- it "reads from keys that are Objects like a Hash" do
927
- store[Value.new(:objkey1)].should == nil
928
- store.load(Value.new(:objkey1)).should == nil
929
- end
930
-
931
- it "guarantees that the same String value is returned when setting a Object key" do
932
- value = "strval1"
933
- (store[Value.new(:objkey1)] = value).should equal(value)
934
- end
935
-
936
- it "returns false from key? if a Object key is not available" do
937
- store.key?(Value.new(:objkey1)).should == false
938
- end
939
-
940
- it "returns nil from delete if an element for a Object key does not exist" do
941
- store.delete(Value.new(:objkey1)).should == nil
942
- end
943
-
944
- it "removes all Object keys from the store with clear" do
945
- store[Value.new(:objkey1)] = "strval1"
946
- store[Value.new(:objkey2)] = "strval2"
947
- store.clear.should equal(store)
948
- store.key?(Value.new(:objkey1)).should_not == true
949
- store.key?(Value.new(:objkey2)).should_not == true
950
- end
951
-
952
- it "fetches a Object key with a default value with fetch, if the key is not available" do
953
- store.fetch(Value.new(:objkey1), "strval1").should == "strval1"
954
- end
955
-
956
- it "fetches a Object key with a block with fetch, if the key is not available" do
957
- key = Value.new(:objkey1)
958
- value = "strval1"
959
- store.fetch(key) do |k|
960
- k.should equal(key)
961
- value
962
- end.should equal(value)
963
- end
964
-
965
- it 'should accept options' do
966
- store.key?(Value.new(:objkey1), :option1 => 1).should == false
967
- store.load(Value.new(:objkey1), :option2 => 2).should == nil
968
- store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
969
- store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
970
- store.delete(Value.new(:objkey1), :option4 => 4).should == nil
971
- store.clear(:option5 => 5).should equal(store)
972
- store.store(Value.new(:objkey1), "strval1", :option6 => 6).should == "strval1"
973
- end
974
- end
975
-
976
- #################### store_objectkey_stringvalue ####################
977
-
978
- shared_examples_for 'store_objectkey_stringvalue' do
979
- it "writes String values to keys that are Objects like a Hash" do
980
- store[Value.new(:objkey1)] = "strval1"
981
- store[Value.new(:objkey1)].should == "strval1"
982
- store.load(Value.new(:objkey1)).should == "strval1"
983
- end
984
-
985
- it "returns true from key? if a Object key is available" do
986
- store[Value.new(:objkey1)] = "strval1"
987
- store.key?(Value.new(:objkey1)).should == true
988
- store[Value.new(:objkey2)] = "strval2"
989
- store.key?(Value.new(:objkey2)).should == true
990
- end
991
-
992
- it "stores String values with Object keys with #store" do
993
- value = "strval1"
994
- store.store(Value.new(:objkey1), value).should equal(value)
995
- store[Value.new(:objkey1)].should == "strval1"
996
- store.load(Value.new(:objkey1)).should == "strval1"
997
- end
998
-
999
- it "removes and returns a String element with a Object key from the backing store via delete if it exists" do
1000
- store[Value.new(:objkey1)] = "strval1"
1001
- store.delete(Value.new(:objkey1)).should == "strval1"
1002
- store.key?(Value.new(:objkey1)).should == false
1003
- end
1004
-
1005
- it "overwrites existing String values with Object" do
1006
- store[Value.new(:objkey1)] = "strval1"
1007
- store[Value.new(:objkey1)].should == "strval1"
1008
- store[Value.new(:objkey1)] = "strval2"
1009
- store[Value.new(:objkey1)].should == "strval2"
1010
- end
1011
-
1012
- it "does not run the block if the Object key is available" do
1013
- store[Value.new(:objkey1)] = "strval1"
1014
- unaltered = "unaltered"
1015
- store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
1016
- unaltered.should == "unaltered"
1017
- end
1018
-
1019
- it "fetches a Object key with a default value with fetch, if the key is available" do
1020
- store[Value.new(:objkey1)] = "strval1"
1021
- store.fetch(Value.new(:objkey1), "strval2").should == "strval1"
1022
- end
1023
- end
1024
-
1025
- #################### returndifferent_objectkey_stringvalue ####################
1026
-
1027
- shared_examples_for 'returndifferent_objectkey_stringvalue' do
1028
- it "guarantees that a different String value is retrieved from the Object key" do
1029
- value = "strval1"
1030
- store[Value.new(:objkey1)] = "strval1"
1031
- store[Value.new(:objkey1)].should_not be_equal("strval1")
1032
- end
1033
- end
1034
-
1035
- #################### expires_objectkey_stringvalue ####################
1036
-
1037
- shared_examples_for 'expires_objectkey_stringvalue' do
1038
- it 'should support expires on store and #[]' do
1039
- store.store(Value.new(:objkey1), "strval1", :expires => 2)
1040
- store[Value.new(:objkey1)].should == "strval1"
1041
- sleep 1
1042
- store[Value.new(:objkey1)].should == "strval1"
1043
- sleep 2
1044
- store[Value.new(:objkey1)].should == nil
1045
- end
1046
-
1047
- it 'should support expires on store and load' do
1048
- store.store(Value.new(:objkey1), "strval1", :expires => 2)
1049
- store.load(Value.new(:objkey1)).should == "strval1"
1050
- sleep 1
1051
- store.load(Value.new(:objkey1)).should == "strval1"
1052
- sleep 2
1053
- store.load(Value.new(:objkey1)).should == nil
1054
- end
1055
-
1056
- it 'should support expires on store and key?' do
1057
- store.store(Value.new(:objkey1), "strval1", :expires => 2)
1058
- store.key?(Value.new(:objkey1)).should == true
1059
- sleep 1
1060
- store.key?(Value.new(:objkey1)).should == true
1061
- sleep 2
1062
- store.key?(Value.new(:objkey1)).should == false
1063
- end
1064
-
1065
- it 'should support updating the expiration time in load' do
1066
- store.store(Value.new(:objkey2), "strval2", :expires => 2)
1067
- store[Value.new(:objkey2)].should == "strval2"
1068
- sleep 1
1069
- store.load(Value.new(:objkey2), :expires => 3).should == "strval2"
1070
- store[Value.new(:objkey2)].should == "strval2"
1071
- sleep 1
1072
- store[Value.new(:objkey2)].should == "strval2"
1073
- sleep 3
1074
- store[Value.new(:objkey2)].should == nil
1075
- end
1076
-
1077
- it 'should support updating the expiration time in key?' do
1078
- store.store(Value.new(:objkey2), "strval2", :expires => 2)
1079
- store[Value.new(:objkey2)].should == "strval2"
1080
- sleep 1
1081
- store.key?(Value.new(:objkey2), :expires => 3).should be_true
1082
- store[Value.new(:objkey2)].should == "strval2"
1083
- sleep 1
1084
- store[Value.new(:objkey2)].should == "strval2"
1085
- sleep 3
1086
- store[Value.new(:objkey2)].should == nil
1087
- end
1088
-
1089
- it 'should support updating the expiration time in fetch' do
1090
- store.store(Value.new(:objkey1), "strval1", :expires => 2)
1091
- store[Value.new(:objkey1)].should == "strval1"
1092
- sleep 1
1093
- store.fetch(Value.new(:objkey1), nil, :expires => 3).should == "strval1"
1094
- store[Value.new(:objkey1)].should == "strval1"
1095
- sleep 1
1096
- store[Value.new(:objkey1)].should == "strval1"
1097
- sleep 3
1098
- store[Value.new(:objkey1)].should == nil
1099
- end
1100
-
1101
- it 'should respect expires in delete' do
1102
- store.store(Value.new(:objkey2), "strval2", :expires => 2)
1103
- store[Value.new(:objkey2)].should == "strval2"
1104
- sleep 1
1105
- store[Value.new(:objkey2)].should == "strval2"
1106
- sleep 2
1107
- store.delete(Value.new(:objkey2)).should == nil
1108
- end
1109
- end
1110
-
1111
- #################### null_objectkey_hashvalue ####################
1112
-
1113
- shared_examples_for 'null_objectkey_hashvalue' do
1114
- it "reads from keys that are Objects like a Hash" do
1115
- store[Value.new(:objkey1)].should == nil
1116
- store.load(Value.new(:objkey1)).should == nil
1117
- end
1118
-
1119
- it "guarantees that the same Hash value is returned when setting a Object key" do
1120
- value = {"hashval1"=>["array1", 1]}
1121
- (store[Value.new(:objkey1)] = value).should equal(value)
1122
- end
1123
-
1124
- it "returns false from key? if a Object key is not available" do
1125
- store.key?(Value.new(:objkey1)).should == false
1126
- end
1127
-
1128
- it "returns nil from delete if an element for a Object key does not exist" do
1129
- store.delete(Value.new(:objkey1)).should == nil
1130
- end
1131
-
1132
- it "removes all Object keys from the store with clear" do
1133
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1134
- store[Value.new(:objkey2)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1135
- store.clear.should equal(store)
1136
- store.key?(Value.new(:objkey1)).should_not == true
1137
- store.key?(Value.new(:objkey2)).should_not == true
1138
- end
1139
-
1140
- it "fetches a Object key with a default value with fetch, if the key is not available" do
1141
- store.fetch(Value.new(:objkey1), {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
1142
- end
1143
-
1144
- it "fetches a Object key with a block with fetch, if the key is not available" do
1145
- key = Value.new(:objkey1)
1146
- value = {"hashval1"=>["array1", 1]}
1147
- store.fetch(key) do |k|
1148
- k.should equal(key)
1149
- value
1150
- end.should equal(value)
1151
- end
1152
-
1153
- it 'should accept options' do
1154
- store.key?(Value.new(:objkey1), :option1 => 1).should == false
1155
- store.load(Value.new(:objkey1), :option2 => 2).should == nil
1156
- store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
1157
- store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
1158
- store.delete(Value.new(:objkey1), :option4 => 4).should == nil
1159
- store.clear(:option5 => 5).should equal(store)
1160
- store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
1161
- end
1162
- end
1163
-
1164
- #################### store_objectkey_hashvalue ####################
1165
-
1166
- shared_examples_for 'store_objectkey_hashvalue' do
1167
- it "writes Hash values to keys that are Objects like a Hash" do
1168
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1169
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1170
- store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1171
- end
1172
-
1173
- it "returns true from key? if a Object key is available" do
1174
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1175
- store.key?(Value.new(:objkey1)).should == true
1176
- store[Value.new(:objkey2)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1177
- store.key?(Value.new(:objkey2)).should == true
1178
- end
1179
-
1180
- it "stores Hash values with Object keys with #store" do
1181
- value = {"hashval1"=>["array1", 1]}
1182
- store.store(Value.new(:objkey1), value).should equal(value)
1183
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1184
- store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1185
- end
1186
-
1187
- it "removes and returns a Hash element with a Object key from the backing store via delete if it exists" do
1188
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1189
- store.delete(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1190
- store.key?(Value.new(:objkey1)).should == false
1191
- end
1192
-
1193
- it "overwrites existing Hash values with Object" do
1194
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1195
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1196
- store[Value.new(:objkey1)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1197
- store[Value.new(:objkey1)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1198
- end
1199
-
1200
- it "does not run the block if the Object key is available" do
1201
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1202
- unaltered = "unaltered"
1203
- store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
1204
- unaltered.should == "unaltered"
1205
- end
1206
-
1207
- it "fetches a Object key with a default value with fetch, if the key is available" do
1208
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1209
- store.fetch(Value.new(:objkey1), {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
1210
- end
1211
- end
1212
-
1213
- #################### returndifferent_objectkey_hashvalue ####################
1214
-
1215
- shared_examples_for 'returndifferent_objectkey_hashvalue' do
1216
- it "guarantees that a different Hash value is retrieved from the Object key" do
1217
- value = {"hashval1"=>["array1", 1]}
1218
- store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1219
- store[Value.new(:objkey1)].should_not be_equal({"hashval1"=>["array1", 1]})
1220
- end
1221
- end
1222
-
1223
- #################### expires_objectkey_hashvalue ####################
1224
-
1225
- shared_examples_for 'expires_objectkey_hashvalue' do
1226
- it 'should support expires on store and #[]' do
1227
- store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1228
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1229
- sleep 1
1230
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1231
- sleep 2
1232
- store[Value.new(:objkey1)].should == nil
1233
- end
1234
-
1235
- it 'should support expires on store and load' do
1236
- store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1237
- store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1238
- sleep 1
1239
- store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1240
- sleep 2
1241
- store.load(Value.new(:objkey1)).should == nil
1242
- end
1243
-
1244
- it 'should support expires on store and key?' do
1245
- store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1246
- store.key?(Value.new(:objkey1)).should == true
1247
- sleep 1
1248
- store.key?(Value.new(:objkey1)).should == true
1249
- sleep 2
1250
- store.key?(Value.new(:objkey1)).should == false
1251
- end
1252
-
1253
- it 'should support updating the expiration time in load' do
1254
- store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1255
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1256
- sleep 1
1257
- store.load(Value.new(:objkey2), :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1258
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1259
- sleep 1
1260
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1261
- sleep 3
1262
- store[Value.new(:objkey2)].should == nil
1263
- end
1264
-
1265
- it 'should support updating the expiration time in key?' do
1266
- store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1267
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1268
- sleep 1
1269
- store.key?(Value.new(:objkey2), :expires => 3).should be_true
1270
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1271
- sleep 1
1272
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1273
- sleep 3
1274
- store[Value.new(:objkey2)].should == nil
1275
- end
1276
-
1277
- it 'should support updating the expiration time in fetch' do
1278
- store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1279
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1280
- sleep 1
1281
- store.fetch(Value.new(:objkey1), nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
1282
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1283
- sleep 1
1284
- store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1285
- sleep 3
1286
- store[Value.new(:objkey1)].should == nil
1287
- end
1288
-
1289
- it 'should respect expires in delete' do
1290
- store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1291
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1292
- sleep 1
1293
- store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1294
- sleep 2
1295
- store.delete(Value.new(:objkey2)).should == nil
1296
- end
1297
- end
1298
-
1299
- #################### null_objectkey_objectvalue ####################
1300
-
1301
- shared_examples_for 'null_objectkey_objectvalue' do
1302
- it "reads from keys that are Objects like a Hash" do
1303
- store[Value.new(:objkey1)].should == nil
1304
- store.load(Value.new(:objkey1)).should == nil
1305
- end
1306
-
1307
- it "guarantees that the same Object value is returned when setting a Object key" do
1308
- value = Value.new(:objval1)
1309
- (store[Value.new(:objkey1)] = value).should equal(value)
1310
- end
1311
-
1312
- it "returns false from key? if a Object key is not available" do
1313
- store.key?(Value.new(:objkey1)).should == false
1314
- end
1315
-
1316
- it "returns nil from delete if an element for a Object key does not exist" do
1317
- store.delete(Value.new(:objkey1)).should == nil
1318
- end
1319
-
1320
- it "removes all Object keys from the store with clear" do
1321
- store[Value.new(:objkey1)] = Value.new(:objval1)
1322
- store[Value.new(:objkey2)] = Value.new(:objval2)
1323
- store.clear.should equal(store)
1324
- store.key?(Value.new(:objkey1)).should_not == true
1325
- store.key?(Value.new(:objkey2)).should_not == true
1326
- end
1327
-
1328
- it "fetches a Object key with a default value with fetch, if the key is not available" do
1329
- store.fetch(Value.new(:objkey1), Value.new(:objval1)).should == Value.new(:objval1)
1330
- end
1331
-
1332
- it "fetches a Object key with a block with fetch, if the key is not available" do
1333
- key = Value.new(:objkey1)
1334
- value = Value.new(:objval1)
1335
- store.fetch(key) do |k|
1336
- k.should equal(key)
1337
- value
1338
- end.should equal(value)
1339
- end
1340
-
1341
- it 'should accept options' do
1342
- store.key?(Value.new(:objkey1), :option1 => 1).should == false
1343
- store.load(Value.new(:objkey1), :option2 => 2).should == nil
1344
- store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
1345
- store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
1346
- store.delete(Value.new(:objkey1), :option4 => 4).should == nil
1347
- store.clear(:option5 => 5).should equal(store)
1348
- store.store(Value.new(:objkey1), Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
1349
- end
1350
- end
1351
-
1352
- #################### store_objectkey_objectvalue ####################
1353
-
1354
- shared_examples_for 'store_objectkey_objectvalue' do
1355
- it "writes Object values to keys that are Objects like a Hash" do
1356
- store[Value.new(:objkey1)] = Value.new(:objval1)
1357
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1358
- store.load(Value.new(:objkey1)).should == Value.new(:objval1)
1359
- end
1360
-
1361
- it "returns true from key? if a Object key is available" do
1362
- store[Value.new(:objkey1)] = Value.new(:objval1)
1363
- store.key?(Value.new(:objkey1)).should == true
1364
- store[Value.new(:objkey2)] = Value.new(:objval2)
1365
- store.key?(Value.new(:objkey2)).should == true
1366
- end
1367
-
1368
- it "stores Object values with Object keys with #store" do
1369
- value = Value.new(:objval1)
1370
- store.store(Value.new(:objkey1), value).should equal(value)
1371
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1372
- store.load(Value.new(:objkey1)).should == Value.new(:objval1)
1373
- end
1374
-
1375
- it "removes and returns a Object element with a Object key from the backing store via delete if it exists" do
1376
- store[Value.new(:objkey1)] = Value.new(:objval1)
1377
- store.delete(Value.new(:objkey1)).should == Value.new(:objval1)
1378
- store.key?(Value.new(:objkey1)).should == false
1379
- end
1380
-
1381
- it "overwrites existing Object values with Object" do
1382
- store[Value.new(:objkey1)] = Value.new(:objval1)
1383
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1384
- store[Value.new(:objkey1)] = Value.new(:objval2)
1385
- store[Value.new(:objkey1)].should == Value.new(:objval2)
1386
- end
1387
-
1388
- it "does not run the block if the Object key is available" do
1389
- store[Value.new(:objkey1)] = Value.new(:objval1)
1390
- unaltered = "unaltered"
1391
- store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
1392
- unaltered.should == "unaltered"
1393
- end
1394
-
1395
- it "fetches a Object key with a default value with fetch, if the key is available" do
1396
- store[Value.new(:objkey1)] = Value.new(:objval1)
1397
- store.fetch(Value.new(:objkey1), Value.new(:objval2)).should == Value.new(:objval1)
1398
- end
1399
- end
1400
-
1401
- #################### returndifferent_objectkey_objectvalue ####################
1402
-
1403
- shared_examples_for 'returndifferent_objectkey_objectvalue' do
1404
- it "guarantees that a different Object value is retrieved from the Object key" do
1405
- value = Value.new(:objval1)
1406
- store[Value.new(:objkey1)] = Value.new(:objval1)
1407
- store[Value.new(:objkey1)].should_not be_equal(Value.new(:objval1))
1408
- end
1409
- end
1410
-
1411
- #################### expires_objectkey_objectvalue ####################
1412
-
1413
- shared_examples_for 'expires_objectkey_objectvalue' do
1414
- it 'should support expires on store and #[]' do
1415
- store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
1416
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1417
- sleep 1
1418
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1419
- sleep 2
1420
- store[Value.new(:objkey1)].should == nil
1421
- end
1422
-
1423
- it 'should support expires on store and load' do
1424
- store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
1425
- store.load(Value.new(:objkey1)).should == Value.new(:objval1)
1426
- sleep 1
1427
- store.load(Value.new(:objkey1)).should == Value.new(:objval1)
1428
- sleep 2
1429
- store.load(Value.new(:objkey1)).should == nil
1430
- end
1431
-
1432
- it 'should support expires on store and key?' do
1433
- store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
1434
- store.key?(Value.new(:objkey1)).should == true
1435
- sleep 1
1436
- store.key?(Value.new(:objkey1)).should == true
1437
- sleep 2
1438
- store.key?(Value.new(:objkey1)).should == false
1439
- end
1440
-
1441
- it 'should support updating the expiration time in load' do
1442
- store.store(Value.new(:objkey2), Value.new(:objval2), :expires => 2)
1443
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1444
- sleep 1
1445
- store.load(Value.new(:objkey2), :expires => 3).should == Value.new(:objval2)
1446
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1447
- sleep 1
1448
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1449
- sleep 3
1450
- store[Value.new(:objkey2)].should == nil
1451
- end
1452
-
1453
- it 'should support updating the expiration time in key?' do
1454
- store.store(Value.new(:objkey2), Value.new(:objval2), :expires => 2)
1455
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1456
- sleep 1
1457
- store.key?(Value.new(:objkey2), :expires => 3).should be_true
1458
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1459
- sleep 1
1460
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1461
- sleep 3
1462
- store[Value.new(:objkey2)].should == nil
1463
- end
1464
-
1465
- it 'should support updating the expiration time in fetch' do
1466
- store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
1467
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1468
- sleep 1
1469
- store.fetch(Value.new(:objkey1), nil, :expires => 3).should == Value.new(:objval1)
1470
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1471
- sleep 1
1472
- store[Value.new(:objkey1)].should == Value.new(:objval1)
1473
- sleep 3
1474
- store[Value.new(:objkey1)].should == nil
1475
- end
1476
-
1477
- it 'should respect expires in delete' do
1478
- store.store(Value.new(:objkey2), Value.new(:objval2), :expires => 2)
1479
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1480
- sleep 1
1481
- store[Value.new(:objkey2)].should == Value.new(:objval2)
1482
- sleep 2
1483
- store.delete(Value.new(:objkey2)).should == nil
1484
- end
1485
- end
1486
-
1487
- #################### null_hashkey_booleanvalue ####################
1488
-
1489
- shared_examples_for 'null_hashkey_booleanvalue' do
1490
- it "reads from keys that are Hashs like a Hash" do
1491
- store[{"hashkey1"=>"hashkey2"}].should == nil
1492
- store.load({"hashkey1"=>"hashkey2"}).should == nil
1493
- end
1494
-
1495
- it "guarantees that the same Boolean value is returned when setting a Hash key" do
1496
- value = true
1497
- (store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
1498
- end
1499
-
1500
- it "returns false from key? if a Hash key is not available" do
1501
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1502
- end
1503
-
1504
- it "returns nil from delete if an element for a Hash key does not exist" do
1505
- store.delete({"hashkey1"=>"hashkey2"}).should == nil
1506
- end
1507
-
1508
- it "removes all Hash keys from the store with clear" do
1509
- store[{"hashkey1"=>"hashkey2"}] = true
1510
- store[{"hashkey3"=>"hashkey4"}] = false
1511
- store.clear.should equal(store)
1512
- store.key?({"hashkey1"=>"hashkey2"}).should_not == true
1513
- store.key?({"hashkey3"=>"hashkey4"}).should_not == true
1514
- end
1515
-
1516
- it "fetches a Hash key with a default value with fetch, if the key is not available" do
1517
- store.fetch({"hashkey1"=>"hashkey2"}, true).should == true
1518
- end
1519
-
1520
- it "fetches a Hash key with a block with fetch, if the key is not available" do
1521
- key = {"hashkey1"=>"hashkey2"}
1522
- value = true
1523
- store.fetch(key) do |k|
1524
- k.should equal(key)
1525
- value
1526
- end.should equal(value)
1527
- end
1528
-
1529
- it 'should accept options' do
1530
- store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
1531
- store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
1532
- store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
1533
- store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
1534
- store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
1535
- store.clear(:option5 => 5).should equal(store)
1536
- store.store({"hashkey1"=>"hashkey2"}, true, :option6 => 6).should == true
1537
- end
1538
- end
1539
-
1540
- #################### store_hashkey_booleanvalue ####################
1541
-
1542
- shared_examples_for 'store_hashkey_booleanvalue' do
1543
- it "writes Boolean values to keys that are Hashs like a Hash" do
1544
- store[{"hashkey1"=>"hashkey2"}] = true
1545
- store[{"hashkey1"=>"hashkey2"}].should == true
1546
- store.load({"hashkey1"=>"hashkey2"}).should == true
1547
- end
1548
-
1549
- it "returns true from key? if a Hash key is available" do
1550
- store[{"hashkey1"=>"hashkey2"}] = true
1551
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1552
- store[{"hashkey3"=>"hashkey4"}] = false
1553
- store.key?({"hashkey3"=>"hashkey4"}).should == true
1554
- end
1555
-
1556
- it "stores Boolean values with Hash keys with #store" do
1557
- value = true
1558
- store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
1559
- store[{"hashkey1"=>"hashkey2"}].should == true
1560
- store.load({"hashkey1"=>"hashkey2"}).should == true
1561
- end
1562
-
1563
- it "removes and returns a Boolean element with a Hash key from the backing store via delete if it exists" do
1564
- store[{"hashkey1"=>"hashkey2"}] = true
1565
- store.delete({"hashkey1"=>"hashkey2"}).should == true
1566
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1567
- end
1568
-
1569
- it "overwrites existing Boolean values with Hash" do
1570
- store[{"hashkey1"=>"hashkey2"}] = true
1571
- store[{"hashkey1"=>"hashkey2"}].should == true
1572
- store[{"hashkey1"=>"hashkey2"}] = false
1573
- store[{"hashkey1"=>"hashkey2"}].should == false
1574
- end
1575
-
1576
- it "does not run the block if the Hash key is available" do
1577
- store[{"hashkey1"=>"hashkey2"}] = true
1578
- unaltered = "unaltered"
1579
- store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
1580
- unaltered.should == "unaltered"
1581
- end
1582
-
1583
- it "fetches a Hash key with a default value with fetch, if the key is available" do
1584
- store[{"hashkey1"=>"hashkey2"}] = true
1585
- store.fetch({"hashkey1"=>"hashkey2"}, false).should == true
1586
- end
1587
- end
1588
-
1589
- #################### expires_hashkey_booleanvalue ####################
1590
-
1591
- shared_examples_for 'expires_hashkey_booleanvalue' do
1592
- it 'should support expires on store and #[]' do
1593
- store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1594
- store[{"hashkey1"=>"hashkey2"}].should == true
1595
- sleep 1
1596
- store[{"hashkey1"=>"hashkey2"}].should == true
1597
- sleep 2
1598
- store[{"hashkey1"=>"hashkey2"}].should == nil
1599
- end
1600
-
1601
- it 'should support expires on store and load' do
1602
- store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1603
- store.load({"hashkey1"=>"hashkey2"}).should == true
1604
- sleep 1
1605
- store.load({"hashkey1"=>"hashkey2"}).should == true
1606
- sleep 2
1607
- store.load({"hashkey1"=>"hashkey2"}).should == nil
1608
- end
1609
-
1610
- it 'should support expires on store and key?' do
1611
- store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1612
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1613
- sleep 1
1614
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1615
- sleep 2
1616
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1617
- end
1618
-
1619
- it 'should support updating the expiration time in load' do
1620
- store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
1621
- store[{"hashkey3"=>"hashkey4"}].should == false
1622
- sleep 1
1623
- store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == false
1624
- store[{"hashkey3"=>"hashkey4"}].should == false
1625
- sleep 1
1626
- store[{"hashkey3"=>"hashkey4"}].should == false
1627
- sleep 3
1628
- store[{"hashkey3"=>"hashkey4"}].should == nil
1629
- end
1630
-
1631
- it 'should support updating the expiration time in key?' do
1632
- store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
1633
- store[{"hashkey3"=>"hashkey4"}].should == false
1634
- sleep 1
1635
- store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
1636
- store[{"hashkey3"=>"hashkey4"}].should == false
1637
- sleep 1
1638
- store[{"hashkey3"=>"hashkey4"}].should == false
1639
- sleep 3
1640
- store[{"hashkey3"=>"hashkey4"}].should == nil
1641
- end
1642
-
1643
- it 'should support updating the expiration time in fetch' do
1644
- store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1645
- store[{"hashkey1"=>"hashkey2"}].should == true
1646
- sleep 1
1647
- store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == true
1648
- store[{"hashkey1"=>"hashkey2"}].should == true
1649
- sleep 1
1650
- store[{"hashkey1"=>"hashkey2"}].should == true
1651
- sleep 3
1652
- store[{"hashkey1"=>"hashkey2"}].should == nil
1653
- end
1654
-
1655
- it 'should respect expires in delete' do
1656
- store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
1657
- store[{"hashkey3"=>"hashkey4"}].should == false
1658
- sleep 1
1659
- store[{"hashkey3"=>"hashkey4"}].should == false
1660
- sleep 2
1661
- store.delete({"hashkey3"=>"hashkey4"}).should == nil
1662
- end
1663
- end
1664
-
1665
- #################### null_hashkey_stringvalue ####################
1666
-
1667
- shared_examples_for 'null_hashkey_stringvalue' do
1668
- it "reads from keys that are Hashs like a Hash" do
1669
- store[{"hashkey1"=>"hashkey2"}].should == nil
1670
- store.load({"hashkey1"=>"hashkey2"}).should == nil
1671
- end
1672
-
1673
- it "guarantees that the same String value is returned when setting a Hash key" do
1674
- value = "strval1"
1675
- (store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
1676
- end
1677
-
1678
- it "returns false from key? if a Hash key is not available" do
1679
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1680
- end
1681
-
1682
- it "returns nil from delete if an element for a Hash key does not exist" do
1683
- store.delete({"hashkey1"=>"hashkey2"}).should == nil
1684
- end
1685
-
1686
- it "removes all Hash keys from the store with clear" do
1687
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1688
- store[{"hashkey3"=>"hashkey4"}] = "strval2"
1689
- store.clear.should equal(store)
1690
- store.key?({"hashkey1"=>"hashkey2"}).should_not == true
1691
- store.key?({"hashkey3"=>"hashkey4"}).should_not == true
1692
- end
1693
-
1694
- it "fetches a Hash key with a default value with fetch, if the key is not available" do
1695
- store.fetch({"hashkey1"=>"hashkey2"}, "strval1").should == "strval1"
1696
- end
1697
-
1698
- it "fetches a Hash key with a block with fetch, if the key is not available" do
1699
- key = {"hashkey1"=>"hashkey2"}
1700
- value = "strval1"
1701
- store.fetch(key) do |k|
1702
- k.should equal(key)
1703
- value
1704
- end.should equal(value)
1705
- end
1706
-
1707
- it 'should accept options' do
1708
- store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
1709
- store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
1710
- store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
1711
- store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
1712
- store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
1713
- store.clear(:option5 => 5).should equal(store)
1714
- store.store({"hashkey1"=>"hashkey2"}, "strval1", :option6 => 6).should == "strval1"
1715
- end
1716
- end
1717
-
1718
- #################### store_hashkey_stringvalue ####################
1719
-
1720
- shared_examples_for 'store_hashkey_stringvalue' do
1721
- it "writes String values to keys that are Hashs like a Hash" do
1722
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1723
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1724
- store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
1725
- end
1726
-
1727
- it "returns true from key? if a Hash key is available" do
1728
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1729
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1730
- store[{"hashkey3"=>"hashkey4"}] = "strval2"
1731
- store.key?({"hashkey3"=>"hashkey4"}).should == true
1732
- end
1733
-
1734
- it "stores String values with Hash keys with #store" do
1735
- value = "strval1"
1736
- store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
1737
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1738
- store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
1739
- end
1740
-
1741
- it "removes and returns a String element with a Hash key from the backing store via delete if it exists" do
1742
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1743
- store.delete({"hashkey1"=>"hashkey2"}).should == "strval1"
1744
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1745
- end
1746
-
1747
- it "overwrites existing String values with Hash" do
1748
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1749
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1750
- store[{"hashkey1"=>"hashkey2"}] = "strval2"
1751
- store[{"hashkey1"=>"hashkey2"}].should == "strval2"
1752
- end
1753
-
1754
- it "does not run the block if the Hash key is available" do
1755
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1756
- unaltered = "unaltered"
1757
- store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
1758
- unaltered.should == "unaltered"
1759
- end
1760
-
1761
- it "fetches a Hash key with a default value with fetch, if the key is available" do
1762
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1763
- store.fetch({"hashkey1"=>"hashkey2"}, "strval2").should == "strval1"
1764
- end
1765
- end
1766
-
1767
- #################### returndifferent_hashkey_stringvalue ####################
1768
-
1769
- shared_examples_for 'returndifferent_hashkey_stringvalue' do
1770
- it "guarantees that a different String value is retrieved from the Hash key" do
1771
- value = "strval1"
1772
- store[{"hashkey1"=>"hashkey2"}] = "strval1"
1773
- store[{"hashkey1"=>"hashkey2"}].should_not be_equal("strval1")
1774
- end
1775
- end
1776
-
1777
- #################### expires_hashkey_stringvalue ####################
1778
-
1779
- shared_examples_for 'expires_hashkey_stringvalue' do
1780
- it 'should support expires on store and #[]' do
1781
- store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
1782
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1783
- sleep 1
1784
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1785
- sleep 2
1786
- store[{"hashkey1"=>"hashkey2"}].should == nil
1787
- end
1788
-
1789
- it 'should support expires on store and load' do
1790
- store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
1791
- store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
1792
- sleep 1
1793
- store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
1794
- sleep 2
1795
- store.load({"hashkey1"=>"hashkey2"}).should == nil
1796
- end
1797
-
1798
- it 'should support expires on store and key?' do
1799
- store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
1800
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1801
- sleep 1
1802
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1803
- sleep 2
1804
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1805
- end
1806
-
1807
- it 'should support updating the expiration time in load' do
1808
- store.store({"hashkey3"=>"hashkey4"}, "strval2", :expires => 2)
1809
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1810
- sleep 1
1811
- store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == "strval2"
1812
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1813
- sleep 1
1814
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1815
- sleep 3
1816
- store[{"hashkey3"=>"hashkey4"}].should == nil
1817
- end
1818
-
1819
- it 'should support updating the expiration time in key?' do
1820
- store.store({"hashkey3"=>"hashkey4"}, "strval2", :expires => 2)
1821
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1822
- sleep 1
1823
- store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
1824
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1825
- sleep 1
1826
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1827
- sleep 3
1828
- store[{"hashkey3"=>"hashkey4"}].should == nil
1829
- end
1830
-
1831
- it 'should support updating the expiration time in fetch' do
1832
- store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
1833
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1834
- sleep 1
1835
- store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == "strval1"
1836
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1837
- sleep 1
1838
- store[{"hashkey1"=>"hashkey2"}].should == "strval1"
1839
- sleep 3
1840
- store[{"hashkey1"=>"hashkey2"}].should == nil
1841
- end
1842
-
1843
- it 'should respect expires in delete' do
1844
- store.store({"hashkey3"=>"hashkey4"}, "strval2", :expires => 2)
1845
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1846
- sleep 1
1847
- store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1848
- sleep 2
1849
- store.delete({"hashkey3"=>"hashkey4"}).should == nil
1850
- end
1851
- end
1852
-
1853
- #################### null_hashkey_hashvalue ####################
1854
-
1855
- shared_examples_for 'null_hashkey_hashvalue' do
1856
- it "reads from keys that are Hashs like a Hash" do
1857
- store[{"hashkey1"=>"hashkey2"}].should == nil
1858
- store.load({"hashkey1"=>"hashkey2"}).should == nil
1859
- end
1860
-
1861
- it "guarantees that the same Hash value is returned when setting a Hash key" do
1862
- value = {"hashval1"=>["array1", 1]}
1863
- (store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
1864
- end
1865
-
1866
- it "returns false from key? if a Hash key is not available" do
1867
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1868
- end
1869
-
1870
- it "returns nil from delete if an element for a Hash key does not exist" do
1871
- store.delete({"hashkey1"=>"hashkey2"}).should == nil
1872
- end
1873
-
1874
- it "removes all Hash keys from the store with clear" do
1875
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1876
- store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1877
- store.clear.should equal(store)
1878
- store.key?({"hashkey1"=>"hashkey2"}).should_not == true
1879
- store.key?({"hashkey3"=>"hashkey4"}).should_not == true
1880
- end
1881
-
1882
- it "fetches a Hash key with a default value with fetch, if the key is not available" do
1883
- store.fetch({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
1884
- end
1885
-
1886
- it "fetches a Hash key with a block with fetch, if the key is not available" do
1887
- key = {"hashkey1"=>"hashkey2"}
1888
- value = {"hashval1"=>["array1", 1]}
1889
- store.fetch(key) do |k|
1890
- k.should equal(key)
1891
- value
1892
- end.should equal(value)
1893
- end
1894
-
1895
- it 'should accept options' do
1896
- store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
1897
- store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
1898
- store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
1899
- store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
1900
- store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
1901
- store.clear(:option5 => 5).should equal(store)
1902
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
1903
- end
1904
- end
1905
-
1906
- #################### store_hashkey_hashvalue ####################
1907
-
1908
- shared_examples_for 'store_hashkey_hashvalue' do
1909
- it "writes Hash values to keys that are Hashs like a Hash" do
1910
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1911
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1912
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1913
- end
1914
-
1915
- it "returns true from key? if a Hash key is available" do
1916
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1917
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1918
- store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1919
- store.key?({"hashkey3"=>"hashkey4"}).should == true
1920
- end
1921
-
1922
- it "stores Hash values with Hash keys with #store" do
1923
- value = {"hashval1"=>["array1", 1]}
1924
- store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
1925
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1926
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1927
- end
1928
-
1929
- it "removes and returns a Hash element with a Hash key from the backing store via delete if it exists" do
1930
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1931
- store.delete({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1932
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1933
- end
1934
-
1935
- it "overwrites existing Hash values with Hash" do
1936
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1937
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1938
- store[{"hashkey1"=>"hashkey2"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1939
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1940
- end
1941
-
1942
- it "does not run the block if the Hash key is available" do
1943
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1944
- unaltered = "unaltered"
1945
- store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
1946
- unaltered.should == "unaltered"
1947
- end
1948
-
1949
- it "fetches a Hash key with a default value with fetch, if the key is available" do
1950
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1951
- store.fetch({"hashkey1"=>"hashkey2"}, {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
1952
- end
1953
- end
1954
-
1955
- #################### returndifferent_hashkey_hashvalue ####################
1956
-
1957
- shared_examples_for 'returndifferent_hashkey_hashvalue' do
1958
- it "guarantees that a different Hash value is retrieved from the Hash key" do
1959
- value = {"hashval1"=>["array1", 1]}
1960
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1961
- store[{"hashkey1"=>"hashkey2"}].should_not be_equal({"hashval1"=>["array1", 1]})
1962
- end
1963
- end
1964
-
1965
- #################### expires_hashkey_hashvalue ####################
1966
-
1967
- shared_examples_for 'expires_hashkey_hashvalue' do
1968
- it 'should support expires on store and #[]' do
1969
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
1970
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1971
- sleep 1
1972
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1973
- sleep 2
1974
- store[{"hashkey1"=>"hashkey2"}].should == nil
1975
- end
1976
-
1977
- it 'should support expires on store and load' do
1978
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
1979
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1980
- sleep 1
1981
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1982
- sleep 2
1983
- store.load({"hashkey1"=>"hashkey2"}).should == nil
1984
- end
1985
-
1986
- it 'should support expires on store and key?' do
1987
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
1988
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1989
- sleep 1
1990
- store.key?({"hashkey1"=>"hashkey2"}).should == true
1991
- sleep 2
1992
- store.key?({"hashkey1"=>"hashkey2"}).should == false
1993
- end
1994
-
1995
- it 'should support updating the expiration time in load' do
1996
- store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1997
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1998
- sleep 1
1999
- store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2000
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2001
- sleep 1
2002
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2003
- sleep 3
2004
- store[{"hashkey3"=>"hashkey4"}].should == nil
2005
- end
2006
-
2007
- it 'should support updating the expiration time in key?' do
2008
- store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
2009
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2010
- sleep 1
2011
- store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
2012
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2013
- sleep 1
2014
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2015
- sleep 3
2016
- store[{"hashkey3"=>"hashkey4"}].should == nil
2017
- end
2018
-
2019
- it 'should support updating the expiration time in fetch' do
2020
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
2021
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
2022
- sleep 1
2023
- store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
2024
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
2025
- sleep 1
2026
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
2027
- sleep 3
2028
- store[{"hashkey1"=>"hashkey2"}].should == nil
2029
- end
2030
-
2031
- it 'should respect expires in delete' do
2032
- store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
2033
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2034
- sleep 1
2035
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2036
- sleep 2
2037
- store.delete({"hashkey3"=>"hashkey4"}).should == nil
2038
- end
2039
- end
2040
-
2041
- #################### null_hashkey_objectvalue ####################
2042
-
2043
- shared_examples_for 'null_hashkey_objectvalue' do
2044
- it "reads from keys that are Hashs like a Hash" do
2045
- store[{"hashkey1"=>"hashkey2"}].should == nil
2046
- store.load({"hashkey1"=>"hashkey2"}).should == nil
2047
- end
2048
-
2049
- it "guarantees that the same Object value is returned when setting a Hash key" do
2050
- value = Value.new(:objval1)
2051
- (store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
2052
- end
2053
-
2054
- it "returns false from key? if a Hash key is not available" do
2055
- store.key?({"hashkey1"=>"hashkey2"}).should == false
2056
- end
2057
-
2058
- it "returns nil from delete if an element for a Hash key does not exist" do
2059
- store.delete({"hashkey1"=>"hashkey2"}).should == nil
2060
- end
2061
-
2062
- it "removes all Hash keys from the store with clear" do
2063
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2064
- store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
2065
- store.clear.should equal(store)
2066
- store.key?({"hashkey1"=>"hashkey2"}).should_not == true
2067
- store.key?({"hashkey3"=>"hashkey4"}).should_not == true
2068
- end
2069
-
2070
- it "fetches a Hash key with a default value with fetch, if the key is not available" do
2071
- store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval1)).should == Value.new(:objval1)
2072
- end
2073
-
2074
- it "fetches a Hash key with a block with fetch, if the key is not available" do
2075
- key = {"hashkey1"=>"hashkey2"}
2076
- value = Value.new(:objval1)
2077
- store.fetch(key) do |k|
2078
- k.should equal(key)
2079
- value
2080
- end.should equal(value)
2081
- end
2082
-
2083
- it 'should accept options' do
2084
- store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
2085
- store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
2086
- store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
2087
- store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
2088
- store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
2089
- store.clear(:option5 => 5).should equal(store)
2090
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
2091
- end
2092
- end
2093
-
2094
- #################### store_hashkey_objectvalue ####################
2095
-
2096
- shared_examples_for 'store_hashkey_objectvalue' do
2097
- it "writes Object values to keys that are Hashs like a Hash" do
2098
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2099
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2100
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
2101
- end
2102
-
2103
- it "returns true from key? if a Hash key is available" do
2104
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2105
- store.key?({"hashkey1"=>"hashkey2"}).should == true
2106
- store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
2107
- store.key?({"hashkey3"=>"hashkey4"}).should == true
2108
- end
2109
-
2110
- it "stores Object values with Hash keys with #store" do
2111
- value = Value.new(:objval1)
2112
- store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
2113
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2114
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
2115
- end
2116
-
2117
- it "removes and returns a Object element with a Hash key from the backing store via delete if it exists" do
2118
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2119
- store.delete({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
2120
- store.key?({"hashkey1"=>"hashkey2"}).should == false
2121
- end
2122
-
2123
- it "overwrites existing Object values with Hash" do
2124
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2125
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2126
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval2)
2127
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval2)
2128
- end
2129
-
2130
- it "does not run the block if the Hash key is available" do
2131
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2132
- unaltered = "unaltered"
2133
- store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
2134
- unaltered.should == "unaltered"
2135
- end
2136
-
2137
- it "fetches a Hash key with a default value with fetch, if the key is available" do
2138
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2139
- store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval2)).should == Value.new(:objval1)
2140
- end
2141
- end
2142
-
2143
- #################### returndifferent_hashkey_objectvalue ####################
2144
-
2145
- shared_examples_for 'returndifferent_hashkey_objectvalue' do
2146
- it "guarantees that a different Object value is retrieved from the Hash key" do
2147
- value = Value.new(:objval1)
2148
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2149
- store[{"hashkey1"=>"hashkey2"}].should_not be_equal(Value.new(:objval1))
2150
- end
2151
- end
2152
-
2153
- #################### expires_hashkey_objectvalue ####################
2154
-
2155
- shared_examples_for 'expires_hashkey_objectvalue' do
2156
- it 'should support expires on store and #[]' do
2157
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
2158
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2159
- sleep 1
2160
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2161
- sleep 2
2162
- store[{"hashkey1"=>"hashkey2"}].should == nil
2163
- end
2164
-
2165
- it 'should support expires on store and load' do
2166
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
2167
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
2168
- sleep 1
2169
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
2170
- sleep 2
2171
- store.load({"hashkey1"=>"hashkey2"}).should == nil
2172
- end
2173
-
2174
- it 'should support expires on store and key?' do
2175
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
2176
- store.key?({"hashkey1"=>"hashkey2"}).should == true
2177
- sleep 1
2178
- store.key?({"hashkey1"=>"hashkey2"}).should == true
2179
- sleep 2
2180
- store.key?({"hashkey1"=>"hashkey2"}).should == false
2181
- end
2182
-
2183
- it 'should support updating the expiration time in load' do
2184
- store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
2185
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2186
- sleep 1
2187
- store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == Value.new(:objval2)
2188
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2189
- sleep 1
2190
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2191
- sleep 3
2192
- store[{"hashkey3"=>"hashkey4"}].should == nil
2193
- end
2194
-
2195
- it 'should support updating the expiration time in key?' do
2196
- store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
2197
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2198
- sleep 1
2199
- store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
2200
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2201
- sleep 1
2202
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2203
- sleep 3
2204
- store[{"hashkey3"=>"hashkey4"}].should == nil
2205
- end
2206
-
2207
- it 'should support updating the expiration time in fetch' do
2208
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
2209
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2210
- sleep 1
2211
- store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == Value.new(:objval1)
2212
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2213
- sleep 1
2214
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2215
- sleep 3
2216
- store[{"hashkey1"=>"hashkey2"}].should == nil
2217
- end
2218
-
2219
- it 'should respect expires in delete' do
2220
- store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
2221
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2222
- sleep 1
2223
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2224
- sleep 2
2225
- store.delete({"hashkey3"=>"hashkey4"}).should == nil
2226
- end
2227
- end
2228
-
2229
- #################### marshallable_key ####################
2230
-
2231
- shared_examples_for 'marshallable_key' do
2232
- it 'refuses to #[] from keys that cannot be marshalled' do
2233
- expect do
2234
- store[Struct.new(:foo).new(:bar)]
2235
- end.to raise_error(marshal_error)
2236
- end
2237
-
2238
- it 'refuses to load from keys that cannot be marshalled' do
2239
- expect do
2240
- store.load(Struct.new(:foo).new(:bar))
2241
- end.to raise_error(marshal_error)
2242
- end
2243
-
2244
- it 'refuses to fetch from keys that cannot be marshalled' do
2245
- expect do
2246
- store.fetch(Struct.new(:foo).new(:bar), true)
2247
- end.to raise_error(marshal_error)
2248
- end
2249
-
2250
- it 'refuses to #[]= to keys that cannot be marshalled' do
2251
- expect do
2252
- store[Struct.new(:foo).new(:bar)] = 'value'
2253
- end.to raise_error(marshal_error)
2254
- end
2255
-
2256
- it 'refuses to store to keys that cannot be marshalled' do
2257
- expect do
2258
- store.store Struct.new(:foo).new(:bar), 'value'
2259
- end.to raise_error(marshal_error)
2260
- end
2261
-
2262
- it 'refuses to check for key? if the key cannot be marshalled' do
2263
- expect do
2264
- store.key? Struct.new(:foo).new(:bar)
2265
- end.to raise_error(marshal_error)
2266
- end
2267
-
2268
- it 'refuses to delete a key if the key cannot be marshalled' do
2269
- expect do
2270
- store.delete Struct.new(:foo).new(:bar)
2271
- end.to raise_error(marshal_error)
2272
- end
2273
- end
2274
-
2275
- #################### marshallable_value ####################
2276
-
2277
- shared_examples_for 'marshallable_value' do
2278
- it 'refuses to store values that cannot be marshalled' do
2279
- expect do
2280
- store.store 'key', Struct.new(:foo).new(:bar)
2281
- end.to raise_error(marshal_error)
2282
- end
2283
- end
2284
-