shoulda-matchers 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -1
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +8 -2
  5. data/NEWS.md +29 -1
  6. data/README.md +3 -11
  7. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +17 -0
  8. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +3 -4
  9. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +1 -1
  10. data/doc_config/yard/templates/default/layout/html/footer.erb +6 -0
  11. data/docs/errors/NonCaseSwappableValueError.md +111 -0
  12. data/gemfiles/4.0.0.gemfile +1 -2
  13. data/gemfiles/4.0.0.gemfile.lock +5 -2
  14. data/gemfiles/4.0.1.gemfile +1 -2
  15. data/gemfiles/4.0.1.gemfile.lock +5 -2
  16. data/gemfiles/4.1.gemfile +1 -2
  17. data/gemfiles/4.1.gemfile.lock +5 -2
  18. data/gemfiles/4.2.gemfile +1 -2
  19. data/gemfiles/4.2.gemfile.lock +5 -2
  20. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +1 -5
  21. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +26 -4
  22. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +9 -8
  23. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +14 -8
  24. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +47 -12
  25. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +15 -9
  26. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +14 -7
  27. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +16 -4
  28. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +67 -5
  29. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +35 -0
  30. data/lib/shoulda/matchers/util.rb +2 -0
  31. data/lib/shoulda/matchers/util/word_wrap.rb +178 -0
  32. data/lib/shoulda/matchers/version.rb +1 -1
  33. data/lib/shoulda/matchers/warn.rb +1 -10
  34. data/spec/acceptance_spec_helper.rb +2 -10
  35. data/spec/doublespeak_spec_helper.rb +1 -17
  36. data/spec/spec_helper.rb +23 -0
  37. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
  38. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +5 -2
  39. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +5 -2
  40. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +5 -1
  41. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +91 -4
  42. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +292 -2
  43. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +16 -2
  44. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +197 -0
  45. data/spec/unit_spec_helper.rb +1 -16
  46. data/tasks/documentation.rb +10 -17
  47. metadata +9 -2
@@ -126,6 +126,42 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
126
126
  record = build_record_validating_numericality
127
127
  expect(record).to validate_numericality
128
128
  end
129
+
130
+ context 'when the column is an integer column' do
131
+ it 'raises an IneffectiveTestError' do
132
+ record = build_record_validating_numericality(
133
+ column_type: :integer
134
+ )
135
+ assertion = -> { expect(record).to validate_numericality }
136
+
137
+ expect(&assertion).
138
+ to raise_error(described_class::IneffectiveTestError)
139
+ end
140
+ end
141
+
142
+ context 'when the column is a float column' do
143
+ it 'raises an IneffectiveTestError' do
144
+ record = build_record_validating_numericality(
145
+ column_type: :float
146
+ )
147
+ assertion = -> { expect(record).to validate_numericality }
148
+
149
+ expect(&assertion).
150
+ to raise_error(described_class::IneffectiveTestError)
151
+ end
152
+ end
153
+
154
+ context 'when the column is a decimal column' do
155
+ it 'raises an IneffectiveTestError' do
156
+ record = build_record_validating_numericality(
157
+ column_type: :decimal,
158
+ )
159
+ assertion = -> { expect(record).to validate_numericality }
160
+
161
+ expect(&assertion).
162
+ to raise_error(described_class::IneffectiveTestError)
163
+ end
164
+ end
129
165
  end
130
166
 
131
167
  context 'and not validating anything' do
@@ -187,6 +223,39 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
187
223
  record = build_record_validating_numericality(odd: true)
188
224
  expect(record).to validate_numericality.odd
189
225
  end
226
+
227
+ context 'when the column is an integer column' do
228
+ it 'accepts (and does not raise an error)' do
229
+ record = build_record_validating_numericality(
230
+ column_type: :integer,
231
+ odd: true
232
+ )
233
+
234
+ expect(record).to validate_numericality.odd
235
+ end
236
+ end
237
+
238
+ context 'when the column is a float column' do
239
+ it 'accepts (and does not raise an error)' do
240
+ record = build_record_validating_numericality(
241
+ column_type: :float,
242
+ odd: true
243
+ )
244
+
245
+ expect(record).to validate_numericality.odd
246
+ end
247
+ end
248
+
249
+ context 'when the column is a decimal column' do
250
+ it 'accepts (and does not raise an error)' do
251
+ record = build_record_validating_numericality(
252
+ column_type: :decimal,
253
+ odd: true,
254
+ )
255
+
256
+ expect(record).to validate_numericality.odd
257
+ end
258
+ end
190
259
  end
191
260
 
192
261
  context 'and not validating with odd' do
@@ -204,10 +273,43 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
204
273
 
205
274
  context 'qualified with even' do
206
275
  context 'and validating with even' do
207
- it 'allows even number values for that attribute' do
276
+ it 'accepts' do
208
277
  record = build_record_validating_numericality(even: true)
209
278
  expect(record).to validate_numericality.even
210
279
  end
280
+
281
+ context 'when the column is an integer column' do
282
+ it 'accepts (and does not raise an error)' do
283
+ record = build_record_validating_numericality(
284
+ column_type: :integer,
285
+ even: true
286
+ )
287
+
288
+ expect(record).to validate_numericality.even
289
+ end
290
+ end
291
+
292
+ context 'when the column is a float column' do
293
+ it 'accepts (and does not raise an error)' do
294
+ record = build_record_validating_numericality(
295
+ column_type: :float,
296
+ even: true
297
+ )
298
+
299
+ expect(record).to validate_numericality.even
300
+ end
301
+ end
302
+
303
+ context 'when the column is a decimal column' do
304
+ it 'accepts (and does not raise an error)' do
305
+ record = build_record_validating_numericality(
306
+ column_type: :decimal,
307
+ even: true,
308
+ )
309
+
310
+ expect(record).to validate_numericality.even
311
+ end
312
+ end
211
313
  end
212
314
 
213
315
  context 'and not validating with even' do
@@ -229,6 +331,39 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
229
331
  )
230
332
  expect(record).to validate_numericality.is_less_than_or_equal_to(18)
231
333
  end
334
+
335
+ context 'when the column is an integer column' do
336
+ it 'accepts (and does not raise an error)' do
337
+ record = build_record_validating_numericality(
338
+ column_type: :integer,
339
+ less_than_or_equal_to: 18
340
+ )
341
+
342
+ expect(record).to validate_numericality.is_less_than_or_equal_to(18)
343
+ end
344
+ end
345
+
346
+ context 'when the column is a float column' do
347
+ it 'accepts (and does not raise an error)' do
348
+ record = build_record_validating_numericality(
349
+ column_type: :float,
350
+ less_than_or_equal_to: 18
351
+ )
352
+
353
+ expect(record).to validate_numericality.is_less_than_or_equal_to(18)
354
+ end
355
+ end
356
+
357
+ context 'when the column is a decimal column' do
358
+ it 'accepts (and does not raise an error)' do
359
+ record = build_record_validating_numericality(
360
+ column_type: :decimal,
361
+ less_than_or_equal_to: 18,
362
+ )
363
+
364
+ expect(record).to validate_numericality.is_less_than_or_equal_to(18)
365
+ end
366
+ end
232
367
  end
233
368
 
234
369
  context 'and not validating with less_than_or_equal_to' do
@@ -254,6 +389,39 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
254
389
  to validate_numericality.
255
390
  is_less_than(18)
256
391
  end
392
+
393
+ context 'when the column is an integer column' do
394
+ it 'accepts (and does not raise an error)' do
395
+ record = build_record_validating_numericality(
396
+ column_type: :integer,
397
+ less_than: 18
398
+ )
399
+
400
+ expect(record).to validate_numericality.is_less_than(18)
401
+ end
402
+ end
403
+
404
+ context 'when the column is a float column' do
405
+ it 'accepts (and does not raise an error)' do
406
+ record = build_record_validating_numericality(
407
+ column_type: :float,
408
+ less_than: 18
409
+ )
410
+
411
+ expect(record).to validate_numericality.is_less_than(18)
412
+ end
413
+ end
414
+
415
+ context 'when the column is a decimal column' do
416
+ it 'accepts (and does not raise an error)' do
417
+ record = build_record_validating_numericality(
418
+ column_type: :decimal,
419
+ less_than: 18,
420
+ )
421
+
422
+ expect(record).to validate_numericality.is_less_than(18)
423
+ end
424
+ end
257
425
  end
258
426
 
259
427
  context 'and not validating with less_than' do
@@ -277,6 +445,39 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
277
445
  record = build_record_validating_numericality(equal_to: 18)
278
446
  expect(record).to validate_numericality.is_equal_to(18)
279
447
  end
448
+
449
+ context 'when the column is an integer column' do
450
+ it 'accepts (and does not raise an error)' do
451
+ record = build_record_validating_numericality(
452
+ column_type: :integer,
453
+ equal_to: 18
454
+ )
455
+
456
+ expect(record).to validate_numericality.is_equal_to(18)
457
+ end
458
+ end
459
+
460
+ context 'when the column is a float column' do
461
+ it 'accepts (and does not raise an error)' do
462
+ record = build_record_validating_numericality(
463
+ column_type: :float,
464
+ equal_to: 18
465
+ )
466
+
467
+ expect(record).to validate_numericality.is_equal_to(18)
468
+ end
469
+ end
470
+
471
+ context 'when the column is a decimal column' do
472
+ it 'accepts (and does not raise an error)' do
473
+ record = build_record_validating_numericality(
474
+ column_type: :decimal,
475
+ equal_to: 18,
476
+ )
477
+
478
+ expect(record).to validate_numericality.is_equal_to(18)
479
+ end
480
+ end
280
481
  end
281
482
 
282
483
  context 'and not validating with equal_to' do
@@ -302,6 +503,45 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
302
503
  to validate_numericality.
303
504
  is_greater_than_or_equal_to(18)
304
505
  end
506
+
507
+ context 'when the column is an integer column' do
508
+ it 'accepts (and does not raise an error)' do
509
+ record = build_record_validating_numericality(
510
+ column_type: :integer,
511
+ greater_than_or_equal_to: 18
512
+ )
513
+
514
+ expect(record).
515
+ to validate_numericality.
516
+ is_greater_than_or_equal_to(18)
517
+ end
518
+ end
519
+
520
+ context 'when the column is a float column' do
521
+ it 'accepts (and does not raise an error)' do
522
+ record = build_record_validating_numericality(
523
+ column_type: :float,
524
+ greater_than_or_equal_to: 18
525
+ )
526
+
527
+ expect(record).
528
+ to validate_numericality.
529
+ is_greater_than_or_equal_to(18)
530
+ end
531
+ end
532
+
533
+ context 'when the column is a decimal column' do
534
+ it 'accepts (and does not raise an error)' do
535
+ record = build_record_validating_numericality(
536
+ column_type: :decimal,
537
+ greater_than_or_equal_to: 18,
538
+ )
539
+
540
+ expect(record).
541
+ to validate_numericality.
542
+ is_greater_than_or_equal_to(18)
543
+ end
544
+ end
305
545
  end
306
546
 
307
547
  context 'not validating with greater_than_or_equal_to' do
@@ -327,6 +567,45 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
327
567
  to validate_numericality.
328
568
  is_greater_than(18)
329
569
  end
570
+
571
+ context 'when the column is an integer column' do
572
+ it 'accepts (and does not raise an error)' do
573
+ record = build_record_validating_numericality(
574
+ column_type: :integer,
575
+ greater_than: 18
576
+ )
577
+
578
+ expect(record).
579
+ to validate_numericality.
580
+ is_greater_than(18)
581
+ end
582
+ end
583
+
584
+ context 'when the column is a float column' do
585
+ it 'accepts (and does not raise an error)' do
586
+ record = build_record_validating_numericality(
587
+ column_type: :float,
588
+ greater_than: 18
589
+ )
590
+
591
+ expect(record).
592
+ to validate_numericality.
593
+ is_greater_than(18)
594
+ end
595
+ end
596
+
597
+ context 'when the column is a decimal column' do
598
+ it 'accepts (and does not raise an error)' do
599
+ record = build_record_validating_numericality(
600
+ column_type: :decimal,
601
+ greater_than: 18,
602
+ )
603
+
604
+ expect(record).
605
+ to validate_numericality.
606
+ is_greater_than(18)
607
+ end
608
+ end
330
609
  end
331
610
 
332
611
  context 'and not validating with greater_than' do
@@ -740,6 +1019,16 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
740
1019
  end
741
1020
  end
742
1021
 
1022
+ context 'against an ActiveModel model' do
1023
+ it 'accepts' do
1024
+ model = define_active_model_class :example, accessors: [:attr] do
1025
+ validates_numericality_of :attr
1026
+ end
1027
+
1028
+ expect(model.new).to validate_numericality_of(:attr)
1029
+ end
1030
+ end
1031
+
743
1032
  describe '#description' do
744
1033
  context 'qualified with nothing' do
745
1034
  it 'describes that it allows numbers' do
@@ -845,8 +1134,9 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
845
1134
 
846
1135
  def define_model_validating_numericality(options = {})
847
1136
  attribute_name = options.delete(:attribute_name) { self.attribute_name }
1137
+ column_type = options.delete(:column_type) { :string }
848
1138
 
849
- define_model 'Example', attribute_name => :string do |model|
1139
+ define_model 'Example', attribute_name => { type: column_type } do |model|
850
1140
  model.validates_numericality_of(attribute_name, options)
851
1141
  end
852
1142
  end
@@ -441,7 +441,7 @@ describe Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher, type: :mo
441
441
  end
442
442
 
443
443
  context 'when the model has a case-sensitive validation' do
444
- context 'when case_insensitive is not specified' do
444
+ context 'when the matcher is not qualified with case_insensitive' do
445
445
  it 'accepts' do
446
446
  record = build_record_validating_uniqueness(
447
447
  attribute_type: :string,
@@ -450,9 +450,23 @@ describe Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher, type: :mo
450
450
 
451
451
  expect(record).to validate_uniqueness
452
452
  end
453
+
454
+ context 'given an existing record where the value of the attribute under test is not case-swappable' do
455
+ it 'raises a NonCaseSwappableValueError' do
456
+ model = define_model_validating_uniqueness(
457
+ attribute_type: :string,
458
+ validation_options: { case_sensitive: true },
459
+ )
460
+ record = create_record_from(model, attribute_name => '123')
461
+ running_matcher = -> { validate_uniqueness.matches?(record) }
462
+
463
+ expect(&running_matcher).
464
+ to raise_error(described_class::NonCaseSwappableValueError)
465
+ end
466
+ end
453
467
  end
454
468
 
455
- context 'when case_insensitive is specified' do
469
+ context 'when the matcher is qualified with case_insensitive' do
456
470
  it 'rejects' do
457
471
  record = build_record_validating_uniqueness(
458
472
  attribute_type: :string,
@@ -0,0 +1,197 @@
1
+ require 'spec_helper'
2
+ require 'shoulda/matchers/util/word_wrap'
3
+
4
+ describe Shoulda::Matchers, ".word_wrap" do
5
+ it "can wrap a simple paragraph" do
6
+ wrapped_message = described_class.word_wrap(<<-MESSAGE.strip)
7
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat
8
+ MESSAGE
9
+
10
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
11
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus,
12
+ ipsum sit amet efficitur feugiat
13
+ MESSAGE
14
+ end
15
+
16
+ it "does not split words up when wrapping" do
17
+ wrapped_message = described_class.word_wrap(<<-MESSAGE.strip)
18
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean lusciousness, ipsum sit amet efficitur feugiat
19
+ MESSAGE
20
+
21
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
22
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
23
+ lusciousness, ipsum sit amet efficitur feugiat
24
+ MESSAGE
25
+ end
26
+
27
+ it "considers punctuation as part of a word" do
28
+ wrapped_message = described_class.word_wrap(<<-MESSAGE.strip)
29
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luscious, ipsum sit amet efficitur feugiat
30
+ MESSAGE
31
+
32
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
33
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
34
+ luscious, ipsum sit amet efficitur feugiat
35
+ MESSAGE
36
+ end
37
+
38
+ it "re-wraps entire paragraphs" do
39
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
40
+ Lorem ipsum dolor sit amet,
41
+ consectetur adipiscing elit.
42
+ Aenean luctus,
43
+ ipsum sit amet efficitur feugiat,
44
+ dolor mauris fringilla erat, sed posuere diam ex ut velit.
45
+ MESSAGE
46
+
47
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
48
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus,
49
+ ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed
50
+ posuere diam ex ut velit.
51
+ MESSAGE
52
+ end
53
+
54
+ it "can wrap multiple paragraphs" do
55
+ wrapped_message = described_class.word_wrap(<<-MESSAGE.strip)
56
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
57
+
58
+ Etiam ultrices cursus ligula eget feugiat. Vestibulum eget tincidunt risus, non faucibus sem.
59
+ MESSAGE
60
+
61
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
62
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus,
63
+ ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed
64
+ posuere diam ex ut velit.
65
+
66
+ Etiam ultrices cursus ligula eget feugiat. Vestibulum eget tincidunt
67
+ risus, non faucibus sem.
68
+ MESSAGE
69
+ end
70
+
71
+ it "can wrap a bulleted list" do
72
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
73
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
74
+ * And the beat goes on.
75
+ MESSAGE
76
+
77
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
78
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
79
+ luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla
80
+ erat, sed posuere diam ex ut velit.
81
+ * And the beat goes on.
82
+ MESSAGE
83
+ end
84
+
85
+ it "re-wraps bulleted lists" do
86
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
87
+ * Lorem ipsum dolor sit amet,
88
+ consectetur adipiscing elit.
89
+ Aenean luctus,
90
+ ipsum sit amet efficitur feugiat,
91
+ dolor mauris fringilla erat,
92
+ sed posuere diam ex ut velit.
93
+ * And the beat goes on.
94
+ MESSAGE
95
+
96
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
97
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
98
+ luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla
99
+ erat, sed posuere diam ex ut velit.
100
+ * And the beat goes on.
101
+ MESSAGE
102
+ end
103
+
104
+ it "can wrap a numbered list" do
105
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
106
+ 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
107
+ 2. And the beat goes on.
108
+ MESSAGE
109
+
110
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
111
+ 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
112
+ luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla
113
+ erat, sed posuere diam ex ut velit.
114
+ 2. And the beat goes on.
115
+ MESSAGE
116
+ end
117
+
118
+ it "re-wraps numbered lists" do
119
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
120
+ 1. Lorem ipsum dolor sit amet,
121
+ consectetur adipiscing elit.
122
+ Aenean luctus,
123
+ ipsum sit amet efficitur feugiat,
124
+ dolor mauris fringilla erat,
125
+ sed posuere diam ex ut velit.
126
+ 2. And the beat goes on.
127
+ MESSAGE
128
+
129
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
130
+ 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
131
+ luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla
132
+ erat, sed posuere diam ex ut velit.
133
+ 2. And the beat goes on.
134
+ MESSAGE
135
+ end
136
+
137
+ it "can wrap a numbered list, using x) instead of x. as the leader" do
138
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
139
+ 1) Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
140
+ 2) And the beat goes on.
141
+ MESSAGE
142
+
143
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
144
+ 1) Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
145
+ luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla
146
+ erat, sed posuere diam ex ut velit.
147
+ 2) And the beat goes on.
148
+ MESSAGE
149
+ end
150
+
151
+ it "re-wraps numbered lists using x) instead of x. as the leader" do
152
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
153
+ 1) Lorem ipsum dolor sit amet,
154
+ consectetur adipiscing elit.
155
+ Aenean luctus,
156
+ ipsum sit amet efficitur feugiat,
157
+ dolor mauris fringilla erat,
158
+ sed posuere diam ex ut velit.
159
+ 2) And the beat goes on.
160
+ MESSAGE
161
+
162
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
163
+ 1) Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
164
+ luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla
165
+ erat, sed posuere diam ex ut velit.
166
+ 2) And the beat goes on.
167
+ MESSAGE
168
+ end
169
+
170
+ it "doesn't mess with indented blocks" do
171
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
172
+ Some text is gonna go here.
173
+
174
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
175
+
176
+ And now we return.
177
+ MESSAGE
178
+
179
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
180
+ Some text is gonna go here.
181
+
182
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
183
+
184
+ And now we return.
185
+ MESSAGE
186
+ end
187
+
188
+ it "doesn't get stuck trying to wrap a line that can't be wrapped" do
189
+ wrapped_message = described_class.word_wrap(<<-MESSAGE)
190
+ Loremipsumdolorsitamet,consecteturadipiscingelit.Aeneanluctus,ipsumsitametefficiturfeugiat,
191
+ MESSAGE
192
+
193
+ expect(wrapped_message).to eq(<<-MESSAGE.strip)
194
+ Loremipsumdolorsitamet,consecteturadipiscingelit.Aeneanluctus,ipsumsitametefficiturfeugiat,
195
+ MESSAGE
196
+ end
197
+ end