rambling-trie 1.0.2 → 1.0.3

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/README.md +23 -7
  4. data/Rakefile +4 -0
  5. data/lib/rambling/trie.rb +27 -21
  6. data/lib/rambling/trie/comparable.rb +3 -3
  7. data/lib/rambling/trie/compressible.rb +14 -0
  8. data/lib/rambling/trie/compressor.rb +37 -24
  9. data/lib/rambling/trie/configuration/properties.rb +8 -6
  10. data/lib/rambling/trie/configuration/provider_collection.rb +34 -16
  11. data/lib/rambling/trie/container.rb +156 -36
  12. data/lib/rambling/trie/enumerable.rb +4 -4
  13. data/lib/rambling/trie/nodes.rb +11 -0
  14. data/lib/rambling/trie/nodes/compressed.rb +115 -0
  15. data/lib/rambling/trie/nodes/missing.rb +10 -0
  16. data/lib/rambling/trie/nodes/node.rb +151 -0
  17. data/lib/rambling/trie/nodes/raw.rb +89 -0
  18. data/lib/rambling/trie/readers/plain_text.rb +1 -11
  19. data/lib/rambling/trie/serializers/marshal.rb +4 -4
  20. data/lib/rambling/trie/serializers/yaml.rb +4 -4
  21. data/lib/rambling/trie/serializers/zip.rb +9 -8
  22. data/lib/rambling/trie/version.rb +1 -1
  23. data/spec/assets/test_words.es_DO.txt +1 -0
  24. data/spec/integration/rambling/trie_spec.rb +40 -35
  25. data/spec/lib/rambling/trie/comparable_spec.rb +6 -15
  26. data/spec/lib/rambling/trie/compressor_spec.rb +88 -13
  27. data/spec/lib/rambling/trie/configuration/properties_spec.rb +7 -7
  28. data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +8 -20
  29. data/spec/lib/rambling/trie/container_spec.rb +159 -168
  30. data/spec/lib/rambling/trie/enumerable_spec.rb +12 -9
  31. data/spec/lib/rambling/trie/inspectable_spec.rb +11 -11
  32. data/spec/lib/rambling/trie/nodes/compressed_spec.rb +35 -0
  33. data/spec/lib/rambling/trie/nodes/node_spec.rb +7 -0
  34. data/spec/lib/rambling/trie/nodes/raw_spec.rb +177 -0
  35. data/spec/lib/rambling/trie/serializers/file_spec.rb +4 -4
  36. data/spec/lib/rambling/trie/serializers/marshal_spec.rb +3 -7
  37. data/spec/lib/rambling/trie/serializers/yaml_spec.rb +3 -7
  38. data/spec/lib/rambling/trie/serializers/zip_spec.rb +16 -20
  39. data/spec/lib/rambling/trie/stringifyable_spec.rb +7 -8
  40. data/spec/lib/rambling/trie_spec.rb +2 -2
  41. data/spec/spec_helper.rb +3 -1
  42. data/spec/support/config.rb +4 -0
  43. data/spec/support/helpers/add_word.rb +18 -0
  44. data/spec/support/shared_examples/{a_compressable_trie.rb → a_compressible_trie.rb} +13 -3
  45. data/spec/support/shared_examples/a_serializable_trie.rb +8 -6
  46. data/spec/support/shared_examples/a_serializer.rb +6 -0
  47. data/spec/{lib/rambling/trie/node_spec.rb → support/shared_examples/a_trie_node.rb} +61 -30
  48. data/spec/{lib/rambling/trie/compressed_node_spec.rb → support/shared_examples/a_trie_node_implementation.rb} +18 -69
  49. metadata +22 -15
  50. data/lib/rambling/trie/compressable.rb +0 -14
  51. data/lib/rambling/trie/compressed_node.rb +0 -120
  52. data/lib/rambling/trie/missing_node.rb +0 -8
  53. data/lib/rambling/trie/node.rb +0 -97
  54. data/lib/rambling/trie/raw_node.rb +0 -96
  55. data/spec/lib/rambling/trie/raw_node_spec.rb +0 -389
@@ -6,7 +6,7 @@ describe Rambling::Trie::Configuration::Properties do
6
6
  describe '.new' do
7
7
  it 'configures the serializers' do
8
8
  serializers = properties.serializers
9
- expect(serializers.keys).to match_array %i(marshal yaml yml zip)
9
+ expect(serializers.formats).to match_array %i(marshal yaml yml zip)
10
10
 
11
11
  expect(serializers[:marshal]).to be_instance_of Rambling::Trie::Serializers::Marshal
12
12
  expect(serializers[:yaml]).to be_instance_of Rambling::Trie::Serializers::Yaml
@@ -16,7 +16,7 @@ describe Rambling::Trie::Configuration::Properties do
16
16
 
17
17
  it 'configures the readers' do
18
18
  readers = properties.readers
19
- expect(readers.keys).to match_array %i(txt)
19
+ expect(readers.formats).to match_array %i(txt)
20
20
 
21
21
  expect(readers[:txt]).to be_instance_of Rambling::Trie::Readers::PlainText
22
22
  end
@@ -26,7 +26,7 @@ describe Rambling::Trie::Configuration::Properties do
26
26
  end
27
27
 
28
28
  it 'configures the root_builder' do
29
- expect(properties.root_builder.call).to be_instance_of Rambling::Trie::RawNode
29
+ expect(properties.root_builder.call).to be_instance_of Rambling::Trie::Nodes::Raw
30
30
  end
31
31
  end
32
32
 
@@ -37,13 +37,13 @@ describe Rambling::Trie::Configuration::Properties do
37
37
  end
38
38
 
39
39
  it 'resets the serializers and readers to initial values' do
40
- expect(properties.serializers.keys).to include :test
41
- expect(properties.readers.keys).to include :test
40
+ expect(properties.serializers.formats).to include :test
41
+ expect(properties.readers.formats).to include :test
42
42
 
43
43
  properties.reset
44
44
 
45
- expect(properties.serializers.keys).not_to include :test
46
- expect(properties.readers.keys).not_to include :test
45
+ expect(properties.serializers.formats).not_to include :test
46
+ expect(properties.readers.formats).not_to include :test
47
47
  end
48
48
  end
49
49
  end
@@ -11,7 +11,7 @@ describe Rambling::Trie::Configuration::ProviderCollection do
11
11
 
12
12
  let(:provider_collection) do
13
13
  Rambling::Trie::Configuration::ProviderCollection.new(
14
- 'provider',
14
+ :provider,
15
15
  configured_providers,
16
16
  configured_default
17
17
  )
@@ -19,7 +19,7 @@ describe Rambling::Trie::Configuration::ProviderCollection do
19
19
 
20
20
  describe '.new' do
21
21
  it 'has a name' do
22
- expect(provider_collection.name).to eq 'provider'
22
+ expect(provider_collection.name).to eq :provider
23
23
  end
24
24
 
25
25
  it 'has the given providers' do
@@ -45,32 +45,20 @@ describe Rambling::Trie::Configuration::ProviderCollection do
45
45
 
46
46
  before do
47
47
  allow(providers) .to receive_messages(
48
- :[] => nil,
49
- :[]= => nil,
50
- keys: nil,
51
- values: nil,
48
+ :[] => 'value',
49
+ keys: %i(a b),
52
50
  )
53
51
  end
54
52
 
55
- it 'delegates #[] to providers' do
56
- provider_collection[:key]
53
+ it 'delegates `#[]` to providers' do
54
+ expect(provider_collection[:key]).to eq 'value'
57
55
  expect(providers).to have_received(:[]).with :key
58
56
  end
59
57
 
60
- it 'delegates #[]= to providers' do
61
- provider_collection[:key] = 'hello'
62
- expect(providers).to have_received(:[]=).with :key, 'hello'
63
- end
64
-
65
- it 'delegates #keys to providers' do
66
- provider_collection.keys
58
+ it 'aliases `#formats` to `providers#keys`' do
59
+ expect(provider_collection.formats).to eq %i(a b)
67
60
  expect(providers).to have_received :keys
68
61
  end
69
-
70
- it 'delegates #values to providers' do
71
- provider_collection.values
72
- expect(providers).to have_received :values
73
- end
74
62
  end
75
63
 
76
64
  describe '#add' do
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Rambling::Trie::Container do
4
4
  let(:container) { Rambling::Trie::Container.new root, compressor }
5
5
  let(:compressor) { Rambling::Trie::Compressor.new }
6
- let(:root) { Rambling::Trie::RawNode.new }
6
+ let(:root) { Rambling::Trie::Nodes::Raw.new }
7
7
 
8
8
  describe '.new' do
9
9
  it 'uses the provided node as root' do
@@ -24,40 +24,51 @@ describe Rambling::Trie::Container do
24
24
  end
25
25
 
26
26
  describe '#add' do
27
- let(:clone) { double :clone }
28
- let(:word) { double :word, clone: clone }
27
+ it 'adds the word to the root node' do
28
+ add_word container, 'hello'
29
29
 
30
- before do
31
- allow(root).to receive(:add)
30
+ expect(root.children.size).to eq 1
31
+ expect(root.to_a).to eq %w(hello)
32
32
  end
33
+ end
33
34
 
34
- it 'clones the original word' do
35
- container.add word
36
- expect(root).to have_received(:add).with clone
35
+ describe '#concat' do
36
+ it 'adds all the words to the root node' do
37
+ container.concat %w(other words)
38
+
39
+ expect(root.children.size).to eq 2
40
+ expect(root.to_a).to eq %w(other words)
41
+ end
42
+
43
+ it 'returns all the corresponding nodes' do
44
+ nodes = container.concat %w(other words)
45
+
46
+ expect(nodes.first.letter).to eq :o
47
+ expect(nodes.last.letter).to eq :w
37
48
  end
38
49
  end
39
50
 
40
51
  describe '#compress!' do
41
- let(:node) { double :node, add: nil, compressed?: false }
52
+ let(:node) { Rambling::Trie::Nodes::Compressed.new }
42
53
 
43
54
  before do
44
55
  allow(compressor).to receive(:compress).and_return node
45
- allow(root).to receive(:add)
56
+
57
+ add_word root, 'yes'
58
+ node[:yes] = Rambling::Trie::Nodes::Compressed.new
46
59
  end
47
60
 
48
61
  it 'compresses the trie using the compressor' do
49
62
  container.compress!
50
63
 
51
- expect(compressor).to have_received(:compress)
52
- .with root
64
+ expect(compressor).to have_received(:compress).with root
53
65
  end
54
66
 
55
67
  it 'changes to the root returned by the compressor' do
56
68
  container.compress!
57
- container.add 'word'
58
69
 
59
- expect(root).not_to have_received :add
60
- expect(node).to have_received :add
70
+ expect(container.root).not_to eq root
71
+ expect(container.root).to eq node
61
72
  end
62
73
 
63
74
  it 'returns itself' do
@@ -73,13 +84,57 @@ describe Rambling::Trie::Container do
73
84
  end
74
85
  end
75
86
 
87
+ describe '#compress' do
88
+ let(:node) { Rambling::Trie::Nodes::Compressed.new }
89
+
90
+ before do
91
+ allow(compressor).to receive(:compress).and_return node
92
+
93
+ add_word root, 'yes'
94
+ node[:yes] = Rambling::Trie::Nodes::Compressed.new
95
+ end
96
+
97
+ it 'compresses the trie using the compressor' do
98
+ container.compress
99
+
100
+ expect(compressor).to have_received(:compress).with root
101
+ end
102
+
103
+ it 'returns a container with the new root' do
104
+ new_container = container.compress
105
+
106
+ expect(new_container.root).not_to eq root
107
+ expect(new_container.root).to eq node
108
+ end
109
+
110
+ it 'returns a new container' do
111
+ expect(container.compress).not_to eq container
112
+ end
113
+
114
+ it 'can compress multiple times' do
115
+ container.compress
116
+ container.compress
117
+
118
+ expect(compressor).to have_received(:compress).twice
119
+ end
120
+
121
+ it 'cannot compress the result' do
122
+ new_container = container.compress
123
+ new_container.compress
124
+
125
+ expect(compressor).to have_received(:compress).once
126
+ end
127
+ end
128
+
76
129
  describe '#word?' do
130
+ let(:root) do
131
+ double :root,
132
+ compressed?: compressed,
133
+ word?: nil
134
+ end
135
+
77
136
  context 'for an uncompressed root' do
78
- let(:root) do
79
- double :root,
80
- compressed?: false,
81
- word?: nil
82
- end
137
+ let(:compressed) { true }
83
138
 
84
139
  it 'calls the root with the word characters' do
85
140
  container.word? 'words'
@@ -88,11 +143,7 @@ describe Rambling::Trie::Container do
88
143
  end
89
144
 
90
145
  context 'for a compressed root' do
91
- let(:root) do
92
- double :root,
93
- compressed?: true,
94
- word?: nil
95
- end
146
+ let(:compressed) { false }
96
147
 
97
148
  it 'calls the root with the full word' do
98
149
  container.word? 'words'
@@ -102,12 +153,14 @@ describe Rambling::Trie::Container do
102
153
  end
103
154
 
104
155
  describe '#partial_word?' do
156
+ let(:root) do
157
+ double :root,
158
+ compressed?: compressed,
159
+ partial_word?: nil
160
+ end
161
+
105
162
  context 'for an uncompressed root' do
106
- let(:root) do
107
- double :root,
108
- compressed?: false,
109
- partial_word?: nil
110
- end
163
+ let(:compressed) { true }
111
164
 
112
165
  it 'calls the root with the word characters' do
113
166
  container.partial_word? 'words'
@@ -116,11 +169,7 @@ describe Rambling::Trie::Container do
116
169
  end
117
170
 
118
171
  context 'for a compressed root' do
119
- let(:root) do
120
- double :root,
121
- compressed?: true,
122
- partial_word?: nil
123
- end
172
+ let(:compressed) { false }
124
173
 
125
174
  it 'calls the root with the word characters' do
126
175
  container.partial_word? 'words'
@@ -168,12 +217,12 @@ describe Rambling::Trie::Container do
168
217
 
169
218
  it 'aliases `#<<` to `#add`' do
170
219
  container << 'words'
171
- expect(root).to have_received(:add).with 'words'
220
+ expect(root).to have_received(:add).with %i(s d r o w)
172
221
  end
173
222
 
174
223
  it 'delegates `#[]` to the root node' do
175
- container.[]
176
- expect(root).to have_received :[]
224
+ container[:yep]
225
+ expect(root).to have_received(:[]).with :yep
177
226
  end
178
227
 
179
228
  it 'delegates `#as_word` to the root node' do
@@ -196,14 +245,14 @@ describe Rambling::Trie::Container do
196
245
  expect(root).to have_received :compressed?
197
246
  end
198
247
 
199
- it 'delegates `#each` to the root node' do
200
- container.each
201
- expect(root).to have_received :each
248
+ it 'delegates `#has_key?` to the root node' do
249
+ container.has_key? :yup
250
+ expect(root).to have_received(:has_key?).with :yup
202
251
  end
203
252
 
204
- it 'delegates `#has_key?` to the root node' do
205
- container.has_key?
206
- expect(root).to have_received :has_key?
253
+ it 'aliases `#has_letter?` to `#has_key?`' do
254
+ container.has_letter? :yup
255
+ expect(root).to have_received(:has_key?).with :yup
207
256
  end
208
257
 
209
258
  it 'delegates `#inspect` to the root node' do
@@ -233,118 +282,41 @@ describe Rambling::Trie::Container do
233
282
  end
234
283
 
235
284
  describe '#compress!' do
236
- let(:compressor) { Rambling::Trie::Compressor.new }
237
- let(:root) { Rambling::Trie::RawNode.new }
238
-
239
- context 'with at least one word' do
240
- it 'keeps the root letter nil' do
241
- container.add 'all'
242
- container.compress!
243
-
244
- expect(container.letter).to be_nil
245
- end
246
- end
247
-
248
- context 'with a single word' do
249
- before do
250
- container.add 'all'
251
- container.compress!
252
- end
253
-
254
- it 'compresses into a single node without children' do
255
- expect(container[:all].letter).to eq :all
256
- expect(container[:all].children.size).to eq 0
257
- expect(container[:all]).to be_terminal
258
- expect(container[:all]).to be_compressed
259
- end
260
- end
261
-
262
- context 'with two words' do
263
- before do
264
- container.add 'all'
265
- container.add 'ask'
266
- container.compress!
267
- end
268
-
269
- it 'compresses into corresponding three nodes' do
270
- expect(container[:a].letter).to eq :a
271
- expect(container[:a].children.size).to eq 2
272
-
273
- expect(container[:a][:ll].letter).to eq :ll
274
- expect(container[:a][:sk].letter).to eq :sk
275
-
276
- expect(container[:a][:ll].children.size).to eq 0
277
- expect(container[:a][:sk].children.size).to eq 0
278
-
279
- expect(container[:a][:ll]).to be_terminal
280
- expect(container[:a][:sk]).to be_terminal
281
-
282
- expect(container[:a][:ll]).to be_compressed
283
- expect(container[:a][:sk]).to be_compressed
284
- end
285
- end
286
-
287
- it 'reassigns the parent nodes correctly' do
288
- container.add 'repay'
289
- container.add 'rest'
290
- container.add 'repaint'
285
+ it 'gets a new root from the compressor' do
291
286
  container.compress!
292
287
 
293
- expect(container[:re].letter).to eq :re
294
- expect(container[:re].children.size).to eq 2
295
-
296
- expect(container[:re][:pa].letter).to eq :pa
297
- expect(container[:re][:st].letter).to eq :st
298
-
299
- expect(container[:re][:pa].children.size).to eq 2
300
- expect(container[:re][:st].children.size).to eq 0
301
-
302
- expect(container[:re][:pa][:y].letter).to eq :y
303
- expect(container[:re][:pa][:int].letter).to eq :int
304
-
305
- expect(container[:re][:pa][:y].children.size).to eq 0
306
- expect(container[:re][:pa][:int].children.size).to eq 0
307
-
308
- expect(container[:re][:pa][:y].parent).to eq container[:re][:pa]
309
- expect(container[:re][:pa][:int].parent).to eq container[:re][:pa]
288
+ expect(container.root).not_to be root
289
+ expect(container.root).to be_compressed
290
+ expect(root).not_to be_compressed
310
291
  end
311
292
 
312
- it 'does not compress terminal nodes' do
313
- container.add 'you'
314
- container.add 'your'
315
- container.add 'yours'
293
+ it 'generates a new root with the words from the passed root' do
294
+ words = %w(a few words hello hell)
316
295
 
296
+ add_words container, words
317
297
  container.compress!
318
298
 
319
- expect(container[:you].letter).to eq :you
320
-
321
- expect(container[:you][:r].letter).to eq :r
322
- expect(container[:you][:r]).to be_compressed
323
-
324
- expect(container[:you][:r][:s].letter).to eq :s
325
- expect(container[:you][:r][:s]).to be_compressed
299
+ words.each do |word|
300
+ expect(container).to include word
301
+ end
326
302
  end
327
303
 
328
304
  describe 'and trying to add a word' do
329
305
  it 'raises an error' do
330
- container.add 'repay'
331
- container.add 'rest'
332
- container.add 'repaint'
306
+ add_words container, %w(repay rest repaint)
333
307
  container.compress!
334
308
 
335
- expect { container.add 'restaurant' }.to raise_error Rambling::Trie::InvalidOperation
309
+ expect do
310
+ add_word container, 'restaurant'
311
+ end.to raise_error Rambling::Trie::InvalidOperation
336
312
  end
337
313
  end
338
314
  end
339
315
 
340
316
  describe '#word?' do
341
- let(:compressor) { Rambling::Trie::Compressor.new }
342
- let(:root) { Rambling::Trie::RawNode.new }
343
-
344
317
  context 'word is contained' do
345
318
  before do
346
- container.add 'hello'
347
- container.add 'high'
319
+ add_words container, %w(hello high)
348
320
  end
349
321
 
350
322
  it 'matches the whole word' do
@@ -366,7 +338,7 @@ describe Rambling::Trie::Container do
366
338
 
367
339
  context 'word is not contained' do
368
340
  before do
369
- container.add 'hello'
341
+ add_word container, 'hello'
370
342
  end
371
343
 
372
344
  it 'does not match the whole word' do
@@ -390,8 +362,7 @@ describe Rambling::Trie::Container do
390
362
  describe '#partial_word?' do
391
363
  context 'word is contained' do
392
364
  before do
393
- container.add 'hello'
394
- container.add 'high'
365
+ add_words container, %w(hello high)
395
366
  end
396
367
 
397
368
  it 'matches part of the word' do
@@ -416,27 +387,25 @@ describe Rambling::Trie::Container do
416
387
  end
417
388
  end
418
389
 
390
+ shared_examples_for 'a non matching tree' do
391
+ it 'does not match any part of the word' do
392
+ %w(ha hal al).each do |word|
393
+ expect(container.partial_word? word).to be false
394
+ end
395
+ end
396
+ end
397
+
419
398
  context 'word is not contained' do
420
399
  before do
421
- container.add 'hello'
400
+ add_word container, 'hello'
422
401
  end
423
402
 
424
- it 'does not match any part of the word' do
425
- expect(container.partial_word? 'ha').to be false
426
- expect(container.partial_word? 'hal').to be false
427
- expect(container.partial_word? 'al').to be false
403
+ context 'and the root is uncompressed' do
404
+ it_behaves_like 'a non matching tree'
428
405
  end
429
406
 
430
407
  context 'and the root has been compressed' do
431
- before do
432
- container.compress!
433
- end
434
-
435
- it 'does not match any part of the word' do
436
- expect(container.partial_word? 'ha').to be false
437
- expect(container.partial_word? 'hal').to be false
438
- expect(container.partial_word? 'al').to be false
439
- end
408
+ it_behaves_like 'a non matching tree'
440
409
  end
441
410
  end
442
411
  end
@@ -444,9 +413,7 @@ describe Rambling::Trie::Container do
444
413
  describe '#scan' do
445
414
  context 'words that match are not contained' do
446
415
  before do
447
- %w(hi hello high hell highlight histerical).each do |word|
448
- container.add word
449
- end
416
+ add_words container, %w(hi hello high hell highlight histerical)
450
417
  end
451
418
 
452
419
  it 'returns an array with the words that match' do
@@ -486,7 +453,7 @@ describe Rambling::Trie::Container do
486
453
 
487
454
  context 'words that match are not contained' do
488
455
  before do
489
- container.add 'hello'
456
+ add_word container, 'hello'
490
457
  end
491
458
 
492
459
  it 'returns an empty array' do
@@ -507,9 +474,7 @@ describe Rambling::Trie::Container do
507
474
 
508
475
  describe '#words_within' do
509
476
  before do
510
- %w(one word and other words).each do |word|
511
- container.add word
512
- end
477
+ add_words container, %w(one word and other words)
513
478
  end
514
479
 
515
480
  context 'phrase does not contain any words' do
@@ -581,9 +546,7 @@ describe Rambling::Trie::Container do
581
546
 
582
547
  describe '#words_within?' do
583
548
  before do
584
- %w(one word and other words).each do |word|
585
- container.add word
586
- end
549
+ add_words container, %w(one word and other words)
587
550
  end
588
551
 
589
552
  context 'phrase does not contain any words' do
@@ -602,7 +565,9 @@ describe Rambling::Trie::Container do
602
565
 
603
566
  describe '#==' do
604
567
  context 'when the root nodes are the same' do
605
- let(:other_container) { Rambling::Trie::Container.new container.root, compressor }
568
+ let(:other_container) do
569
+ Rambling::Trie::Container.new container.root, compressor
570
+ end
606
571
 
607
572
  it 'returns true' do
608
573
  expect(container).to eq other_container
@@ -610,11 +575,13 @@ describe Rambling::Trie::Container do
610
575
  end
611
576
 
612
577
  context 'when the root nodes are not the same' do
613
- let(:other_root) { Rambling::Trie::RawNode.new }
578
+ let(:other_root) { Rambling::Trie::Nodes::Raw.new }
614
579
  let(:other_container) do
615
- Rambling::Trie::Container.new other_root, compressor do |c|
616
- c << 'hola'
617
- end
580
+ Rambling::Trie::Container.new other_root, compressor
581
+ end
582
+
583
+ before do
584
+ add_word other_container, 'hola'
618
585
  end
619
586
 
620
587
  it 'returns false' do
@@ -622,4 +589,28 @@ describe Rambling::Trie::Container do
622
589
  end
623
590
  end
624
591
  end
592
+
593
+ describe '#each' do
594
+ before do
595
+ add_words container, %w(yes no why)
596
+ end
597
+
598
+ it 'returns an enumerator when no block is given' do
599
+ expect(container.each).to be_instance_of Enumerator
600
+ end
601
+
602
+ it 'iterates through all words contained' do
603
+ expect(container.each.to_a).to eq %w(yes no why)
604
+ end
605
+ end
606
+
607
+ describe '#inspect' do
608
+ before do
609
+ add_words container, %w(a few words hello hell)
610
+ end
611
+
612
+ it 'returns the container class name plus the root inspection' do
613
+ expect(container.inspect).to eq '#<Rambling::Trie::Container root: #<Rambling::Trie::Nodes::Raw letter: nil, terminal: nil, children: [:a, :f, :w, :h]>>'
614
+ end
615
+ end
625
616
  end