poefy-sqlite3 0.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/LICENSE +13 -13
- data/README.md +7 -7
- data/Rakefile +8 -8
- data/lib/poefy/sqlite3/version.rb +24 -24
- data/lib/poefy/sqlite3.rb +275 -275
- data/poefy-sqlite3.gemspec +4 -2
- data/spec/poefy_sqlite3_spec.rb +701 -686
- data/spec/spec_helper.rb +11 -11
- metadata +9 -13
data/spec/poefy_sqlite3_spec.rb
CHANGED
@@ -1,686 +1,701 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: UTF-8
|
3
|
-
|
4
|
-
################################################################################
|
5
|
-
|
6
|
-
describe Poefy::Poem, "-- SQLite" do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
require 'poefy/sqlite3'
|
10
|
-
@root = Poefy.root
|
11
|
-
dbs = %w{spec_test_tiny spec_shakespeare spec_whitman}
|
12
|
-
dbs.each do |db_name|
|
13
|
-
db_file = "#{@root}/data/#{db_name}.db"
|
14
|
-
File.delete(db_file) if File.
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
after(:all) do
|
19
|
-
dbs = %w{spec_test_tiny spec_shakespeare spec_whitman}
|
20
|
-
dbs.each do |db_name|
|
21
|
-
db_file = "#{@root}/data/#{db_name}.db"
|
22
|
-
File.delete(db_file) if File.
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
##############################################################################
|
27
|
-
|
28
|
-
describe "using tiny dataset 'spec_test_tiny'" do
|
29
|
-
corpus = "spec_test_tiny"
|
30
|
-
db_file = "#{Poefy.root}/data/#{corpus}.db"
|
31
|
-
|
32
|
-
# Create a small corpus of a few rhymes.
|
33
|
-
text_array = %w{man plan flan can dan fish dish wish bee sea tree flea}
|
34
|
-
text_array.map!{ |i| 'a ' + i }
|
35
|
-
text_string = text_array.join("\n")
|
36
|
-
row_count = text_array.count
|
37
|
-
|
38
|
-
before(:each) do
|
39
|
-
@poefy = Poefy::Poem.new(corpus, { proper: false })
|
40
|
-
end
|
41
|
-
after(:each) do
|
42
|
-
@poefy.close
|
43
|
-
end
|
44
|
-
it "initialised object not nil" do
|
45
|
-
expect(@poefy).to_not be_nil
|
46
|
-
end
|
47
|
-
|
48
|
-
# Create corpora in the three different ways.
|
49
|
-
describe "@poefy#make_database!" do
|
50
|
-
|
51
|
-
it "Use array of strings" do
|
52
|
-
@poefy.make_database! text_array
|
53
|
-
expect(@poefy.corpus.
|
54
|
-
expect(File.
|
55
|
-
expect(@poefy.corpus.count).to be row_count
|
56
|
-
poem = @poefy.poem({ rhyme: 'aabb' })
|
57
|
-
expect(poem.count).to be 4
|
58
|
-
end
|
59
|
-
|
60
|
-
it "Use one long newline delimited string" do
|
61
|
-
@poefy.make_database! text_string
|
62
|
-
expect(@poefy.corpus.
|
63
|
-
expect(File.
|
64
|
-
expect(@poefy.corpus.count).to be row_count
|
65
|
-
poem = @poefy.poem({ rhyme: 'aabb' })
|
66
|
-
expect(poem.count).to be 4
|
67
|
-
end
|
68
|
-
|
69
|
-
it "Use text lines from a file" do
|
70
|
-
|
71
|
-
# Create a temp file.
|
72
|
-
tmp = Tempfile.new('spec-', Poefy.root + '/spec')
|
73
|
-
text_path = tmp.path
|
74
|
-
tmp.write text_string
|
75
|
-
tmp.close
|
76
|
-
|
77
|
-
@poefy.make_database! text_path
|
78
|
-
expect(@poefy.corpus.
|
79
|
-
expect(File.
|
80
|
-
expect(@poefy.corpus.count).to be row_count
|
81
|
-
poem = @poefy.poem({ rhyme: 'aabb' })
|
82
|
-
expect(poem.count).to be 4
|
83
|
-
|
84
|
-
# Delete the temp file.
|
85
|
-
tmp.delete
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Make sure that the description can be updated as specified
|
90
|
-
# and that it doesn't cause SQL injection.
|
91
|
-
describe "corpus description using #desc=" do
|
92
|
-
it "@poefy.corpus.desc is initially empty" do
|
93
|
-
expect(@poefy.corpus.desc).to eq ''
|
94
|
-
end
|
95
|
-
|
96
|
-
values = [
|
97
|
-
"test",
|
98
|
-
" -- test",
|
99
|
-
"; -- test",
|
100
|
-
"test' -- ",
|
101
|
-
"test'' -- ",
|
102
|
-
"'test' -- ",
|
103
|
-
"'test'' -- ",
|
104
|
-
"Shakespeare's sonnets",
|
105
|
-
"Shakespeare's -- sonnets",
|
106
|
-
"Shakespeare's; -- sonnets",
|
107
|
-
"test' ; INSERT INTO spec_test_tiny VALUES('foo') -- ",
|
108
|
-
"105 OR 1=1",
|
109
|
-
"' or ''='"
|
110
|
-
]
|
111
|
-
values.each do |value|
|
112
|
-
it "@poefy.corpus.desc = #{value}" do
|
113
|
-
@poefy.corpus.desc = value
|
114
|
-
expect(@poefy.corpus.desc).to eq value
|
115
|
-
expect(@poefy.corpus.count).to be row_count
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe ":rhyme option" do
|
121
|
-
|
122
|
-
describe "should
|
123
|
-
it "blank, no argument" do
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
expect
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
expect(poem.
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
it "({ form: :not_a_form
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
poem
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
}
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
poem
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
poem
|
505
|
-
|
506
|
-
|
507
|
-
poefy.
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
expect(poem
|
538
|
-
expect(poem[
|
539
|
-
expect(poem[
|
540
|
-
poefy.close
|
541
|
-
end
|
542
|
-
|
543
|
-
it "should correctly transform the output
|
544
|
-
poefy = Poefy::Poem.new :spec_shakespeare
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
poefy
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
form_from_text: @text
|
610
|
-
})
|
611
|
-
poem.
|
612
|
-
|
613
|
-
expect(poem
|
614
|
-
expect(poem[
|
615
|
-
expect(poem[
|
616
|
-
expect(poem[
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
poem.map!(&:strip!)
|
627
|
-
expect(poem.count).to be @line_count
|
628
|
-
expect(poem[0]).to eq "[Chorus 1]"
|
629
|
-
expect(poem[8]).to eq "[Verse 1]"
|
630
|
-
expect(poem[5]).to eq poem[4]
|
631
|
-
expect(poem[6]).to eq poem[4]
|
632
|
-
poefy.close
|
633
|
-
end
|
634
|
-
|
635
|
-
it "should correctly modify the poetic form
|
636
|
-
poefy = Poefy::Poem.new
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
poem.map!(&:strip!)
|
642
|
-
expect(poem.count).to be @line_count
|
643
|
-
expect(poem[0]).to eq "[Chorus 1]"
|
644
|
-
expect(poem[8]).to eq "[Verse 1]"
|
645
|
-
expect(poem[5]).to eq poem[4]
|
646
|
-
expect(poem[6]).to eq poem[4]
|
647
|
-
poefy.close
|
648
|
-
end
|
649
|
-
|
650
|
-
it "should correctly modify the poetic form
|
651
|
-
poefy = Poefy::Poem.new
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
poem.
|
658
|
-
expect(poem
|
659
|
-
expect(poem[
|
660
|
-
expect(poem[
|
661
|
-
expect(poem[
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
poem.
|
674
|
-
expect(poem
|
675
|
-
expect(poem[
|
676
|
-
expect(poem[
|
677
|
-
expect(poem[
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: UTF-8
|
3
|
+
|
4
|
+
################################################################################
|
5
|
+
|
6
|
+
describe Poefy::Poem, "-- SQLite" do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
require 'poefy/sqlite3'
|
10
|
+
@root = Poefy.root
|
11
|
+
dbs = %w{spec_test_tiny spec_shakespeare spec_whitman}
|
12
|
+
dbs.each do |db_name|
|
13
|
+
db_file = "#{@root}/data/#{db_name}.db"
|
14
|
+
File.delete(db_file) if File.exist?(db_file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) do
|
19
|
+
dbs = %w{spec_test_tiny spec_shakespeare spec_whitman}
|
20
|
+
dbs.each do |db_name|
|
21
|
+
db_file = "#{@root}/data/#{db_name}.db"
|
22
|
+
File.delete(db_file) if File.exist?(db_file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
##############################################################################
|
27
|
+
|
28
|
+
describe "using tiny dataset 'spec_test_tiny'" do
|
29
|
+
corpus = "spec_test_tiny"
|
30
|
+
db_file = "#{Poefy.root}/data/#{corpus}.db"
|
31
|
+
|
32
|
+
# Create a small corpus of a few rhymes.
|
33
|
+
text_array = %w{man plan flan can dan fish dish wish bee sea tree flea}
|
34
|
+
text_array.map!{ |i| 'a ' + i }
|
35
|
+
text_string = text_array.join("\n")
|
36
|
+
row_count = text_array.count
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
@poefy = Poefy::Poem.new(corpus, { proper: false })
|
40
|
+
end
|
41
|
+
after(:each) do
|
42
|
+
@poefy.close
|
43
|
+
end
|
44
|
+
it "initialised object not nil" do
|
45
|
+
expect(@poefy).to_not be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create corpora in the three different ways.
|
49
|
+
describe "@poefy#make_database!" do
|
50
|
+
|
51
|
+
it "Use array of strings" do
|
52
|
+
@poefy.make_database! text_array
|
53
|
+
expect(@poefy.corpus.exist?).to be true
|
54
|
+
expect(File.exist?(db_file)).to be true
|
55
|
+
expect(@poefy.corpus.count).to be row_count
|
56
|
+
poem = @poefy.poem({ rhyme: 'aabb' })
|
57
|
+
expect(poem.count).to be 4
|
58
|
+
end
|
59
|
+
|
60
|
+
it "Use one long newline delimited string" do
|
61
|
+
@poefy.make_database! text_string
|
62
|
+
expect(@poefy.corpus.exist?).to be true
|
63
|
+
expect(File.exist?(db_file)).to be true
|
64
|
+
expect(@poefy.corpus.count).to be row_count
|
65
|
+
poem = @poefy.poem({ rhyme: 'aabb' })
|
66
|
+
expect(poem.count).to be 4
|
67
|
+
end
|
68
|
+
|
69
|
+
it "Use text lines from a file" do
|
70
|
+
|
71
|
+
# Create a temp file.
|
72
|
+
tmp = Tempfile.new('spec-', Poefy.root + '/spec')
|
73
|
+
text_path = tmp.path
|
74
|
+
tmp.write text_string
|
75
|
+
tmp.close
|
76
|
+
|
77
|
+
@poefy.make_database! text_path
|
78
|
+
expect(@poefy.corpus.exist?).to be true
|
79
|
+
expect(File.exist?(db_file)).to be true
|
80
|
+
expect(@poefy.corpus.count).to be row_count
|
81
|
+
poem = @poefy.poem({ rhyme: 'aabb' })
|
82
|
+
expect(poem.count).to be 4
|
83
|
+
|
84
|
+
# Delete the temp file.
|
85
|
+
tmp.delete
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Make sure that the description can be updated as specified
|
90
|
+
# and that it doesn't cause SQL injection.
|
91
|
+
describe "corpus description using #desc=" do
|
92
|
+
it "@poefy.corpus.desc is initially empty" do
|
93
|
+
expect(@poefy.corpus.desc).to eq ''
|
94
|
+
end
|
95
|
+
|
96
|
+
values = [
|
97
|
+
"test",
|
98
|
+
" -- test",
|
99
|
+
"; -- test",
|
100
|
+
"test' -- ",
|
101
|
+
"test'' -- ",
|
102
|
+
"'test' -- ",
|
103
|
+
"'test'' -- ",
|
104
|
+
"Shakespeare's sonnets",
|
105
|
+
"Shakespeare's -- sonnets",
|
106
|
+
"Shakespeare's; -- sonnets",
|
107
|
+
"test' ; INSERT INTO spec_test_tiny VALUES('foo') -- ",
|
108
|
+
"105 OR 1=1",
|
109
|
+
"' or ''='"
|
110
|
+
]
|
111
|
+
values.each do |value|
|
112
|
+
it "@poefy.corpus.desc = #{value}" do
|
113
|
+
@poefy.corpus.desc = value
|
114
|
+
expect(@poefy.corpus.desc).to eq value
|
115
|
+
expect(@poefy.corpus.count).to be row_count
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe ":rhyme option" do
|
121
|
+
|
122
|
+
describe "should raise Poefy::MissingFormOrRhyme" do
|
123
|
+
it "blank, no argument" do
|
124
|
+
expect {
|
125
|
+
@poefy.poem
|
126
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
127
|
+
end
|
128
|
+
it "({ })" do
|
129
|
+
expect {
|
130
|
+
@poefy.poem ({ })
|
131
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
132
|
+
end
|
133
|
+
it "({ rhyme: nil })" do
|
134
|
+
expect {
|
135
|
+
@poefy.poem ({ rhyme: nil })
|
136
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
137
|
+
end
|
138
|
+
it "({ rhyme: ' ' })" do
|
139
|
+
expect {
|
140
|
+
@poefy.poem ({ rhyme: ' ' })
|
141
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
142
|
+
end
|
143
|
+
it "({ rhyme: '' })" do
|
144
|
+
expect {
|
145
|
+
@poefy.poem ({ rhyme: '' })
|
146
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "should return correct number of lines" do
|
151
|
+
rhymes = %w{a b z A aa ab zz AA AB AA1 A1 B1 Z1 AB1 A1A1A1A1B1B1B1B1B1}
|
152
|
+
rhymes += ['A1A1A1 A1A1A1 B1B1B1B1B1B1','a b c a b c']
|
153
|
+
rhymes += [' abc','abc ',' abc ']
|
154
|
+
rhymes += ['n aaa n','n aXXXa N1']
|
155
|
+
rhymes.each do |i|
|
156
|
+
it "({ rhyme: '#{i}' })" do
|
157
|
+
poem = @poefy.poem ({ rhyme: i })
|
158
|
+
expect(poem.count).to be i.gsub(/[0-9]/,'').length
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "should accept characters other than number" do
|
164
|
+
rhymes = %w{. , : .. ., ,, :: (()) @ ~ <<>< A1A1A1...a;}
|
165
|
+
rhymes.each do |i|
|
166
|
+
it "({ rhyme: '#{i}' })" do
|
167
|
+
poem = @poefy.poem ({ rhyme: i })
|
168
|
+
expect(poem.count).to be i.gsub(/[0-9]/,'').length
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "should raise error if can't parse rhyme string" do
|
174
|
+
rhymes = %w{a1 b1 ab1 Ab1 AAAAABb1 1 1111 1122 11221 ;;::1. }
|
175
|
+
rhymes += ['AA Bb1','11 11','11 1 1','..1.']
|
176
|
+
rhymes.each do |i|
|
177
|
+
it "({ rhyme: '#{i}' })" do
|
178
|
+
expect {
|
179
|
+
@poefy.poem ({ rhyme: i })
|
180
|
+
}.to raise_error(Poefy::RhymeError)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "should raise error if can't complete rhyme string" do
|
186
|
+
rhymes = %w{aaaaaa abcd aaaaabbbbb}
|
187
|
+
rhymes.each do |i|
|
188
|
+
it "({ rhyme: '#{i}' })" do
|
189
|
+
expect {
|
190
|
+
@poefy.poem ({ rhyme: i })
|
191
|
+
}.to raise_error(Poefy::NotEnoughData)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "should correctly repeat uppercase lines" do
|
197
|
+
lines = 200
|
198
|
+
it "({ rhyme: 'A' * #{lines} })" do
|
199
|
+
poem = @poefy.poem ({ rhyme: 'A' * lines })
|
200
|
+
expect(poem.count).to be lines
|
201
|
+
expect(poem.uniq.count).to be 1
|
202
|
+
end
|
203
|
+
it "({ rhyme: ('A'..'C').to_a.map { |i| i * #{lines} }.join })" do
|
204
|
+
rhyme = ('A'..'C').to_a.map { |i| i * lines }.join
|
205
|
+
poem = @poefy.poem ({ rhyme: rhyme })
|
206
|
+
expect(poem.count).to be lines * 3
|
207
|
+
expect(poem.uniq.count).to be 3
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "should raise error if can't complete repeating rhyme string" do
|
212
|
+
lines = 200
|
213
|
+
it "({ rhyme: ('A'..'D').to_a.map { |i| i * #{lines} }.join })" do
|
214
|
+
rhyme = ('A'..'D').to_a.map { |i| i * lines }.join
|
215
|
+
expect {
|
216
|
+
@poefy.poem ({ rhyme: rhyme })
|
217
|
+
}.to raise_error(Poefy::NotEnoughData)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
describe ":form option" do
|
224
|
+
|
225
|
+
describe "should return correct number of lines" do
|
226
|
+
it "({ form: :default })" do
|
227
|
+
poem = @poefy.poem ({ form: :default })
|
228
|
+
expect(poem.count).to be 1
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "should raise error if given a named form it can't fulfil" do
|
233
|
+
it "({ form: 'sonnet' })" do
|
234
|
+
expect {
|
235
|
+
@poefy.poem ({ form: 'sonnet' })
|
236
|
+
}.to raise_error(Poefy::NotEnoughData)
|
237
|
+
end
|
238
|
+
it "({ form: :villanelle })" do
|
239
|
+
expect {
|
240
|
+
@poefy.poem ({ form: 'villanelle' })
|
241
|
+
}.to raise_error(Poefy::NotEnoughData)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "should raise error if given a junk named form" do
|
246
|
+
it "({ form: 'sonnet_junk' })" do
|
247
|
+
expect {
|
248
|
+
@poefy.poem ({ form: 'sonnet_junk' })
|
249
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
250
|
+
end
|
251
|
+
it "({ form: :not_a_form })" do
|
252
|
+
expect {
|
253
|
+
@poefy.poem ({ form: :not_a_form })
|
254
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
255
|
+
end
|
256
|
+
it "({ form: :not_a_form, indent: '0010' })" do
|
257
|
+
expect {
|
258
|
+
@poefy.poem ({ form: :not_a_form, indent: '0010' })
|
259
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "should be valid if given a junk named form, and a rhyme" do
|
264
|
+
it "({ form: :not_a_form, rhyme: 'abcb' })" do
|
265
|
+
poem = @poefy.poem ({ form: :not_a_form, rhyme: 'abcb' })
|
266
|
+
expect(poem.count).to be 4
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe "should overwrite a named form if another option is specified" do
|
271
|
+
it "({ form: 'default', rhyme: 'ab' })" do
|
272
|
+
poem = @poefy.poem ({ form: 'default', rhyme: 'ab' })
|
273
|
+
expect(poem.count).to be 2
|
274
|
+
end
|
275
|
+
it "({ form: :villanelle, rhyme: 'abcb' })" do
|
276
|
+
poem = @poefy.poem ({ form: :villanelle, rhyme: 'abcb' })
|
277
|
+
expect(poem.count).to be 4
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
##############################################################################
|
284
|
+
|
285
|
+
describe "using dataset 'spec_shakespeare'" do
|
286
|
+
|
287
|
+
file_txt = "shakespeare_sonnets.txt"
|
288
|
+
file_db = "spec_shakespeare.db"
|
289
|
+
|
290
|
+
# All the Shakespeare lines are pentameter, so some forms should fail.
|
291
|
+
forms = Poefy::PoeticForms::POETIC_FORMS
|
292
|
+
forms_fail = [:limerick, :haiku, :common, :ballad, :double_dactyl]
|
293
|
+
forms_pass = forms.keys - forms_fail
|
294
|
+
|
295
|
+
before(:each) do
|
296
|
+
@poefy = Poefy::Poem.new(file_db, { proper: false })
|
297
|
+
end
|
298
|
+
after(:each) do
|
299
|
+
@poefy.close
|
300
|
+
end
|
301
|
+
|
302
|
+
it "initialised object not nil" do
|
303
|
+
expect(@poefy).to_not be_nil
|
304
|
+
end
|
305
|
+
|
306
|
+
describe "#make_database( '#{@root}/data/#{file_txt}', true )" do
|
307
|
+
it "should make the database '#{@root}/data/#{file_db}" do
|
308
|
+
db_file = "#{@root}/data/#{file_db}"
|
309
|
+
input = `sed '/[a-z]/!d' #{@root}/data/#{file_txt}`
|
310
|
+
@poefy.make_database input
|
311
|
+
expect(@poefy.corpus.exist?).to be true
|
312
|
+
expect(File.exist?(db_file)).to be true
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe "using acrostic option" do
|
317
|
+
describe "should return correct number of lines" do
|
318
|
+
it "({ form: :sonnet, acrostic: 'pauldpthompson' })" do
|
319
|
+
poem = @poefy.poem ({ form: :sonnet,
|
320
|
+
acrostic: 'pauldpthompson' })
|
321
|
+
expect(poem.count).to be 14
|
322
|
+
end
|
323
|
+
end
|
324
|
+
describe "should raise Poefy::NotEnoughData" do
|
325
|
+
it "({ form: :sonnet, acrostic: 'qqqqqqqqqqqqqq' })" do
|
326
|
+
expect {
|
327
|
+
@poefy.poem ({ form: :sonnet,
|
328
|
+
acrostic: 'qqqqqqqqqqqqqq' })
|
329
|
+
}.to raise_error(Poefy::NotEnoughData)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe "using form string" do
|
335
|
+
describe "should return correct number of lines" do
|
336
|
+
|
337
|
+
# Make sure each form's lines match the expected output.
|
338
|
+
# Generate a few to be sure.
|
339
|
+
forms_pass.each do |form|
|
340
|
+
it "({ form: #{form} })" do
|
341
|
+
10.times do
|
342
|
+
poem = @poefy.poem ({ form: form })
|
343
|
+
expect(poem.count).to satisfy do |c|
|
344
|
+
[*forms[form][:rhyme]].map do |r|
|
345
|
+
r.gsub(/[0-9]/,'').length
|
346
|
+
end.include?(c)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
describe "should raise Poefy::NotEnoughData" do
|
354
|
+
forms_fail.each do |form|
|
355
|
+
it "({ form: #{form} })" do
|
356
|
+
4.times do
|
357
|
+
expect {
|
358
|
+
@poefy.poem ({ form: form })
|
359
|
+
}.to raise_error(Poefy::NotEnoughData)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
describe "make sonnets" do
|
367
|
+
sonnet_options = [
|
368
|
+
{ rhyme: 'ababcdcdefefgg' },
|
369
|
+
{ rhyme: 'abab cdcd efef gg', indent: '0101 0101 0011 01' },
|
370
|
+
{ form: 'sonnet' },
|
371
|
+
{ form: :sonnet, syllable: 0 },
|
372
|
+
{ form: :sonnet, syllable: 10 },
|
373
|
+
{ form: :sonnet, regex: /^[A-Z].*$/ },
|
374
|
+
{ form: :sonnet, regex: '^[A-Z].*$' },
|
375
|
+
{ form: :sonnet, acrostic: 'pauldpthompson' },
|
376
|
+
{ form: 'sonnet', indent: '01010101001101' },
|
377
|
+
{ form: 'sonnet', proper: false }
|
378
|
+
]
|
379
|
+
sonnet_options.each do |option|
|
380
|
+
it "#{option}" do
|
381
|
+
4.times do
|
382
|
+
poem = @poefy.poem(option)
|
383
|
+
expect(poem).to_not be_nil
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
##############################################################################
|
391
|
+
|
392
|
+
describe "using dataset 'spec_whitman'" do
|
393
|
+
|
394
|
+
file_txt = "whitman_leaves.txt"
|
395
|
+
file_db = "spec_whitman.db"
|
396
|
+
|
397
|
+
# There's a good mix of syllable count, so all forms should pass.
|
398
|
+
forms = Poefy::PoeticForms::POETIC_FORMS
|
399
|
+
forms_pass = forms.keys
|
400
|
+
|
401
|
+
before(:each) do
|
402
|
+
@poefy = Poefy::Poem.new(file_db, { proper: false })
|
403
|
+
end
|
404
|
+
after(:each) do
|
405
|
+
@poefy.close
|
406
|
+
end
|
407
|
+
|
408
|
+
it "initialised object not nil" do
|
409
|
+
expect(@poefy).to_not be_nil
|
410
|
+
end
|
411
|
+
|
412
|
+
describe "#make_database( '#{@root}/data/#{file_txt}', true )" do
|
413
|
+
it "should make the database '#{@root}/data/#{file_db}" do
|
414
|
+
db_file = "#{@root}/data/#{file_db}"
|
415
|
+
input = `sed '/[a-z]/!d' #{@root}/data/#{file_txt}`
|
416
|
+
@poefy.make_database input
|
417
|
+
expect(@poefy.corpus.exist?).to be true
|
418
|
+
expect(File.exist?(db_file)).to be true
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
describe "using form string" do
|
423
|
+
describe "should return correct number of lines" do
|
424
|
+
|
425
|
+
# Make sure each form's lines match the expected output.
|
426
|
+
# Generate a few to be sure.
|
427
|
+
forms_pass.each do |form|
|
428
|
+
it "({ form: #{form} })" do
|
429
|
+
10.times do
|
430
|
+
poem = @poefy.poem ({ form: form })
|
431
|
+
expect(poem.count).to satisfy do |c|
|
432
|
+
[*forms[form][:rhyme]].map do |r|
|
433
|
+
r.gsub(/[0-9]/,'').length
|
434
|
+
end.include?(c)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
describe "make sonnets" do
|
443
|
+
sonnet_options = [
|
444
|
+
{ rhyme: 'ababcdcdefefgg' },
|
445
|
+
{ rhyme: 'abab cdcd efef gg', indent: '0101 0101 0011 01' },
|
446
|
+
{ form: 'sonnet' },
|
447
|
+
{ form: :sonnet, syllable: 0 },
|
448
|
+
{ form: :sonnet, syllable: 10 },
|
449
|
+
{ form: :sonnet, regex: /^[A-Z].*$/ },
|
450
|
+
{ form: :sonnet, regex: '^[A-Z].*$' },
|
451
|
+
{ form: :sonnet, acrostic: 'pauldpthompson' },
|
452
|
+
{ form: 'sonnet', indent: '01010101001101' },
|
453
|
+
{ form: 'sonnet', proper: false }
|
454
|
+
]
|
455
|
+
sonnet_options.each do |option|
|
456
|
+
it "#{option}" do
|
457
|
+
4.times do
|
458
|
+
poem = @poefy.poem(option)
|
459
|
+
expect(poem).to_not be_nil
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
describe "using syllable string" do
|
466
|
+
|
467
|
+
it "({ rhyme: 'abcb defe', syllable: '[8,6,8,6,0,8,6,8,6]' })" do
|
468
|
+
options = {
|
469
|
+
rhyme: 'abcb defe',
|
470
|
+
syllable: '[8,6,8,6,0,8,6,8,6]'
|
471
|
+
}
|
472
|
+
poem = @poefy.poem (options)
|
473
|
+
expect(poem.count).to be options[:rhyme].length
|
474
|
+
end
|
475
|
+
|
476
|
+
it "({ rhyme: 'abcb defe', syllable: '[8,6,8,6,8,6,8,6]' })" do
|
477
|
+
options = {
|
478
|
+
rhyme: 'abcb defe',
|
479
|
+
syllable: '[8,6,8,6,8,6,8,6]'
|
480
|
+
}
|
481
|
+
poem = @poefy.poem (options)
|
482
|
+
expect(poem.count).to be options[:rhyme].length
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
##############################################################################
|
488
|
+
|
489
|
+
describe "reusing the same Poem instance" do
|
490
|
+
it "should correctly merge the option hashes" do
|
491
|
+
|
492
|
+
# Default to use rondeau poetic form, and proper sentence validation
|
493
|
+
poefy = Poefy::Poem.new(
|
494
|
+
'spec_shakespeare',
|
495
|
+
{ form: 'rondeau', proper: true }
|
496
|
+
)
|
497
|
+
|
498
|
+
# Generate a properly sentenced rondeau
|
499
|
+
poem = poefy.poem
|
500
|
+
expect(poem.count).to be 17
|
501
|
+
|
502
|
+
# Generate a rondeau without proper validation
|
503
|
+
poem = poefy.poem ({ proper: false })
|
504
|
+
expect(poem.count).to be 17
|
505
|
+
|
506
|
+
# Generate a proper rondeau with a certain indentation
|
507
|
+
poem = poefy.poem ({ indent: '01012 0012 010112' })
|
508
|
+
expect(poem.count).to be 17
|
509
|
+
|
510
|
+
# Generate other forms
|
511
|
+
poem = poefy.poem ({ rhyme: 'abbaabbacdecde' })
|
512
|
+
expect(poem.count).to be 14
|
513
|
+
poem = poefy.poem ({ form: 'sonnet' })
|
514
|
+
expect(poem.count).to be 14
|
515
|
+
poem = poefy.poem ({ form: 'ballade' })
|
516
|
+
expect(poem.count).to be 31
|
517
|
+
|
518
|
+
# Generate a default rondeau again
|
519
|
+
poem = poefy.poem
|
520
|
+
expect(poem.count).to be 17
|
521
|
+
|
522
|
+
poefy.close
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
##############################################################################
|
527
|
+
|
528
|
+
describe "using the transform option" do
|
529
|
+
|
530
|
+
it "should correctly transform the output 1" do
|
531
|
+
poefy = Poefy::Poem.new :spec_shakespeare
|
532
|
+
transform_hash = {
|
533
|
+
4 => proc { |line, num, poem| line.upcase },
|
534
|
+
12 => proc { |line, num, poem| line.upcase }
|
535
|
+
}
|
536
|
+
poem = poefy.poem({ form: :sonnet, transform: transform_hash })
|
537
|
+
expect(poem.count).to be 14
|
538
|
+
expect(poem[3]).to eq poem[3].upcase
|
539
|
+
expect(poem[11]).to eq poem[11].upcase
|
540
|
+
poefy.close
|
541
|
+
end
|
542
|
+
|
543
|
+
it "should correctly transform the output 2" do
|
544
|
+
poefy = Poefy::Poem.new :spec_shakespeare
|
545
|
+
transform_hash = {
|
546
|
+
4 => proc { |line, num, poem| poem.count },
|
547
|
+
-3 => proc { |line, num, poem| poem.count },
|
548
|
+
7 => proc { |line, num, poem| 'test string' }
|
549
|
+
}
|
550
|
+
poem = poefy.poem({ form: :sonnet, transform: transform_hash })
|
551
|
+
expect(poem.count).to be 14
|
552
|
+
expect(poem[3]).to eq '14'
|
553
|
+
expect(poem[11]).to eq '14'
|
554
|
+
expect(poem[6]).to eq 'test string'
|
555
|
+
poefy.close
|
556
|
+
end
|
557
|
+
|
558
|
+
it "should correctly transform the output 3" do
|
559
|
+
poefy = Poefy::Poem.new :spec_shakespeare
|
560
|
+
transform_proc = proc { |line, num, poem| line.downcase }
|
561
|
+
poem = poefy.poem({ form: :sonnet, transform: transform_proc })
|
562
|
+
expect(poem.count).to be 14
|
563
|
+
poem.each do |i|
|
564
|
+
expect(i).to eq i.downcase
|
565
|
+
end
|
566
|
+
poefy.close
|
567
|
+
end
|
568
|
+
|
569
|
+
it "should correctly transform the output 4" do
|
570
|
+
poefy = Poefy::Poem.new :spec_shakespeare
|
571
|
+
transform_proc = proc { |line, num, poem| "#{num} #{line.downcase}" }
|
572
|
+
poem = poefy.poem({ form: :sonnet, transform: transform_proc })
|
573
|
+
expect(poem.count).to be 14
|
574
|
+
poem.each.with_index do |line, index|
|
575
|
+
expect(line).to eq line.downcase
|
576
|
+
first_word = line.split(' ').first
|
577
|
+
expect(first_word).to eq (index + 1).to_s
|
578
|
+
end
|
579
|
+
poefy.close
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
##############################################################################
|
584
|
+
|
585
|
+
describe "using the form_from_text option" do
|
586
|
+
before(:all) do
|
587
|
+
@text = <<-TEXT
|
588
|
+
[Chorus 1]
|
589
|
+
Oh yeah, I'll tell you something
|
590
|
+
I think you'll understand
|
591
|
+
When I'll say that something
|
592
|
+
I want to hold your hand
|
593
|
+
I want to hold your hand
|
594
|
+
I want to hold your hand
|
595
|
+
|
596
|
+
[Verse 1]
|
597
|
+
Oh please, say to me
|
598
|
+
You'll let me be your man
|
599
|
+
And please, say to me
|
600
|
+
You'll let me hold your hand
|
601
|
+
I'll let me hold your hand
|
602
|
+
I want to hold your hand
|
603
|
+
TEXT
|
604
|
+
@line_count = @text.split("\n").count
|
605
|
+
end
|
606
|
+
|
607
|
+
it "should use the exact poetic form 1" do
|
608
|
+
poefy = Poefy::Poem.new(:spec_whitman, {
|
609
|
+
form_from_text: @text
|
610
|
+
})
|
611
|
+
poem = poefy.poem
|
612
|
+
poem.map!(&:strip!)
|
613
|
+
expect(poem.count).to be @line_count
|
614
|
+
expect(poem[0]).to eq "[Chorus 1]"
|
615
|
+
expect(poem[8]).to eq "[Verse 1]"
|
616
|
+
expect(poem[5]).to eq poem[4]
|
617
|
+
expect(poem[6]).to eq poem[4]
|
618
|
+
poefy.close
|
619
|
+
end
|
620
|
+
|
621
|
+
it "should use the exact poetic form 2" do
|
622
|
+
poefy = Poefy::Poem.new :spec_whitman
|
623
|
+
poem = poefy.poem({
|
624
|
+
form_from_text: @text
|
625
|
+
})
|
626
|
+
poem.map!(&:strip!)
|
627
|
+
expect(poem.count).to be @line_count
|
628
|
+
expect(poem[0]).to eq "[Chorus 1]"
|
629
|
+
expect(poem[8]).to eq "[Verse 1]"
|
630
|
+
expect(poem[5]).to eq poem[4]
|
631
|
+
expect(poem[6]).to eq poem[4]
|
632
|
+
poefy.close
|
633
|
+
end
|
634
|
+
|
635
|
+
it "should correctly modify the poetic form 1" do
|
636
|
+
poefy = Poefy::Poem.new(:spec_whitman, {
|
637
|
+
form_from_text: @text,
|
638
|
+
syllable: 6
|
639
|
+
})
|
640
|
+
poem = poefy.poem
|
641
|
+
poem.map!(&:strip!)
|
642
|
+
expect(poem.count).to be @line_count
|
643
|
+
expect(poem[0]).to eq "[Chorus 1]"
|
644
|
+
expect(poem[8]).to eq "[Verse 1]"
|
645
|
+
expect(poem[5]).to eq poem[4]
|
646
|
+
expect(poem[6]).to eq poem[4]
|
647
|
+
poefy.close
|
648
|
+
end
|
649
|
+
|
650
|
+
it "should correctly modify the poetic form 2" do
|
651
|
+
poefy = Poefy::Poem.new :spec_whitman
|
652
|
+
poem = poefy.poem({
|
653
|
+
form_from_text: @text,
|
654
|
+
syllable: 6
|
655
|
+
})
|
656
|
+
poem.map!(&:strip!)
|
657
|
+
expect(poem.count).to be @line_count
|
658
|
+
expect(poem[0]).to eq "[Chorus 1]"
|
659
|
+
expect(poem[8]).to eq "[Verse 1]"
|
660
|
+
expect(poem[5]).to eq poem[4]
|
661
|
+
expect(poem[6]).to eq poem[4]
|
662
|
+
poefy.close
|
663
|
+
end
|
664
|
+
|
665
|
+
it "should correctly modify the poetic form 3" do
|
666
|
+
poefy = Poefy::Poem.new(:spec_whitman, {
|
667
|
+
form_from_text: @text
|
668
|
+
})
|
669
|
+
poem = poefy.poem({
|
670
|
+
syllable: 6
|
671
|
+
})
|
672
|
+
poem.map!(&:strip!)
|
673
|
+
expect(poem.count).to be @line_count
|
674
|
+
expect(poem[0]).to eq "[Chorus 1]"
|
675
|
+
expect(poem[8]).to eq "[Verse 1]"
|
676
|
+
expect(poem[5]).to eq poem[4]
|
677
|
+
expect(poem[6]).to eq poem[4]
|
678
|
+
poefy.close
|
679
|
+
end
|
680
|
+
|
681
|
+
it "should correctly replace the poetic form" do
|
682
|
+
poefy = Poefy::Poem.new(:spec_whitman, {
|
683
|
+
syllable: 6
|
684
|
+
})
|
685
|
+
poem = poefy.poem({
|
686
|
+
form_from_text: @text
|
687
|
+
})
|
688
|
+
poem.map!(&:strip!)
|
689
|
+
expect(poem.count).to be @line_count
|
690
|
+
expect(poem[0]).to eq "[Chorus 1]"
|
691
|
+
expect(poem[8]).to eq "[Verse 1]"
|
692
|
+
expect(poem[5]).to eq poem[4]
|
693
|
+
expect(poem[6]).to eq poem[4]
|
694
|
+
poefy.close
|
695
|
+
end
|
696
|
+
|
697
|
+
end
|
698
|
+
|
699
|
+
end
|
700
|
+
|
701
|
+
################################################################################
|