ghost_dm-core 1.3.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. data/.autotest +29 -0
  2. data/.document +5 -0
  3. data/.gitignore +35 -0
  4. data/.yardopts +1 -0
  5. data/Gemfile +65 -0
  6. data/LICENSE +20 -0
  7. data/README.md +269 -0
  8. data/Rakefile +4 -0
  9. data/dm-core.gemspec +24 -0
  10. data/lib/dm-core.rb +292 -0
  11. data/lib/dm-core/adapters.rb +222 -0
  12. data/lib/dm-core/adapters/abstract_adapter.rb +237 -0
  13. data/lib/dm-core/adapters/in_memory_adapter.rb +113 -0
  14. data/lib/dm-core/associations/many_to_many.rb +499 -0
  15. data/lib/dm-core/associations/many_to_one.rb +290 -0
  16. data/lib/dm-core/associations/one_to_many.rb +348 -0
  17. data/lib/dm-core/associations/one_to_one.rb +86 -0
  18. data/lib/dm-core/associations/relationship.rb +663 -0
  19. data/lib/dm-core/backwards.rb +13 -0
  20. data/lib/dm-core/collection.rb +1515 -0
  21. data/lib/dm-core/core_ext/kernel.rb +23 -0
  22. data/lib/dm-core/core_ext/pathname.rb +6 -0
  23. data/lib/dm-core/core_ext/symbol.rb +10 -0
  24. data/lib/dm-core/identity_map.rb +7 -0
  25. data/lib/dm-core/model.rb +874 -0
  26. data/lib/dm-core/model/hook.rb +103 -0
  27. data/lib/dm-core/model/is.rb +32 -0
  28. data/lib/dm-core/model/property.rb +249 -0
  29. data/lib/dm-core/model/relationship.rb +378 -0
  30. data/lib/dm-core/model/scope.rb +89 -0
  31. data/lib/dm-core/property.rb +866 -0
  32. data/lib/dm-core/property/binary.rb +21 -0
  33. data/lib/dm-core/property/boolean.rb +20 -0
  34. data/lib/dm-core/property/class.rb +17 -0
  35. data/lib/dm-core/property/date.rb +10 -0
  36. data/lib/dm-core/property/date_time.rb +10 -0
  37. data/lib/dm-core/property/decimal.rb +36 -0
  38. data/lib/dm-core/property/discriminator.rb +44 -0
  39. data/lib/dm-core/property/float.rb +16 -0
  40. data/lib/dm-core/property/integer.rb +22 -0
  41. data/lib/dm-core/property/invalid_value_error.rb +22 -0
  42. data/lib/dm-core/property/lookup.rb +27 -0
  43. data/lib/dm-core/property/numeric.rb +38 -0
  44. data/lib/dm-core/property/object.rb +34 -0
  45. data/lib/dm-core/property/serial.rb +14 -0
  46. data/lib/dm-core/property/string.rb +38 -0
  47. data/lib/dm-core/property/text.rb +9 -0
  48. data/lib/dm-core/property/time.rb +10 -0
  49. data/lib/dm-core/property_set.rb +177 -0
  50. data/lib/dm-core/query.rb +1366 -0
  51. data/lib/dm-core/query/conditions/comparison.rb +911 -0
  52. data/lib/dm-core/query/conditions/operation.rb +721 -0
  53. data/lib/dm-core/query/direction.rb +36 -0
  54. data/lib/dm-core/query/operator.rb +35 -0
  55. data/lib/dm-core/query/path.rb +114 -0
  56. data/lib/dm-core/query/sort.rb +39 -0
  57. data/lib/dm-core/relationship_set.rb +72 -0
  58. data/lib/dm-core/repository.rb +226 -0
  59. data/lib/dm-core/resource.rb +1214 -0
  60. data/lib/dm-core/resource/persistence_state.rb +75 -0
  61. data/lib/dm-core/resource/persistence_state/clean.rb +40 -0
  62. data/lib/dm-core/resource/persistence_state/deleted.rb +30 -0
  63. data/lib/dm-core/resource/persistence_state/dirty.rb +96 -0
  64. data/lib/dm-core/resource/persistence_state/immutable.rb +34 -0
  65. data/lib/dm-core/resource/persistence_state/persisted.rb +29 -0
  66. data/lib/dm-core/resource/persistence_state/transient.rb +80 -0
  67. data/lib/dm-core/spec/lib/adapter_helpers.rb +64 -0
  68. data/lib/dm-core/spec/lib/collection_helpers.rb +21 -0
  69. data/lib/dm-core/spec/lib/counter_adapter.rb +38 -0
  70. data/lib/dm-core/spec/lib/pending_helpers.rb +50 -0
  71. data/lib/dm-core/spec/lib/spec_helper.rb +74 -0
  72. data/lib/dm-core/spec/setup.rb +174 -0
  73. data/lib/dm-core/spec/shared/adapter_spec.rb +341 -0
  74. data/lib/dm-core/spec/shared/public/property_spec.rb +229 -0
  75. data/lib/dm-core/spec/shared/resource_spec.rb +1232 -0
  76. data/lib/dm-core/spec/shared/sel_spec.rb +111 -0
  77. data/lib/dm-core/spec/shared/semipublic/property_spec.rb +176 -0
  78. data/lib/dm-core/spec/shared/semipublic/query/conditions/abstract_comparison_spec.rb +261 -0
  79. data/lib/dm-core/support/assertions.rb +8 -0
  80. data/lib/dm-core/support/chainable.rb +18 -0
  81. data/lib/dm-core/support/deprecate.rb +12 -0
  82. data/lib/dm-core/support/descendant_set.rb +89 -0
  83. data/lib/dm-core/support/equalizer.rb +48 -0
  84. data/lib/dm-core/support/ext/array.rb +22 -0
  85. data/lib/dm-core/support/ext/blank.rb +25 -0
  86. data/lib/dm-core/support/ext/hash.rb +67 -0
  87. data/lib/dm-core/support/ext/module.rb +47 -0
  88. data/lib/dm-core/support/ext/object.rb +57 -0
  89. data/lib/dm-core/support/ext/string.rb +24 -0
  90. data/lib/dm-core/support/ext/try_dup.rb +12 -0
  91. data/lib/dm-core/support/hook.rb +405 -0
  92. data/lib/dm-core/support/inflections.rb +60 -0
  93. data/lib/dm-core/support/inflector/inflections.rb +211 -0
  94. data/lib/dm-core/support/inflector/methods.rb +151 -0
  95. data/lib/dm-core/support/lazy_array.rb +451 -0
  96. data/lib/dm-core/support/local_object_space.rb +13 -0
  97. data/lib/dm-core/support/logger.rb +201 -0
  98. data/lib/dm-core/support/mash.rb +176 -0
  99. data/lib/dm-core/support/naming_conventions.rb +90 -0
  100. data/lib/dm-core/support/ordered_set.rb +380 -0
  101. data/lib/dm-core/support/subject.rb +33 -0
  102. data/lib/dm-core/support/subject_set.rb +250 -0
  103. data/lib/dm-core/version.rb +3 -0
  104. data/script/performance.rb +275 -0
  105. data/script/profile.rb +218 -0
  106. data/spec/lib/rspec_immediate_feedback_formatter.rb +54 -0
  107. data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +68 -0
  108. data/spec/public/associations/many_to_many_spec.rb +197 -0
  109. data/spec/public/associations/many_to_one_spec.rb +83 -0
  110. data/spec/public/associations/many_to_one_with_boolean_cpk_spec.rb +40 -0
  111. data/spec/public/associations/many_to_one_with_custom_fk_spec.rb +49 -0
  112. data/spec/public/associations/one_to_many_spec.rb +81 -0
  113. data/spec/public/associations/one_to_one_spec.rb +176 -0
  114. data/spec/public/associations/one_to_one_with_boolean_cpk_spec.rb +46 -0
  115. data/spec/public/collection_spec.rb +69 -0
  116. data/spec/public/finalize_spec.rb +76 -0
  117. data/spec/public/model/hook_spec.rb +246 -0
  118. data/spec/public/model/property_spec.rb +88 -0
  119. data/spec/public/model/relationship_spec.rb +1040 -0
  120. data/spec/public/model_spec.rb +462 -0
  121. data/spec/public/property/binary_spec.rb +41 -0
  122. data/spec/public/property/boolean_spec.rb +22 -0
  123. data/spec/public/property/class_spec.rb +28 -0
  124. data/spec/public/property/date_spec.rb +22 -0
  125. data/spec/public/property/date_time_spec.rb +22 -0
  126. data/spec/public/property/decimal_spec.rb +23 -0
  127. data/spec/public/property/discriminator_spec.rb +135 -0
  128. data/spec/public/property/float_spec.rb +22 -0
  129. data/spec/public/property/integer_spec.rb +22 -0
  130. data/spec/public/property/object_spec.rb +107 -0
  131. data/spec/public/property/serial_spec.rb +22 -0
  132. data/spec/public/property/string_spec.rb +22 -0
  133. data/spec/public/property/text_spec.rb +63 -0
  134. data/spec/public/property/time_spec.rb +22 -0
  135. data/spec/public/property_spec.rb +341 -0
  136. data/spec/public/resource_spec.rb +288 -0
  137. data/spec/public/sel_spec.rb +53 -0
  138. data/spec/public/setup_spec.rb +145 -0
  139. data/spec/public/shared/association_collection_shared_spec.rb +309 -0
  140. data/spec/public/shared/collection_finder_shared_spec.rb +267 -0
  141. data/spec/public/shared/collection_shared_spec.rb +1667 -0
  142. data/spec/public/shared/finder_shared_spec.rb +1629 -0
  143. data/spec/rcov.opts +6 -0
  144. data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
  145. data/spec/semipublic/adapters/in_memory_adapter_spec.rb +13 -0
  146. data/spec/semipublic/associations/many_to_many_spec.rb +94 -0
  147. data/spec/semipublic/associations/many_to_one_spec.rb +63 -0
  148. data/spec/semipublic/associations/one_to_many_spec.rb +55 -0
  149. data/spec/semipublic/associations/one_to_one_spec.rb +53 -0
  150. data/spec/semipublic/associations/relationship_spec.rb +200 -0
  151. data/spec/semipublic/associations_spec.rb +177 -0
  152. data/spec/semipublic/collection_spec.rb +110 -0
  153. data/spec/semipublic/model_spec.rb +96 -0
  154. data/spec/semipublic/property/binary_spec.rb +13 -0
  155. data/spec/semipublic/property/boolean_spec.rb +47 -0
  156. data/spec/semipublic/property/class_spec.rb +33 -0
  157. data/spec/semipublic/property/date_spec.rb +43 -0
  158. data/spec/semipublic/property/date_time_spec.rb +46 -0
  159. data/spec/semipublic/property/decimal_spec.rb +83 -0
  160. data/spec/semipublic/property/discriminator_spec.rb +19 -0
  161. data/spec/semipublic/property/float_spec.rb +82 -0
  162. data/spec/semipublic/property/integer_spec.rb +82 -0
  163. data/spec/semipublic/property/lookup_spec.rb +29 -0
  164. data/spec/semipublic/property/serial_spec.rb +13 -0
  165. data/spec/semipublic/property/string_spec.rb +13 -0
  166. data/spec/semipublic/property/text_spec.rb +31 -0
  167. data/spec/semipublic/property/time_spec.rb +50 -0
  168. data/spec/semipublic/property_spec.rb +114 -0
  169. data/spec/semipublic/query/conditions/comparison_spec.rb +1501 -0
  170. data/spec/semipublic/query/conditions/operation_spec.rb +1294 -0
  171. data/spec/semipublic/query/path_spec.rb +471 -0
  172. data/spec/semipublic/query_spec.rb +3682 -0
  173. data/spec/semipublic/resource/state/clean_spec.rb +88 -0
  174. data/spec/semipublic/resource/state/deleted_spec.rb +78 -0
  175. data/spec/semipublic/resource/state/dirty_spec.rb +162 -0
  176. data/spec/semipublic/resource/state/immutable_spec.rb +105 -0
  177. data/spec/semipublic/resource/state/transient_spec.rb +162 -0
  178. data/spec/semipublic/resource/state_spec.rb +230 -0
  179. data/spec/semipublic/resource_spec.rb +23 -0
  180. data/spec/semipublic/shared/condition_shared_spec.rb +9 -0
  181. data/spec/semipublic/shared/resource_shared_spec.rb +199 -0
  182. data/spec/semipublic/shared/resource_state_shared_spec.rb +79 -0
  183. data/spec/semipublic/shared/subject_shared_spec.rb +79 -0
  184. data/spec/spec.opts +5 -0
  185. data/spec/spec_helper.rb +38 -0
  186. data/spec/support/core_ext/hash.rb +10 -0
  187. data/spec/support/core_ext/inheritable_attributes.rb +46 -0
  188. data/spec/support/properties/huge_integer.rb +17 -0
  189. data/spec/unit/array_spec.rb +23 -0
  190. data/spec/unit/blank_spec.rb +73 -0
  191. data/spec/unit/data_mapper/ordered_set/append_spec.rb +26 -0
  192. data/spec/unit/data_mapper/ordered_set/clear_spec.rb +24 -0
  193. data/spec/unit/data_mapper/ordered_set/delete_spec.rb +28 -0
  194. data/spec/unit/data_mapper/ordered_set/each_spec.rb +19 -0
  195. data/spec/unit/data_mapper/ordered_set/empty_spec.rb +20 -0
  196. data/spec/unit/data_mapper/ordered_set/entries_spec.rb +22 -0
  197. data/spec/unit/data_mapper/ordered_set/eql_spec.rb +51 -0
  198. data/spec/unit/data_mapper/ordered_set/equal_value_spec.rb +84 -0
  199. data/spec/unit/data_mapper/ordered_set/hash_spec.rb +12 -0
  200. data/spec/unit/data_mapper/ordered_set/include_spec.rb +23 -0
  201. data/spec/unit/data_mapper/ordered_set/index_spec.rb +28 -0
  202. data/spec/unit/data_mapper/ordered_set/initialize_spec.rb +32 -0
  203. data/spec/unit/data_mapper/ordered_set/merge_spec.rb +36 -0
  204. data/spec/unit/data_mapper/ordered_set/shared/append_spec.rb +24 -0
  205. data/spec/unit/data_mapper/ordered_set/shared/clear_spec.rb +9 -0
  206. data/spec/unit/data_mapper/ordered_set/shared/delete_spec.rb +25 -0
  207. data/spec/unit/data_mapper/ordered_set/shared/each_spec.rb +17 -0
  208. data/spec/unit/data_mapper/ordered_set/shared/empty_spec.rb +9 -0
  209. data/spec/unit/data_mapper/ordered_set/shared/entries_spec.rb +9 -0
  210. data/spec/unit/data_mapper/ordered_set/shared/include_spec.rb +9 -0
  211. data/spec/unit/data_mapper/ordered_set/shared/index_spec.rb +13 -0
  212. data/spec/unit/data_mapper/ordered_set/shared/initialize_spec.rb +28 -0
  213. data/spec/unit/data_mapper/ordered_set/shared/merge_spec.rb +28 -0
  214. data/spec/unit/data_mapper/ordered_set/shared/size_spec.rb +13 -0
  215. data/spec/unit/data_mapper/ordered_set/shared/to_ary_spec.rb +11 -0
  216. data/spec/unit/data_mapper/ordered_set/size_spec.rb +27 -0
  217. data/spec/unit/data_mapper/ordered_set/to_ary_spec.rb +23 -0
  218. data/spec/unit/data_mapper/subject_set/append_spec.rb +47 -0
  219. data/spec/unit/data_mapper/subject_set/clear_spec.rb +34 -0
  220. data/spec/unit/data_mapper/subject_set/delete_spec.rb +40 -0
  221. data/spec/unit/data_mapper/subject_set/each_spec.rb +30 -0
  222. data/spec/unit/data_mapper/subject_set/empty_spec.rb +31 -0
  223. data/spec/unit/data_mapper/subject_set/entries_spec.rb +31 -0
  224. data/spec/unit/data_mapper/subject_set/get_spec.rb +34 -0
  225. data/spec/unit/data_mapper/subject_set/include_spec.rb +32 -0
  226. data/spec/unit/data_mapper/subject_set/named_spec.rb +33 -0
  227. data/spec/unit/data_mapper/subject_set/shared/append_spec.rb +18 -0
  228. data/spec/unit/data_mapper/subject_set/shared/clear_spec.rb +9 -0
  229. data/spec/unit/data_mapper/subject_set/shared/delete_spec.rb +9 -0
  230. data/spec/unit/data_mapper/subject_set/shared/each_spec.rb +9 -0
  231. data/spec/unit/data_mapper/subject_set/shared/empty_spec.rb +9 -0
  232. data/spec/unit/data_mapper/subject_set/shared/entries_spec.rb +9 -0
  233. data/spec/unit/data_mapper/subject_set/shared/get_spec.rb +9 -0
  234. data/spec/unit/data_mapper/subject_set/shared/include_spec.rb +9 -0
  235. data/spec/unit/data_mapper/subject_set/shared/named_spec.rb +9 -0
  236. data/spec/unit/data_mapper/subject_set/shared/size_spec.rb +13 -0
  237. data/spec/unit/data_mapper/subject_set/shared/to_ary_spec.rb +9 -0
  238. data/spec/unit/data_mapper/subject_set/shared/values_at_spec.rb +44 -0
  239. data/spec/unit/data_mapper/subject_set/size_spec.rb +42 -0
  240. data/spec/unit/data_mapper/subject_set/to_ary_spec.rb +34 -0
  241. data/spec/unit/data_mapper/subject_set/values_at_spec.rb +57 -0
  242. data/spec/unit/hash_spec.rb +28 -0
  243. data/spec/unit/hook_spec.rb +1235 -0
  244. data/spec/unit/inflections_spec.rb +16 -0
  245. data/spec/unit/lazy_array_spec.rb +1949 -0
  246. data/spec/unit/mash_spec.rb +312 -0
  247. data/spec/unit/module_spec.rb +71 -0
  248. data/spec/unit/object_spec.rb +38 -0
  249. data/spec/unit/try_dup_spec.rb +46 -0
  250. data/tasks/ci.rake +1 -0
  251. data/tasks/spec.rake +38 -0
  252. data/tasks/yard.rake +9 -0
  253. data/tasks/yardstick.rake +19 -0
  254. metadata +365 -0
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'dm-core/support/inflector/inflections'
3
+
4
+ describe DataMapper::Inflector do
5
+
6
+ it "should singularize 'status' correctly" do
7
+ DataMapper::Inflector.singularize('status').should eql 'status'
8
+ DataMapper::Inflector.singularize('status').should_not eql 'statu'
9
+ end
10
+
11
+ it "should singularize 'alias' correctly" do
12
+ DataMapper::Inflector.singularize('alias').should eql 'alias'
13
+ DataMapper::Inflector.singularize('alias').should_not eql 'alia'
14
+ end
15
+
16
+ end
@@ -0,0 +1,1949 @@
1
+ require 'spec_helper'
2
+ require 'dm-core/support/lazy_array'
3
+
4
+ # only needed for specs
5
+
6
+ module LazyArraySpec
7
+ module GroupMethods
8
+ def self.extended(base)
9
+ base.class_inheritable_accessor :loaded
10
+ end
11
+
12
+ def subject(&block)
13
+ let(:subject, &block)
14
+ end
15
+
16
+ def action(&block)
17
+ let(:action, &block)
18
+ end
19
+
20
+ def should_respond_to(method)
21
+ unless loaded
22
+ it { subject.should respond_to(method) }
23
+ end
24
+ end
25
+
26
+ def should_return_expected_value(&block)
27
+ it 'should return expected value' do
28
+ action.should eql(instance_eval(&block))
29
+ end
30
+ end
31
+
32
+ def should_return_subject
33
+ should_return_kind_of(LazyArray)
34
+
35
+ it 'should return self' do
36
+ action.should equal(subject)
37
+ end
38
+ end
39
+
40
+ def should_return_kind_of(klass)
41
+ it { action.should be_a_kind_of(klass) }
42
+ end
43
+
44
+ def should_return_copy
45
+ it 'should not return self' do
46
+ action.should_not equal(subject)
47
+ end
48
+
49
+ it 'should eql self' do
50
+ action.should eql(subject)
51
+ end
52
+ end
53
+
54
+ def should_return_true
55
+ it 'should return true' do
56
+ action.should be(true)
57
+ end
58
+ end
59
+
60
+ def should_return_false
61
+ it 'should return false' do
62
+ action.should be(false)
63
+ end
64
+ end
65
+
66
+ def should_return_nil
67
+ it 'should return nil' do
68
+ action.should be_nil
69
+ end
70
+ end
71
+
72
+ def should_raise_error(klass, message = nil)
73
+ it { lambda { action }.should raise_error(klass, message) }
74
+ end
75
+
76
+ def should_clear_subject
77
+ it 'should clear self' do
78
+ lambda { action }.should change(subject, :empty?).from(false).to(true)
79
+ end
80
+ end
81
+
82
+ def should_yield_to_each_entry
83
+ it 'should yield to each entry' do
84
+ lambda { action }.should change(@accumulator, :entries).from([]).to(subject.entries)
85
+ end
86
+ end
87
+
88
+ def should_not_change_subject
89
+ it 'should not change self' do
90
+ # XXX: the following does not work with Array#delete_if, even when nothing removed (ruby bug?)
91
+ #subject.freeze
92
+ #lambda { action }.should_not raise_error(RUBY_VERSION >= '1.9.0' ? RuntimeError : TypeError)
93
+ lambda { action }.should_not change(subject, :entries)
94
+ end
95
+ end
96
+
97
+ def should_be_a_kicker
98
+ unless loaded
99
+ it 'should be a kicker' do
100
+ lambda { action }.should change(subject, :loaded?).from(false).to(true)
101
+ end
102
+ end
103
+ end
104
+
105
+ def should_not_be_a_kicker
106
+ unless loaded
107
+ it 'should not be a kicker' do
108
+ subject.should_not be_loaded
109
+ lambda { action }.should_not change(subject, :loaded?)
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ [ false, true ].each do |loaded|
117
+ describe LazyArray do
118
+ extend LazyArraySpec::GroupMethods
119
+
120
+ self.loaded = loaded
121
+
122
+ # message describing the object state
123
+ state = "(#{'not ' unless loaded}loaded)"
124
+
125
+ before do
126
+ @nancy = 'nancy'
127
+ @bessie = 'bessie'
128
+ @steve = 'steve'
129
+
130
+ @lazy_array = LazyArray.new
131
+ @lazy_array.load_with { |la| la.push(@nancy, @bessie) }
132
+
133
+ @other = LazyArray.new
134
+ @other.load_with { |la| la.push(@steve) }
135
+
136
+ @lazy_array.entries if loaded
137
+ end
138
+
139
+ subject { @lazy_array }
140
+
141
+ it 'should be an Enumerable' do
142
+ (Enumerable === subject).should be(true)
143
+ end
144
+
145
+ describe 'when frozen', state do
146
+ before { subject.freeze }
147
+
148
+ it 'should still be able to kick' do
149
+ lambda { subject.entries }.should_not raise_error
150
+ end
151
+
152
+ it 'should not allow any modifications' do
153
+ lambda { subject << @steve }.should raise_error(RUBY_VERSION >= '1.9.0' ? RuntimeError : TypeError)
154
+ end
155
+ end
156
+
157
+ should_respond_to(:<<)
158
+
159
+ describe '#<<' do
160
+ action { subject << @steve }
161
+
162
+ should_return_subject
163
+ should_not_be_a_kicker
164
+
165
+ it 'should append an entry' do
166
+ (subject << @steve).should == [ @nancy, @bessie, @steve ]
167
+ end
168
+ end
169
+
170
+ should_respond_to(:any?)
171
+
172
+ describe '#any?', state do
173
+ describe 'when not provided a block' do
174
+ action { subject.any? }
175
+
176
+ describe 'when the subject has entries that are not loaded' do
177
+ should_return_true
178
+ should_be_a_kicker
179
+ should_not_change_subject
180
+ end
181
+
182
+ describe 'when the subject has entries that are prepended' do
183
+ subject { LazyArray.new.unshift(@nancy) }
184
+
185
+ should_return_true
186
+ should_not_be_a_kicker
187
+ should_not_change_subject
188
+ end
189
+
190
+ describe 'when the subject has entries that are appended' do
191
+ subject { LazyArray.new << @nancy }
192
+
193
+ should_return_true
194
+ should_not_be_a_kicker
195
+ should_not_change_subject
196
+ end
197
+
198
+ describe 'when the subject has no entries' do
199
+ subject { LazyArray.new }
200
+
201
+ should_return_false
202
+ should_be_a_kicker
203
+ should_not_change_subject
204
+ end
205
+ end
206
+
207
+ describe 'when provided a block that always returns true' do
208
+ action { subject.any? { true } }
209
+
210
+ describe 'when the subject has entries that are not loaded' do
211
+ should_return_true
212
+ should_be_a_kicker
213
+ should_not_change_subject
214
+ end
215
+
216
+ describe 'when the subject has entries that are prepended' do
217
+ subject { LazyArray.new.unshift(@nancy) }
218
+
219
+ should_return_true
220
+ should_not_be_a_kicker
221
+ should_not_change_subject
222
+ end
223
+
224
+ describe 'when the subject has entries that are appended' do
225
+ subject { LazyArray.new << @nancy }
226
+
227
+ should_return_true
228
+ should_not_be_a_kicker
229
+ should_not_change_subject
230
+ end
231
+
232
+ describe 'when the subject has no entries' do
233
+ subject { LazyArray.new }
234
+
235
+ should_return_false
236
+ should_be_a_kicker
237
+ should_not_change_subject
238
+ end
239
+ end
240
+ end
241
+
242
+ should_respond_to(:at)
243
+
244
+ describe '#at', state do
245
+ describe 'with positive index' do
246
+ action { subject.at(0) }
247
+
248
+ should_return_expected_value { @nancy }
249
+ should_be_a_kicker
250
+ should_not_change_subject
251
+ end
252
+
253
+ describe 'with positive index', 'after prepending to the LazyArray' do
254
+ before { subject.unshift(@steve) }
255
+
256
+ action { subject.at(0) }
257
+
258
+ should_return_expected_value { @steve }
259
+ should_not_be_a_kicker
260
+ should_not_change_subject
261
+ end
262
+
263
+ describe 'with negative index' do
264
+ action { subject.at(-1) }
265
+
266
+ should_return_expected_value { @bessie }
267
+ should_be_a_kicker
268
+ should_not_change_subject
269
+ end
270
+
271
+ describe 'with negative index', 'after appending to the LazyArray' do
272
+ before { subject.push(@steve) }
273
+
274
+ action { subject.at(-1) }
275
+
276
+ should_return_expected_value { @steve }
277
+ should_not_be_a_kicker
278
+ should_not_change_subject
279
+ end
280
+
281
+ describe 'with an index not within the LazyArray' do
282
+ action { subject.at(2) }
283
+
284
+ should_return_nil
285
+ should_be_a_kicker
286
+ should_not_change_subject
287
+ end
288
+ end
289
+
290
+ should_respond_to(:clear)
291
+
292
+ describe '#clear', state do
293
+ action { subject.clear }
294
+
295
+ should_return_subject
296
+ should_be_a_kicker # only marks as loadd, does not lazy load
297
+ should_clear_subject
298
+ end
299
+
300
+ [ :collect!, :map! ].each do |method|
301
+ it { @lazy_array.should respond_to(method) }
302
+
303
+ describe "##{method}", state do
304
+ before { @accumulator = [] }
305
+
306
+ action { subject.send(method) { |e| @accumulator << e; @steve } }
307
+
308
+ should_return_subject
309
+ should_yield_to_each_entry
310
+ should_be_a_kicker
311
+
312
+ it 'should update with the block results' do
313
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @steve, @steve ])
314
+ end
315
+ end
316
+ end
317
+
318
+ should_respond_to(:concat)
319
+
320
+ describe '#concat', state do
321
+ action { subject.concat(@other) }
322
+
323
+ should_return_subject
324
+ should_not_be_a_kicker
325
+
326
+ it 'should concatenate other Enumerable' do
327
+ subject.concat(@other).should == [ @nancy, @bessie, @steve ]
328
+ end
329
+ end
330
+
331
+ should_respond_to(:delete)
332
+
333
+ describe '#delete', state do
334
+ describe 'with an object within the LazyArray', state do
335
+ action { subject.delete(@nancy) }
336
+
337
+ should_return_expected_value { @nancy }
338
+ should_be_a_kicker
339
+
340
+ it 'should remove the matching entry' do
341
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie ])
342
+ end
343
+ end
344
+
345
+ describe 'with an object not within the LazyArray', 'without a default block' do
346
+ action { subject.delete(@steve) }
347
+
348
+ should_return_nil
349
+ should_not_change_subject
350
+ should_be_a_kicker
351
+ end
352
+
353
+ describe 'with an object not within the LazyArray', 'with a default block' do
354
+ action { subject.delete(@steve) { @steve } }
355
+
356
+ should_return_expected_value { @steve }
357
+ should_not_change_subject
358
+ should_be_a_kicker
359
+ end
360
+ end
361
+
362
+ should_respond_to(:delete_at)
363
+
364
+ describe '#delete_at', state do
365
+ describe 'with a positive index' do
366
+ action { subject.delete_at(0) }
367
+
368
+ should_return_expected_value { @nancy }
369
+ should_be_a_kicker
370
+
371
+ it 'should remove the matching entry' do
372
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie ])
373
+ end
374
+ end
375
+
376
+ describe 'with a positive index', 'after prepending to the LazyArray' do
377
+ before { subject.unshift(@steve) }
378
+
379
+ action { subject.delete_at(0) }
380
+
381
+ should_return_expected_value { @steve }
382
+ should_not_be_a_kicker
383
+
384
+ it 'should remove the matching entry' do
385
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @nancy, @bessie ])
386
+ end
387
+ end
388
+
389
+ describe 'with a negative index' do
390
+ action { subject.delete_at(-1) }
391
+
392
+ should_return_expected_value { @bessie }
393
+ should_be_a_kicker
394
+
395
+ it 'should remove the matching entry' do
396
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy ])
397
+ end
398
+ end
399
+
400
+ describe 'with a negative index', 'after appending to the LazyArray' do
401
+ before { subject.push(@steve) }
402
+
403
+ action { subject.delete_at(-1) }
404
+
405
+ should_return_expected_value { @steve }
406
+ should_not_be_a_kicker
407
+
408
+ it 'should remove the matching entry' do
409
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie ])
410
+ end
411
+ end
412
+
413
+ describe 'with an index not within the LazyArray' do
414
+ action { subject.delete_at(2) }
415
+
416
+ should_return_nil
417
+ should_not_change_subject
418
+ should_be_a_kicker
419
+ end
420
+ end
421
+
422
+ should_respond_to(:delete_if)
423
+
424
+ describe '#delete_if', state do
425
+ before { @accumulator = [] }
426
+
427
+ describe 'with a block that matches an entry' do
428
+ action { subject.delete_if { |e| @accumulator << e; true } }
429
+
430
+ should_return_subject
431
+ should_yield_to_each_entry
432
+ should_not_be_a_kicker
433
+
434
+ it 'should update with the block results' do
435
+ lambda { action }.should change(subject, :empty?).from(false).to(true)
436
+ end
437
+ end
438
+
439
+ describe 'with a block that does not match an entry' do
440
+ action { subject.delete_if { |e| @accumulator << e; false } }
441
+
442
+ should_return_subject
443
+ should_yield_to_each_entry
444
+ should_not_be_a_kicker
445
+ should_not_change_subject
446
+ end
447
+ end
448
+
449
+ should_respond_to(:dup)
450
+
451
+ describe '#dup', state do
452
+ action { subject.dup }
453
+
454
+ should_return_kind_of(LazyArray)
455
+ should_return_copy
456
+ should_not_be_a_kicker
457
+
458
+ if loaded
459
+ it 'should be loaded if subject loaded' do
460
+ action.should be_loaded
461
+ end
462
+ end
463
+ end
464
+
465
+ should_respond_to(:each)
466
+
467
+ describe '#each', state do
468
+ before { @accumulator = [] }
469
+
470
+ action { subject.each { |e| @accumulator << e } }
471
+
472
+ should_return_subject
473
+ should_yield_to_each_entry
474
+ should_be_a_kicker
475
+ should_not_change_subject
476
+ end
477
+
478
+ should_respond_to(:each_index)
479
+
480
+ describe '#each_index', state do
481
+ before { @accumulator = [] }
482
+
483
+ action { subject.each_index { |i| @accumulator << i } }
484
+
485
+ should_return_subject
486
+ should_be_a_kicker
487
+ should_not_change_subject
488
+
489
+ it 'should yield to each index' do
490
+ lambda { action }.should change(@accumulator, :entries).from([]).to([ 0, 1 ])
491
+ end
492
+ end
493
+
494
+ should_respond_to(:each_with_index)
495
+
496
+ describe '#each_with_index', state do
497
+ before { @accumulator = [] }
498
+
499
+ action { subject.each_with_index { |entry,index| @accumulator << [ entry, index ] } }
500
+
501
+ should_return_subject
502
+ should_be_a_kicker
503
+ should_not_change_subject
504
+
505
+ it 'should yield to each entry and index' do
506
+ lambda { action }.should change(@accumulator, :entries).from([]).to([ [ @nancy, 0 ], [ @bessie, 1 ] ])
507
+ end
508
+ end
509
+
510
+ should_respond_to(:empty?)
511
+
512
+ describe '#empty?', state do
513
+ describe 'when the subject has entries that are not loaded' do
514
+ action { subject.empty? }
515
+
516
+ should_return_false
517
+ should_be_a_kicker
518
+ should_not_change_subject
519
+ end
520
+
521
+ describe 'when the subject has entries that are prepended' do
522
+ subject { LazyArray.new.unshift(@nancy) }
523
+
524
+ action { subject.empty? }
525
+
526
+ should_return_false
527
+ should_not_be_a_kicker
528
+ should_not_change_subject
529
+ end
530
+
531
+ describe 'when the subject has entries that are appended' do
532
+ subject { LazyArray.new << @nancy }
533
+
534
+ action { subject.empty? }
535
+
536
+ should_return_false
537
+ should_not_be_a_kicker
538
+ should_not_change_subject
539
+ end
540
+
541
+ describe 'when the subject has no entries' do
542
+ subject { LazyArray.new }
543
+
544
+ action { subject.empty? }
545
+
546
+ should_return_true
547
+ should_be_a_kicker
548
+ should_not_change_subject
549
+ end
550
+
551
+ describe 'when the subject has only nil entries' do
552
+ subject { LazyArray.new << nil }
553
+
554
+ action { subject.empty? }
555
+
556
+ should_return_false
557
+ should_not_be_a_kicker
558
+ should_not_change_subject
559
+ end
560
+
561
+ end
562
+
563
+ [ :eql?, :== ].each do |method|
564
+ should_respond_to(method)
565
+
566
+ describe "##{method}", state do
567
+ describe 'with an Enumerable containing the same entries' do
568
+ before do
569
+ if method == :eql?
570
+ @other = LazyArray.new
571
+ @other.load_with { |la| la.push(@nancy, @bessie) }
572
+ else
573
+ @other = [ @nancy, @bessie ]
574
+ end
575
+ end
576
+
577
+ action { subject.send(method, @other) }
578
+
579
+ should_return_true
580
+ should_be_a_kicker
581
+ should_not_change_subject
582
+ end
583
+
584
+ describe 'with an Enumerable containing different entries' do
585
+ action { subject.send(method, @other) }
586
+
587
+ should_return_false
588
+ should_be_a_kicker
589
+ should_not_change_subject
590
+ end
591
+
592
+ describe 'with an Enumerable with different entries than in head' do
593
+ before { subject.unshift(@nancy) }
594
+
595
+ action { subject.send(method, [ @steve ]) }
596
+
597
+ should_return_false
598
+ should_not_be_a_kicker
599
+ should_not_change_subject
600
+ end
601
+
602
+ describe 'with an Enumerable with different entries than in tail' do
603
+ before { subject.push(@nancy) }
604
+
605
+ action { subject.send(method, [ @steve ]) }
606
+
607
+ should_return_false
608
+ should_not_be_a_kicker
609
+ should_not_change_subject
610
+ end
611
+ end
612
+ end
613
+
614
+ should_respond_to(:fetch)
615
+
616
+ describe '#fetch', state do
617
+ describe 'with positive index' do
618
+ action { subject.fetch(0) }
619
+
620
+ should_return_expected_value { @nancy }
621
+ should_be_a_kicker
622
+ should_not_change_subject
623
+ end
624
+
625
+ describe 'with positive index', 'after prepending to the LazyArray' do
626
+ before { subject.unshift(@steve) }
627
+
628
+ action { subject.fetch(0) }
629
+
630
+ should_return_expected_value { @steve }
631
+ should_not_be_a_kicker
632
+ should_not_change_subject
633
+ end
634
+
635
+ describe 'with negative index' do
636
+ action { subject.fetch(-1) }
637
+
638
+ should_return_expected_value { @bessie }
639
+ should_be_a_kicker
640
+ should_not_change_subject
641
+ end
642
+
643
+ describe 'with negative index', 'after appending to the LazyArray' do
644
+ before { subject.push(@steve) }
645
+
646
+ action { subject.fetch(-1) }
647
+
648
+ should_return_expected_value { @steve }
649
+ should_not_be_a_kicker
650
+ should_not_change_subject
651
+ end
652
+
653
+ describe 'with an index not within the LazyArray' do
654
+ action { subject.fetch(2) }
655
+
656
+ should_raise_error(IndexError)
657
+ end
658
+
659
+ describe 'with an index not within the LazyArray and default' do
660
+ action { subject.fetch(2, @steve) }
661
+
662
+ should_return_expected_value { @steve }
663
+ should_be_a_kicker
664
+ should_not_change_subject
665
+ end
666
+
667
+ describe 'with an index not within the LazyArray and default block' do
668
+ action { subject.fetch(2) { @steve } }
669
+
670
+ should_return_expected_value { @steve }
671
+ should_be_a_kicker
672
+ should_not_change_subject
673
+ end
674
+ end
675
+
676
+ should_respond_to(:freeze)
677
+
678
+ describe '#freeze', state do
679
+ action { subject.freeze }
680
+
681
+ should_return_subject
682
+ should_not_be_a_kicker
683
+
684
+ it { lambda { action }.should change(subject, :frozen?).from(false).to(true) }
685
+ end
686
+
687
+ should_respond_to(:first)
688
+
689
+ describe '#first', state do
690
+ describe 'with no arguments' do
691
+ action { subject.first }
692
+
693
+ should_return_expected_value { @nancy }
694
+ should_be_a_kicker
695
+ should_not_change_subject
696
+ end
697
+
698
+ describe 'with no arguments', 'after prepending to the LazyArray' do
699
+ before { subject.unshift(@steve) }
700
+
701
+ action { subject.first }
702
+
703
+ should_return_expected_value { @steve }
704
+ should_not_be_a_kicker
705
+ should_not_change_subject
706
+ end
707
+
708
+ describe 'with length specified' do
709
+ action { subject.first(1) }
710
+
711
+ it { action.should == [ @nancy ] }
712
+
713
+ should_be_a_kicker
714
+ should_not_change_subject
715
+ end
716
+
717
+ describe 'with length specified', 'after prepending to the LazyArray' do
718
+ before { subject.unshift(@steve) }
719
+
720
+ action { subject.first(1) }
721
+
722
+ it { action.should == [ @steve ] }
723
+
724
+ should_not_be_a_kicker
725
+ should_not_change_subject
726
+ end
727
+ end
728
+
729
+ should_respond_to(:include?)
730
+
731
+ describe '#include?', state do
732
+ describe 'with an included entry' do
733
+ action { subject.include?(@nancy) }
734
+
735
+ should_return_true
736
+ should_be_a_kicker
737
+ should_not_change_subject
738
+ end
739
+
740
+ describe 'with an included entry', 'after prepending to the LazyArray' do
741
+ before { subject.unshift(@steve) }
742
+
743
+ action { subject.include?(@steve) }
744
+
745
+ should_return_true
746
+ should_not_be_a_kicker
747
+ should_not_change_subject
748
+ end
749
+
750
+ describe 'with an included entry', 'after appending to the LazyArray' do
751
+ before { subject.push(@steve) }
752
+
753
+ action { subject.include?(@steve) }
754
+
755
+ should_return_true
756
+ should_not_be_a_kicker
757
+ should_not_change_subject
758
+ end
759
+
760
+ describe 'with an entry not included' do
761
+ action { subject.include?(@steve) }
762
+
763
+ should_return_false
764
+ should_be_a_kicker
765
+ should_not_change_subject
766
+ end
767
+ end
768
+
769
+ should_respond_to(:index)
770
+
771
+ describe '#index', state do
772
+ describe 'with an included entry' do
773
+ action { subject.index(@nancy) }
774
+
775
+ should_return_expected_value { 0 }
776
+ should_be_a_kicker
777
+ should_not_change_subject
778
+ end
779
+
780
+ describe 'with an included entry', 'after prepending to the LazyArray' do
781
+ before { subject.unshift(@steve) }
782
+
783
+ action { subject.index(@steve) }
784
+
785
+ should_return_expected_value { 0 }
786
+ should_not_be_a_kicker
787
+ should_not_change_subject
788
+ end
789
+
790
+ describe 'with an included entry', 'after appending to the LazyArray' do
791
+ before { subject.push(@steve) }
792
+
793
+ action { subject.index(@steve) }
794
+
795
+ should_return_expected_value { 2 }
796
+ should_be_a_kicker # need to kick because first index could be in lazy array
797
+ should_not_change_subject
798
+ end
799
+
800
+ describe 'with an entry not included' do
801
+ action { subject.index(@steve) }
802
+
803
+ should_return_nil
804
+ should_be_a_kicker
805
+ should_not_change_subject
806
+ end
807
+ end
808
+
809
+ should_respond_to(:insert)
810
+
811
+ describe '#insert', state do
812
+ describe 'with an index of 0' do
813
+ action { subject.insert(0, @steve) }
814
+
815
+ should_return_subject
816
+ should_not_be_a_kicker
817
+
818
+ it 'should insert the entries before the index' do
819
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @steve, @nancy, @bessie ])
820
+ end
821
+ end
822
+
823
+ describe 'with an positive index greater than the head size' do
824
+ action { subject.insert(1, @steve) }
825
+
826
+ should_return_subject
827
+ should_be_a_kicker
828
+
829
+ it 'should insert the entries before the index' do
830
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @steve, @bessie ])
831
+ end
832
+ end
833
+
834
+ describe 'with an index of -1' do
835
+ action { subject.insert(-1, @steve) }
836
+
837
+ should_return_subject
838
+ should_not_be_a_kicker
839
+
840
+ it 'should insert the entries before the index' do
841
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, @steve ])
842
+ end
843
+ end
844
+
845
+ describe 'with a negative index greater than the tail size' do
846
+ action { subject.insert(-2, @steve) }
847
+
848
+ should_return_subject
849
+ should_be_a_kicker
850
+
851
+ it 'should insert the entries before the index' do
852
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @steve, @bessie ])
853
+ end
854
+ end
855
+
856
+ describe 'with a positive index 1 greater than the maximum index of the LazyArray' do
857
+ action { subject.insert(2, @steve) }
858
+
859
+ should_return_subject
860
+ should_be_a_kicker
861
+
862
+ it 'should insert the entries before the index' do
863
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, @steve ])
864
+ end
865
+ end
866
+
867
+ describe 'with a positive index not within the LazyArray' do
868
+ action { subject.insert(3, @steve) }
869
+
870
+ should_return_subject
871
+ should_be_a_kicker
872
+
873
+ it 'should insert the entries before the index, expanding the LazyArray' do
874
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, nil, @steve ])
875
+ end
876
+ end
877
+
878
+ describe 'with a negative index 1 greater than the maximum index of the LazyArray' do
879
+ action { subject.insert(-3, @steve) }
880
+
881
+ should_return_subject
882
+ should_be_a_kicker
883
+
884
+ it 'should insert the entries before the index, expanding the LazyArray' do
885
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @steve, @nancy, @bessie ])
886
+ end
887
+ end
888
+
889
+ describe 'with a negative index not within the LazyArray' do
890
+ action { subject.insert(-4, @steve) }
891
+
892
+ should_raise_error(IndexError)
893
+ end
894
+ end
895
+
896
+ should_respond_to(:kind_of?)
897
+
898
+ describe '#kind_of' do
899
+ describe 'when provided a class that is a superclass' do
900
+ action { subject.kind_of?(Object) }
901
+
902
+ should_return_true
903
+ should_not_be_a_kicker
904
+ should_not_change_subject
905
+ end
906
+
907
+ describe 'when provided a class that is a proxy class superclass' do
908
+ action { subject.kind_of?(Array) }
909
+
910
+ should_return_true
911
+ should_not_be_a_kicker
912
+ should_not_change_subject
913
+ end
914
+
915
+ describe 'when provided a class that is not a superclass' do
916
+ action { subject.kind_of?(Hash) }
917
+
918
+ should_return_false
919
+ should_not_be_a_kicker
920
+ should_not_change_subject
921
+ end
922
+ end
923
+
924
+ should_respond_to(:last)
925
+
926
+ describe '#last', state do
927
+ describe 'with no arguments' do
928
+ action { subject.last }
929
+
930
+ should_return_expected_value { @bessie }
931
+ should_be_a_kicker
932
+ should_not_change_subject
933
+ end
934
+
935
+ describe 'with no arguments', 'after appending to the LazyArray' do
936
+ before { subject.push(@steve) }
937
+
938
+ action { subject.last }
939
+
940
+ should_return_expected_value { @steve }
941
+ should_not_be_a_kicker
942
+ should_not_change_subject
943
+ end
944
+
945
+ describe 'with length specified' do
946
+ action { subject.last(1) }
947
+
948
+ it { action.should == [ @bessie ] }
949
+
950
+ should_be_a_kicker
951
+ should_not_change_subject
952
+ end
953
+
954
+ describe 'with length specified', 'after appending to the LazyArray' do
955
+ before { subject.push(@steve) }
956
+
957
+ action { subject.last(1) }
958
+
959
+ it { action.should == [ @steve ] }
960
+
961
+ should_not_be_a_kicker
962
+ should_not_change_subject
963
+ end
964
+ end
965
+
966
+ should_respond_to(:loaded?)
967
+
968
+ describe '#loaded?' do
969
+ if loaded
970
+ describe 'when loaded' do
971
+ action { subject.loaded? }
972
+
973
+ should_return_true
974
+ should_not_change_subject
975
+ end
976
+ else
977
+ describe 'when not loaded' do
978
+ action { subject.loaded? }
979
+
980
+ should_return_false
981
+ should_not_change_subject
982
+ end
983
+ end
984
+ end
985
+
986
+ should_respond_to(:nil?)
987
+
988
+ describe '#nil?' do
989
+ action { subject.nil? }
990
+
991
+ should_return_expected_value { false }
992
+
993
+ should_not_be_a_kicker
994
+ end
995
+
996
+ should_respond_to(:pop)
997
+
998
+ describe '#pop', state do
999
+ describe 'without appending to the LazyArray' do
1000
+ action { subject.pop }
1001
+
1002
+ should_return_expected_value { @bessie }
1003
+ should_be_a_kicker
1004
+
1005
+ it 'should remove the last entry' do
1006
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy ])
1007
+ end
1008
+ end
1009
+
1010
+ describe 'after appending to the LazyArray' do
1011
+ before { subject.push(@steve) }
1012
+
1013
+ action { subject.pop }
1014
+
1015
+ should_return_expected_value { @steve }
1016
+ should_not_be_a_kicker
1017
+
1018
+ it 'should remove the last entry' do
1019
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie ])
1020
+ end
1021
+ end
1022
+ end
1023
+
1024
+ should_respond_to(:push)
1025
+
1026
+ describe '#push', state do
1027
+ action { subject.push(@steve, @steve) }
1028
+
1029
+ should_return_subject
1030
+ should_not_be_a_kicker
1031
+
1032
+ it 'should append entries' do
1033
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, @steve, @steve ])
1034
+ end
1035
+ end
1036
+
1037
+ should_respond_to(:reject!)
1038
+
1039
+ describe '#reject!', state do
1040
+ before { @accumulator = [] }
1041
+
1042
+ describe 'with a block that matches an entry' do
1043
+ action { subject.reject! { |e| @accumulator << e; true } }
1044
+
1045
+ should_return_subject
1046
+ should_yield_to_each_entry
1047
+ should_be_a_kicker
1048
+
1049
+ it 'should update with the block results' do
1050
+ lambda { action }.should change(subject, :empty?).from(false).to(true)
1051
+ end
1052
+ end
1053
+
1054
+ describe 'with a block that does not match an entry' do
1055
+ action { subject.reject! { |e| @accumulator << e; false } }
1056
+
1057
+ should_return_nil
1058
+ should_yield_to_each_entry
1059
+ should_be_a_kicker
1060
+ should_not_change_subject
1061
+ end
1062
+ end
1063
+
1064
+ should_respond_to(:replace)
1065
+
1066
+ describe '#replace' do
1067
+ action { subject.replace(@other) }
1068
+
1069
+ should_return_subject
1070
+ should_be_a_kicker
1071
+
1072
+ it 'should replace with other Enumerable' do
1073
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @steve ])
1074
+ end
1075
+ end
1076
+
1077
+ should_respond_to(:reverse)
1078
+
1079
+ describe '#reverse', state do
1080
+ action { subject.reverse }
1081
+
1082
+ should_return_kind_of(LazyArray)
1083
+ should_not_be_a_kicker
1084
+ should_not_change_subject
1085
+
1086
+ it 'should return a reversed LazyArray' do
1087
+ action.should == [ @bessie, @nancy ]
1088
+ end
1089
+ end
1090
+
1091
+ should_respond_to(:reverse!)
1092
+
1093
+ describe '#reverse!', state do
1094
+ action { subject.reverse! }
1095
+
1096
+ should_return_subject
1097
+ should_not_be_a_kicker
1098
+
1099
+ it 'should return a reversed LazyArray' do
1100
+ action.should == [ @bessie, @nancy ]
1101
+ end
1102
+ end
1103
+
1104
+ should_respond_to(:reverse_each)
1105
+
1106
+ describe '#reverse_each', state do
1107
+ before { @accumulator = [] }
1108
+
1109
+ action { subject.reverse_each { |e| @accumulator << e } }
1110
+
1111
+ should_return_subject
1112
+ should_be_a_kicker
1113
+ should_not_change_subject
1114
+
1115
+ it 'should yield to each entry' do
1116
+ lambda { action }.should change(@accumulator, :entries).from([]).to([ @bessie, @nancy ])
1117
+ end
1118
+ end
1119
+
1120
+ should_respond_to(:rindex)
1121
+
1122
+ describe '#rindex', state do
1123
+ describe 'with an included entry' do
1124
+ action { subject.rindex(@nancy) }
1125
+
1126
+ should_return_expected_value { 0 }
1127
+ should_be_a_kicker # rindex always a kicker
1128
+ should_not_change_subject
1129
+ end
1130
+
1131
+ describe 'with an included entry', 'after prepending to the LazyArray' do
1132
+ before { subject.unshift(@steve) }
1133
+
1134
+ action { subject.rindex(@steve) }
1135
+
1136
+ should_return_expected_value { 0 }
1137
+ should_be_a_kicker # rindex always a kicker
1138
+ should_not_change_subject
1139
+ end
1140
+
1141
+ describe 'with an included entry', 'after appending to the LazyArray' do
1142
+ before { subject.push(@steve) }
1143
+
1144
+ action { subject.rindex(@steve) }
1145
+
1146
+ should_return_expected_value { 2 }
1147
+ should_be_a_kicker # rindex always a kicker
1148
+ should_not_change_subject
1149
+ end
1150
+
1151
+ describe 'with an entry not included' do
1152
+ action { subject.rindex(@steve) }
1153
+
1154
+ should_return_nil
1155
+ should_be_a_kicker # rindex always a kicker
1156
+ should_not_change_subject
1157
+ end
1158
+ end
1159
+
1160
+ should_respond_to(:shift)
1161
+
1162
+ describe '#shift', state do
1163
+ describe 'without prepending to the LazyArray' do
1164
+ action { subject.shift }
1165
+
1166
+ should_return_expected_value { @nancy }
1167
+ should_be_a_kicker
1168
+
1169
+ it 'should remove the last entry' do
1170
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie ])
1171
+ end
1172
+ end
1173
+
1174
+ describe 'after prepending to the LazyArray' do
1175
+ before { subject.unshift(@steve) }
1176
+
1177
+ action { subject.shift }
1178
+
1179
+ should_return_expected_value { @steve }
1180
+ should_not_be_a_kicker
1181
+
1182
+ it 'should remove the last entry' do
1183
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @nancy, @bessie ])
1184
+ end
1185
+ end
1186
+ end
1187
+
1188
+ [ :slice, :[] ].each do |method|
1189
+ should_respond_to(method)
1190
+
1191
+ describe "##{method}", state do
1192
+ describe 'with a positive index' do
1193
+ action { subject.send(method, 0) }
1194
+
1195
+ should_return_expected_value { @nancy }
1196
+ should_be_a_kicker
1197
+ should_not_change_subject
1198
+ end
1199
+
1200
+ describe 'with a positive index', 'after prepending to the LazyArray' do
1201
+ before { subject.unshift(@steve) }
1202
+
1203
+ action { subject.send(method, 0) }
1204
+
1205
+ should_return_expected_value { @steve }
1206
+ should_not_be_a_kicker
1207
+ should_not_change_subject
1208
+ end
1209
+
1210
+ describe 'with a positive index and length' do
1211
+ action { subject.send(method, 0, 1) }
1212
+
1213
+ should_return_kind_of(Array)
1214
+ should_return_expected_value { [ @nancy ] }
1215
+ should_be_a_kicker
1216
+ should_not_change_subject
1217
+ end
1218
+
1219
+ describe 'with a positive index and length', 'after prepending to the LazyArray' do
1220
+ before { subject.unshift(@steve) }
1221
+
1222
+ action { subject.send(method, 0, 1) }
1223
+
1224
+ should_return_kind_of(Array)
1225
+ should_return_expected_value { [ @steve ] }
1226
+ should_not_be_a_kicker
1227
+ should_not_change_subject
1228
+ end
1229
+
1230
+ describe 'with a positive range' do
1231
+ action { subject.send(method, 0..0) }
1232
+
1233
+ should_return_kind_of(Array)
1234
+ should_return_expected_value { [ @nancy ] }
1235
+ should_be_a_kicker
1236
+ should_not_change_subject
1237
+ end
1238
+
1239
+ describe 'with a positive range', 'after prepending to the LazyArray' do
1240
+ before { subject.unshift(@steve) }
1241
+
1242
+ action { subject.send(method, 0..0) }
1243
+
1244
+ should_return_kind_of(Array)
1245
+ should_return_expected_value { [ @steve ] }
1246
+ should_not_be_a_kicker
1247
+ should_not_change_subject
1248
+ end
1249
+
1250
+ describe 'with a negative index' do
1251
+ action { subject.send(method, -1) }
1252
+
1253
+ should_return_expected_value { @bessie }
1254
+ should_be_a_kicker
1255
+ should_not_change_subject
1256
+ end
1257
+
1258
+ describe 'with a negative index', 'after appending to the LazyArray' do
1259
+ before { subject.push(@steve) }
1260
+
1261
+ action { subject.send(method, -1) }
1262
+
1263
+ should_return_expected_value { @steve }
1264
+ should_not_be_a_kicker
1265
+ should_not_change_subject
1266
+ end
1267
+
1268
+ describe 'with a negative index and length' do
1269
+ action { subject.send(method, -1, 1) }
1270
+
1271
+ should_return_kind_of(Array)
1272
+ should_return_expected_value { [ @bessie ] }
1273
+ should_be_a_kicker
1274
+ should_not_change_subject
1275
+ end
1276
+
1277
+ describe 'with a negative index and length', 'after appending to the LazyArray' do
1278
+ before { subject.push(@steve) }
1279
+
1280
+ action { subject.send(method, -1, 1) }
1281
+
1282
+ should_return_kind_of(Array)
1283
+ should_return_expected_value { [ @steve ] }
1284
+ should_not_be_a_kicker
1285
+ should_not_change_subject
1286
+ end
1287
+
1288
+ describe 'with a negative range' do
1289
+ action { subject.send(method, -1..-1) }
1290
+
1291
+ should_return_kind_of(Array)
1292
+ should_return_expected_value { [ @bessie ] }
1293
+ should_be_a_kicker
1294
+ should_not_change_subject
1295
+ end
1296
+
1297
+ describe 'with a negative range', 'after appending to the LazyArray' do
1298
+ before { subject.push(@steve) }
1299
+
1300
+ action { subject.send(method, -1..-1) }
1301
+
1302
+ should_return_kind_of(Array)
1303
+ should_return_expected_value { [ @steve ] }
1304
+ should_not_be_a_kicker
1305
+ should_not_change_subject
1306
+ end
1307
+
1308
+ describe 'with an index not within the LazyArray' do
1309
+ action { subject.send(method, 2) }
1310
+
1311
+ should_return_nil
1312
+ should_be_a_kicker
1313
+ should_not_change_subject
1314
+ end
1315
+
1316
+ describe 'with an index and length not within the LazyArray' do
1317
+ action { subject.send(method, 2, 1) }
1318
+
1319
+ should_return_kind_of(Array)
1320
+ should_return_expected_value { [] }
1321
+ should_be_a_kicker
1322
+ should_not_change_subject
1323
+ end
1324
+
1325
+ describe 'with a range not within the LazyArray' do
1326
+ action { subject.send(method, 2..2) }
1327
+
1328
+ should_return_kind_of(Array)
1329
+ should_return_expected_value { [] }
1330
+ should_be_a_kicker
1331
+ should_not_change_subject
1332
+ end
1333
+
1334
+ describe 'with invalid arguments' do
1335
+ action { subject.send(method, 1, 1..1) }
1336
+
1337
+ should_raise_error(ArgumentError)
1338
+ end
1339
+ end
1340
+ end
1341
+
1342
+ should_respond_to(:slice!)
1343
+
1344
+ describe '#slice!', state do
1345
+ describe 'with a positive index' do
1346
+ action { subject.slice!(0) }
1347
+
1348
+ should_return_expected_value { @nancy }
1349
+ should_be_a_kicker
1350
+
1351
+ it 'should remove the matching entry' do
1352
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie ])
1353
+ end
1354
+ end
1355
+
1356
+ describe 'with a positive index', 'after prepending to the LazyArray' do
1357
+ before { subject.unshift(@steve) }
1358
+
1359
+ action { subject.slice!(0) }
1360
+
1361
+ should_return_expected_value { @steve }
1362
+ should_not_be_a_kicker
1363
+
1364
+ it 'should remove the matching entry' do
1365
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @nancy, @bessie ])
1366
+ end
1367
+ end
1368
+
1369
+ describe 'with a positive index and length' do
1370
+ action { subject.slice!(0, 1) }
1371
+
1372
+ should_return_kind_of(Array)
1373
+ should_return_expected_value { [ @nancy ] }
1374
+ should_be_a_kicker
1375
+
1376
+ it 'should remove the matching entries' do
1377
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie ])
1378
+ end
1379
+ end
1380
+
1381
+ describe 'with a positive index and length', 'after prepending to the LazyArray' do
1382
+ before { subject.unshift(@steve) }
1383
+
1384
+ action { subject.slice!(0, 1) }
1385
+
1386
+ should_return_kind_of(Array)
1387
+ should_return_expected_value { [ @steve ] }
1388
+ should_not_be_a_kicker
1389
+
1390
+ it 'should remove the matching entries' do
1391
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @nancy, @bessie ])
1392
+ end
1393
+ end
1394
+
1395
+ describe 'with a positive range' do
1396
+ action { subject.slice!(0..0) }
1397
+
1398
+ should_return_kind_of(Array)
1399
+ should_return_expected_value { [ @nancy ] }
1400
+ should_be_a_kicker
1401
+
1402
+ it 'should remove the matching entries' do
1403
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie ])
1404
+ end
1405
+ end
1406
+
1407
+ describe 'with a positive range', 'after prepending to the LazyArray' do
1408
+ before { subject.unshift(@steve) }
1409
+
1410
+ action { subject.slice!(0..0) }
1411
+
1412
+ should_return_kind_of(Array)
1413
+ should_return_expected_value { [ @steve ] }
1414
+ should_not_be_a_kicker
1415
+
1416
+ it 'should remove the matching entry' do
1417
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @nancy, @bessie ])
1418
+ end
1419
+ end
1420
+
1421
+ describe 'with a negative index' do
1422
+ action { subject.slice!(-1) }
1423
+
1424
+ should_return_expected_value { @bessie }
1425
+ should_be_a_kicker
1426
+
1427
+ it 'should remove the matching entries' do
1428
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy ])
1429
+ end
1430
+ end
1431
+
1432
+ describe 'with a negative index', 'after appending to the LazyArray' do
1433
+ before { subject.push(@steve) }
1434
+
1435
+ action { subject.slice!(-1) }
1436
+
1437
+ should_return_expected_value { @steve }
1438
+ should_not_be_a_kicker
1439
+
1440
+ it 'should remove the matching entries' do
1441
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie ])
1442
+ end
1443
+ end
1444
+
1445
+ describe 'with a negative index and length' do
1446
+ action { subject.slice!(-1, 1) }
1447
+
1448
+ should_return_kind_of(Array)
1449
+ should_return_expected_value { [ @bessie ] }
1450
+ should_be_a_kicker
1451
+
1452
+ it 'should remove the matching entries' do
1453
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy ])
1454
+ end
1455
+ end
1456
+
1457
+ describe 'with a negative index and length', 'after appending to the LazyArray' do
1458
+ before { subject.push(@steve) }
1459
+
1460
+ action { subject.slice!(-1, 1) }
1461
+
1462
+ should_return_kind_of(Array)
1463
+ should_return_expected_value { [ @steve ] }
1464
+ should_not_be_a_kicker
1465
+
1466
+ it 'should remove the matching entries' do
1467
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie ])
1468
+ end
1469
+ end
1470
+
1471
+ describe 'with a negative range' do
1472
+ action { subject.slice!(-1..-1) }
1473
+
1474
+ should_return_kind_of(Array)
1475
+ should_return_expected_value { [ @bessie ] }
1476
+ should_be_a_kicker
1477
+
1478
+ it 'should remove the matching entries' do
1479
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy ])
1480
+ end
1481
+ end
1482
+
1483
+ describe 'with a negative range', 'after appending to the LazyArray' do
1484
+ before { subject.push(@steve) }
1485
+
1486
+ action { subject.slice!(-1..-1) }
1487
+
1488
+ should_return_kind_of(Array)
1489
+ should_return_expected_value { [ @steve ] }
1490
+ should_not_be_a_kicker
1491
+
1492
+ it 'should remove the matching entries' do
1493
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie ])
1494
+ end
1495
+ end
1496
+
1497
+ describe 'with an index not within the LazyArray' do
1498
+ action { subject.slice!(2) }
1499
+
1500
+ should_return_nil
1501
+ should_be_a_kicker
1502
+ should_not_change_subject
1503
+ end
1504
+
1505
+ describe 'with an index and length not within the LazyArray' do
1506
+ action { subject.slice!(2, 1) }
1507
+
1508
+ should_return_kind_of(Array)
1509
+ should_return_expected_value { [] }
1510
+ should_be_a_kicker
1511
+ should_not_change_subject
1512
+ end
1513
+
1514
+ describe 'with a range not within the LazyArray' do
1515
+ action { subject.slice!(2..2) }
1516
+
1517
+ should_return_kind_of(Array)
1518
+ should_return_expected_value { [] }
1519
+ should_be_a_kicker
1520
+ should_not_change_subject
1521
+ end
1522
+ end
1523
+
1524
+ should_respond_to(:sort!)
1525
+
1526
+ describe '#sort!', state do
1527
+ describe 'without a block' do
1528
+ action { subject.sort! }
1529
+
1530
+ should_return_subject
1531
+ should_be_a_kicker
1532
+
1533
+ it 'should sort the LazyArray inline using default sort order' do
1534
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie, @nancy ])
1535
+ end
1536
+ end
1537
+
1538
+ describe 'without a block' do
1539
+ action { subject.sort! { |a,b| a <=> b } }
1540
+
1541
+ should_return_subject
1542
+ should_be_a_kicker
1543
+
1544
+ it 'should sort the LazyArray inline using block' do
1545
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @bessie, @nancy ])
1546
+ end
1547
+ end
1548
+ end
1549
+
1550
+ [ :splice, :[]= ].each do |method|
1551
+ should_respond_to(method)
1552
+
1553
+ describe "##{method}", state do
1554
+ before do
1555
+ @jon = 'jon'
1556
+ end
1557
+
1558
+ describe 'with a positive index and entry' do
1559
+ action { subject.send(method, 0, @jon) }
1560
+
1561
+ should_return_expected_value { @jon }
1562
+ should_be_a_kicker
1563
+
1564
+ it 'should change the matching entry' do
1565
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @jon, @bessie ])
1566
+ end
1567
+ end
1568
+
1569
+ describe 'with a positive index', 'after prepending to the LazyArray' do
1570
+ before { subject.unshift(@steve) }
1571
+
1572
+ action { subject.send(method, 0, @jon) }
1573
+
1574
+ should_return_expected_value { @jon }
1575
+ should_not_be_a_kicker
1576
+
1577
+ it 'should change the matching entry' do
1578
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @jon, @nancy, @bessie ])
1579
+ end
1580
+ end
1581
+
1582
+ describe 'with a positive index and length' do
1583
+ action { subject.send(method, 0, 1, [ @jon ]) }
1584
+
1585
+ should_return_kind_of(Array)
1586
+ should_return_expected_value { [ @jon ] }
1587
+ should_be_a_kicker
1588
+
1589
+ it 'should change the matching entries' do
1590
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @jon, @bessie ])
1591
+ end
1592
+ end
1593
+
1594
+ describe 'with a positive index and length', 'after prepending to the LazyArray' do
1595
+ before { subject.unshift(@steve) }
1596
+
1597
+ action { subject.send(method, 0, 1, [ @jon ]) }
1598
+
1599
+ should_return_kind_of(Array)
1600
+ should_return_expected_value { [ @jon ] }
1601
+ should_not_be_a_kicker
1602
+
1603
+ it 'should change the matching entries' do
1604
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @jon, @nancy, @bessie ])
1605
+ end
1606
+ end
1607
+
1608
+ describe 'with a positive range' do
1609
+ action { subject.send(method, 0..0, [ @jon ]) }
1610
+
1611
+ should_return_kind_of(Array)
1612
+ should_return_expected_value { [ @jon ] }
1613
+ should_be_a_kicker
1614
+
1615
+ it 'should change the matching entries' do
1616
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @jon, @bessie ])
1617
+ end
1618
+ end
1619
+
1620
+ describe 'with a positive range', 'after prepending to the LazyArray' do
1621
+ before { subject.unshift(@steve) }
1622
+
1623
+ action { subject.send(method, 0..0, [ @jon ]) }
1624
+
1625
+ should_return_kind_of(Array)
1626
+ should_return_expected_value { [ @jon ] }
1627
+ should_not_be_a_kicker
1628
+
1629
+ it 'should change the matching entry' do
1630
+ lambda { action }.should change(subject, :entries).from([ @steve, @nancy, @bessie ]).to([ @jon, @nancy, @bessie ])
1631
+ end
1632
+ end
1633
+
1634
+ describe 'with a negative index' do
1635
+ action { subject.send(method, -1, @jon) }
1636
+
1637
+ should_return_expected_value { @jon }
1638
+ should_be_a_kicker
1639
+
1640
+ it 'should change the matching entries' do
1641
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @jon ])
1642
+ end
1643
+ end
1644
+
1645
+ describe 'with a negative index', 'after appending to the LazyArray' do
1646
+ before { subject.push(@steve) }
1647
+
1648
+ action { subject.send(method, -1, @jon) }
1649
+
1650
+ should_return_expected_value { @jon }
1651
+ should_not_be_a_kicker
1652
+
1653
+ it 'should change the matching entries' do
1654
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie, @jon ])
1655
+ end
1656
+ end
1657
+
1658
+ describe 'with a negative index and length' do
1659
+ action { subject.send(method, -1, 1, [ @jon ]) }
1660
+
1661
+ should_return_kind_of(Array)
1662
+ should_return_expected_value { [ @jon ] }
1663
+ should_be_a_kicker
1664
+
1665
+ it 'should change the matching entries' do
1666
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @jon ])
1667
+ end
1668
+ end
1669
+
1670
+ describe 'with a negative index and length', 'after appending to the LazyArray' do
1671
+ before { subject.push(@steve) }
1672
+
1673
+ action { subject.send(method, -1, 1, [ @jon ]) }
1674
+
1675
+ should_return_kind_of(Array)
1676
+ should_return_expected_value { [ @jon ] }
1677
+ should_not_be_a_kicker
1678
+
1679
+ it 'should change the matching entries' do
1680
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie, @jon ])
1681
+ end
1682
+ end
1683
+
1684
+ describe 'with a negative range' do
1685
+ action { subject.send(method, -1..-1, [ @jon ]) }
1686
+
1687
+ should_return_kind_of(Array)
1688
+ should_return_expected_value { [ @jon ] }
1689
+ should_be_a_kicker
1690
+
1691
+ it 'should change the matching entries' do
1692
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @jon ])
1693
+ end
1694
+ end
1695
+
1696
+ describe 'with a negative range', 'after appending to the LazyArray' do
1697
+ before { subject.push(@steve) }
1698
+
1699
+ action { subject.send(method, -1..-1, [ @jon ]) }
1700
+
1701
+ should_return_kind_of(Array)
1702
+ should_return_expected_value { [ @jon ] }
1703
+ should_not_be_a_kicker
1704
+
1705
+ it 'should change the matching entries' do
1706
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie, @steve ]).to([ @nancy, @bessie, @jon ])
1707
+ end
1708
+ end
1709
+
1710
+ describe 'with a positive index 1 greater than the maximum index of the LazyArray' do
1711
+ action { subject.send(method, 2, @jon) }
1712
+
1713
+ should_return_expected_value { @jon }
1714
+ should_be_a_kicker
1715
+
1716
+ it 'should change the matching entries' do
1717
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, @jon ])
1718
+ end
1719
+ end
1720
+
1721
+ describe 'with a positive index not within the LazyArray' do
1722
+ action { subject.send(method, 3, @jon) }
1723
+
1724
+ should_return_expected_value { @jon }
1725
+ should_be_a_kicker
1726
+
1727
+ it 'should change the matching entries' do
1728
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, nil, @jon ])
1729
+ end
1730
+ end
1731
+
1732
+ describe 'with a negative index not within the LazyArray' do
1733
+ action { subject.send(method, -3, @jon) }
1734
+
1735
+ should_raise_error(IndexError)
1736
+ end
1737
+
1738
+ describe 'with a positive index and length 1 greater than the maximum index of the LazyArray' do
1739
+ action { subject.send(method, 2, 1, [ @jon ]) }
1740
+
1741
+ should_return_kind_of(Array)
1742
+ should_return_expected_value { [ @jon ] }
1743
+ should_be_a_kicker
1744
+
1745
+ it 'should change the matching entries' do
1746
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, @jon ])
1747
+ end
1748
+ end
1749
+
1750
+ describe 'with a positive index and length not within the LazyArray' do
1751
+ action { subject.send(method, 3, 1, [ @jon ]) }
1752
+
1753
+ should_return_kind_of(Array)
1754
+ should_return_expected_value { [ @jon ] }
1755
+ should_be_a_kicker
1756
+
1757
+ it 'should change the matching entries' do
1758
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, nil, @jon ])
1759
+ end
1760
+ end
1761
+
1762
+ describe 'with a negative index and length not within the LazyArray ' do
1763
+ action { subject.send(method, -3, 1, [ @jon ]) }
1764
+
1765
+ should_raise_error(IndexError)
1766
+ end
1767
+
1768
+ describe 'with a positive range 1 greater than the maximum index of the LazyArray' do
1769
+ action { subject.send(method, 2..2, [ @jon ]) }
1770
+
1771
+ should_return_kind_of(Array)
1772
+ should_return_expected_value { [ @jon ] }
1773
+ should_be_a_kicker
1774
+
1775
+ it 'should change the matching entries' do
1776
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, @jon ])
1777
+ end
1778
+ end
1779
+
1780
+ describe 'with a positive range not within the LazyArray' do
1781
+ action { subject.send(method, 3..3, [ @jon ]) }
1782
+
1783
+ should_return_kind_of(Array)
1784
+ should_return_expected_value { [ @jon ] }
1785
+ should_be_a_kicker
1786
+
1787
+ it 'should change the matching entries' do
1788
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @nancy, @bessie, nil, @jon ])
1789
+ end
1790
+ end
1791
+
1792
+ describe 'with a negative range not within the LazyArray' do
1793
+ action { subject.send(method, -3..-3, [ @jon ]) }
1794
+
1795
+ should_raise_error(RangeError)
1796
+ end
1797
+ end
1798
+ end
1799
+
1800
+ should_respond_to(:to_a)
1801
+
1802
+ describe '#to_a', state do
1803
+ action { subject.to_a }
1804
+
1805
+ should_return_kind_of(Array)
1806
+ should_be_a_kicker
1807
+
1808
+ it 'should be equivalent to self' do
1809
+ action.should == subject
1810
+ end
1811
+ end
1812
+
1813
+ should_respond_to(:unshift)
1814
+
1815
+ describe '#unshift', state do
1816
+ action { subject.unshift(@steve, @steve) }
1817
+
1818
+ should_return_subject
1819
+ should_not_be_a_kicker
1820
+
1821
+ it 'should prepend entries' do
1822
+ lambda { action }.should change(subject, :entries).from([ @nancy, @bessie ]).to([ @steve, @steve, @nancy, @bessie ])
1823
+ end
1824
+ end
1825
+
1826
+ should_respond_to(:values_at)
1827
+
1828
+ describe '#values_at', state do
1829
+ describe 'with a positive index' do
1830
+ action { subject.values_at(0) }
1831
+
1832
+ should_return_kind_of(Array)
1833
+ should_return_expected_value { [ @nancy ] }
1834
+ should_be_a_kicker
1835
+ should_not_change_subject
1836
+ end
1837
+
1838
+ describe 'with a positive index', 'after prepending to the LazyArray' do
1839
+ before { subject.unshift(@steve) }
1840
+
1841
+ action { subject.values_at(0) }
1842
+
1843
+ should_return_kind_of(Array)
1844
+ should_return_expected_value { [ @steve ] }
1845
+ should_not_be_a_kicker
1846
+ should_not_change_subject
1847
+ end
1848
+
1849
+ describe 'with a positive range' do
1850
+ action { subject.values_at(0..0) }
1851
+
1852
+ should_return_kind_of(Array)
1853
+ should_return_expected_value { [ @nancy ] }
1854
+ should_be_a_kicker
1855
+ should_not_change_subject
1856
+ end
1857
+
1858
+ describe 'with a positive range', 'after prepending to the LazyArray' do
1859
+ before { subject.unshift(@steve) }
1860
+
1861
+ action { subject.values_at(0..0) }
1862
+
1863
+ should_return_kind_of(Array)
1864
+ should_return_expected_value { [ @steve ] }
1865
+ should_not_be_a_kicker
1866
+ should_not_change_subject
1867
+ end
1868
+
1869
+ describe 'with a negative index' do
1870
+ action { subject.values_at(-1) }
1871
+
1872
+ should_return_kind_of(Array)
1873
+ should_return_expected_value { [ @bessie ] }
1874
+ should_be_a_kicker
1875
+ should_not_change_subject
1876
+ end
1877
+
1878
+ describe 'with a negative index', 'after appending to the LazyArray' do
1879
+ before { subject.push(@steve) }
1880
+
1881
+ action { subject.values_at(-1) }
1882
+
1883
+ should_return_kind_of(Array)
1884
+ should_return_expected_value { [ @steve ] }
1885
+ should_not_be_a_kicker
1886
+ should_not_change_subject
1887
+ end
1888
+
1889
+ describe 'with a negative range' do
1890
+ action { subject.values_at(-1..-1) }
1891
+
1892
+ should_return_kind_of(Array)
1893
+ should_return_expected_value { [ @bessie ] }
1894
+ should_be_a_kicker
1895
+ should_not_change_subject
1896
+ end
1897
+
1898
+ describe 'with a negative range', 'after appending to the LazyArray' do
1899
+ before { subject.push(@steve) }
1900
+
1901
+ action { subject.values_at(-1..-1) }
1902
+
1903
+ should_return_kind_of(Array)
1904
+ should_return_expected_value { [ @steve ] }
1905
+ should_not_be_a_kicker
1906
+ should_not_change_subject
1907
+ end
1908
+
1909
+ describe 'with an index not within the LazyArray' do
1910
+ action { subject.values_at(2) }
1911
+
1912
+ should_return_kind_of(Array)
1913
+ should_return_expected_value { [ nil ] }
1914
+ should_be_a_kicker
1915
+ should_not_change_subject
1916
+ end
1917
+
1918
+ describe 'with a range not within the LazyArray' do
1919
+ action { subject.values_at(2..2) }
1920
+
1921
+ should_return_kind_of(Array)
1922
+ should_return_expected_value { [ nil ] }
1923
+ should_be_a_kicker
1924
+ should_not_change_subject
1925
+ end
1926
+ end
1927
+
1928
+ describe 'a method mixed into Array' do
1929
+ before :all do
1930
+ Enumerable.class_eval do
1931
+ remove_method :lazy_spec if instance_methods(false).any? { |m| m.to_sym == :lazy_spec }
1932
+ def lazy_spec
1933
+ true
1934
+ end
1935
+ end
1936
+ end
1937
+
1938
+ it 'should delegate to the Array' do
1939
+ subject.lazy_spec.should be(true)
1940
+ end
1941
+ end
1942
+
1943
+ describe 'an unknown method' do
1944
+ action { subject.unknown }
1945
+
1946
+ should_raise_error(NameError)
1947
+ end
1948
+ end
1949
+ end