super_diff 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +24 -12
  3. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +15 -6
  4. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +23 -8
  5. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  6. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +4 -0
  7. data/lib/super_diff/active_support.rb +2 -1
  8. data/lib/super_diff/differs/date_like.rb +15 -0
  9. data/lib/super_diff/differs/defaults.rb +1 -0
  10. data/lib/super_diff/differs.rb +1 -0
  11. data/lib/super_diff/errors.rb +0 -4
  12. data/lib/super_diff/object_inspection/inspection_tree.rb +25 -20
  13. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +31 -12
  14. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +19 -9
  15. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  16. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +46 -21
  17. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -0
  18. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +39 -14
  19. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  20. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +31 -20
  21. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +4 -0
  22. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +3 -2
  23. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  24. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  25. data/lib/super_diff/operation_tree_builders.rb +1 -0
  26. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +3 -7
  27. data/lib/super_diff/rspec/monkey_patches.rb +59 -8
  28. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  29. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +19 -13
  30. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +30 -26
  31. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  32. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +19 -14
  33. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +9 -10
  34. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +9 -10
  35. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  36. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  37. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +4 -0
  38. data/lib/super_diff/rspec.rb +10 -9
  39. data/lib/super_diff/version.rb +1 -1
  40. data/lib/super_diff.rb +9 -0
  41. data/spec/examples.txt +543 -493
  42. data/spec/integration/rails/engines_spec.rb +8 -3
  43. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
  44. data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
  45. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  46. data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
  47. data/spec/integration/rspec/include_matcher_spec.rb +23 -23
  48. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  49. data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
  50. data/spec/integration/rspec/match_matcher_spec.rb +93 -93
  51. data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
  52. data/spec/internal/log/test.log +0 -0
  53. data/spec/spec_helper.rb +3 -0
  54. data/spec/support/integration/helpers.rb +15 -10
  55. data/spec/support/integration/matchers.rb +34 -0
  56. data/spec/support/integration/test_programs/base.rb +6 -6
  57. data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
  58. data/spec/support/shared_examples/active_record.rb +33 -33
  59. data/spec/support/shared_examples/active_support.rb +125 -4
  60. data/spec/support/shared_examples/elided_diffs.rb +48 -48
  61. data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
  62. data/spec/support/shared_examples/key.rb +10 -10
  63. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  64. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  65. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  66. data/spec/unit/rspec/object_inspection_spec.rb +2 -2
  67. data/spec/unit/super_diff_spec.rb +64 -0
  68. metadata +17 -4
  69. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  70. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
@@ -5,7 +5,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
5
5
  context "given only an exception class" do
6
6
  context "when used in the positive" do
7
7
  context "when the block raises a different error than what is given" do
8
- context "when the message is short" do
8
+ context "when the actual message is short" do
9
9
  it "produces the correct failure message" do
10
10
  as_both_colored_and_uncolored do |color_enabled|
11
11
  snippet = <<~TEST.strip
@@ -25,7 +25,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
25
25
  plain "Expected raised exception "
26
26
  actual %|#<StandardError "boo">|
27
27
  plain " to match "
28
- expected "#<RuntimeError>"
28
+ expected "a kind of RuntimeError"
29
29
  plain "."
30
30
  end
31
31
  end
@@ -38,7 +38,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
38
38
  end
39
39
  end
40
40
 
41
- context "when the message is long" do
41
+ context "when the actual message is long" do
42
42
  it "produces the correct failure message" do
43
43
  as_both_colored_and_uncolored do |color_enabled|
44
44
  snippet = <<~TEST.strip
@@ -62,7 +62,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
62
62
 
63
63
  line do
64
64
  plain " to match "
65
- expected "#<RuntimeError>"
65
+ expected "a kind of RuntimeError"
66
66
  end
67
67
  end
68
68
  )
@@ -91,8 +91,10 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
91
91
  expectation:
92
92
  proc do
93
93
  line do
94
- plain "Expected block to raise error "
95
- expected "#<RuntimeError>"
94
+ plain "Expected "
95
+ actual "exception-free block"
96
+ plain " to raise "
97
+ expected "a kind of RuntimeError"
96
98
  plain "."
97
99
  end
98
100
  end
@@ -107,7 +109,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
107
109
  end
108
110
 
109
111
  context "when used in the negative" do
110
- context "when the message is short" do
112
+ context "when the actual message is short" do
111
113
  it "produces the correct failure message" do
112
114
  as_both_colored_and_uncolored do |color_enabled|
113
115
  snippet = <<~TEST.strip
@@ -127,7 +129,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
127
129
  plain "Expected raised exception "
128
130
  actual %|#<StandardError "boo">|
129
131
  plain " not to match "
130
- expected "#<StandardError>"
132
+ expected "a kind of StandardError"
131
133
  plain "."
132
134
  end
133
135
  end
@@ -140,7 +142,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
140
142
  end
141
143
  end
142
144
 
143
- context "when the message is long" do
145
+ context "when the actual message is long" do
144
146
  it "produces the correct failure message" do
145
147
  as_both_colored_and_uncolored do |color_enabled|
146
148
  snippet = <<~TEST.strip
@@ -164,7 +166,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
164
166
 
165
167
  line do
166
168
  plain " not to match "
167
- expected "#<StandardError>"
169
+ expected "a kind of StandardError"
168
170
  end
169
171
  end
170
172
  )
@@ -178,10 +180,10 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
178
180
  end
179
181
  end
180
182
 
181
- context "with only a message (and assuming a RuntimeError)" do
183
+ context "given only a string message" do
182
184
  context "when used in the positive" do
183
185
  context "when the block raises a different error than what is given" do
184
- context "when the message is short" do
186
+ context "when the expected and/or actual message is short" do
185
187
  it "produces the correct failure message" do
186
188
  as_both_colored_and_uncolored do |color_enabled|
187
189
  snippet = <<~TEST.strip
@@ -200,7 +202,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
200
202
  plain "Expected raised exception "
201
203
  actual %|#<RuntimeError "boo">|
202
204
  plain " to match "
203
- expected %|#<Exception "hell">|
205
+ expected %|a kind of Exception with message "hell"|
204
206
  plain "."
205
207
  end
206
208
  end
@@ -213,7 +215,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
213
215
  end
214
216
  end
215
217
 
216
- context "when the message is long" do
218
+ context "when the expected and/or actual message is long" do
217
219
  context "but contains no line breaks" do
218
220
  it "produces the correct failure message when used in the positive" do
219
221
  as_both_colored_and_uncolored do |color_enabled|
@@ -240,7 +242,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
240
242
 
241
243
  line do
242
244
  plain " to match "
243
- expected %|#<Exception "whatever">|
245
+ expected %|a kind of Exception with message "whatever"|
244
246
  end
245
247
  end
246
248
  )
@@ -283,7 +285,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
283
285
 
284
286
  line do
285
287
  plain " to match "
286
- expected %|#<Exception "This is fun\\nAnd so is this">|
288
+ expected %|a kind of Exception with message "This is fun\\nAnd so is this"|
287
289
  end
288
290
  end,
289
291
  diff:
@@ -304,7 +306,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
304
306
  end
305
307
 
306
308
  context "when the block raises no error" do
307
- context "when the message is short" do
309
+ context "when the expected message is short" do
308
310
  it "produces the correct failure message" do
309
311
  as_both_colored_and_uncolored do |color_enabled|
310
312
  snippet = <<~TEST.strip
@@ -320,8 +322,10 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
320
322
  expectation:
321
323
  proc do
322
324
  line do
323
- plain "Expected block to raise error "
324
- expected %|#<Exception "hell">|
325
+ plain "Expected "
326
+ actual "exception-free block"
327
+ plain " to raise "
328
+ expected %|a kind of Exception with message "hell"|
325
329
  plain "."
326
330
  end
327
331
  end
@@ -334,7 +338,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
334
338
  end
335
339
  end
336
340
 
337
- context "when the message is long" do
341
+ context "when the expected message is long" do
338
342
  context "but contains no line breaks" do
339
343
  it "produces the correct failure message" do
340
344
  as_both_colored_and_uncolored do |color_enabled|
@@ -352,14 +356,15 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
352
356
  newline_before_expectation: true,
353
357
  expectation:
354
358
  proc do
359
+ # stree-ignore
355
360
  line do
356
- plain " Expected "
357
- plain "block"
361
+ plain "Expected "
362
+ actual "exception-free block"
358
363
  end
359
364
 
360
365
  line do
361
- plain "to raise error "
362
- expected %|#<Exception "this is a super super super super super super long message">|
366
+ plain "to raise "
367
+ expected %|a kind of Exception with message "this is a super super super super super super long message"|
363
368
  end
364
369
  end
365
370
  )
@@ -372,11 +377,15 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
372
377
  end
373
378
 
374
379
  context "but contains line breaks" do
375
- it "produces the correct failure message when used in the negative" do
380
+ it "produces the correct failure message" do
376
381
  as_both_colored_and_uncolored do |color_enabled|
377
382
  snippet = <<~TEST.strip
378
- message = "some really long message"
379
- expect { raise(message) }.not_to raise_error(message)
383
+ expected_message = <<\~MESSAGE.rstrip
384
+ this is a super super
385
+ super super super
386
+ super long message
387
+ MESSAGE
388
+ expect { }.to raise_error(expected_message)
380
389
  TEST
381
390
  program =
382
391
  make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -384,19 +393,19 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
384
393
  expected_output =
385
394
  build_expected_output(
386
395
  color_enabled: color_enabled,
387
- snippet:
388
- "expect { raise(message) }.not_to raise_error(message)",
396
+ snippet: "expect { }.to raise_error(expected_message)",
389
397
  newline_before_expectation: true,
390
398
  expectation:
391
399
  proc do
400
+ # stree-ignore
392
401
  line do
393
- plain "Expected raised exception "
394
- actual %|#<RuntimeError "some really long message">|
402
+ plain "Expected "
403
+ actual "exception-free block"
395
404
  end
396
405
 
397
406
  line do
398
- plain " not to match "
399
- expected %|#<Exception "some really long message">|
407
+ plain "to raise "
408
+ expected %|a kind of Exception with message "this is a super super\\nsuper super super\\nsuper long message"|
400
409
  end
401
410
  end
402
411
  )
@@ -412,7 +421,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
412
421
  end
413
422
 
414
423
  context "when used in the negative" do
415
- context "when the message is short" do
424
+ context "when the expected and/or actual message is short" do
416
425
  it "produces the correct failure message" do
417
426
  as_both_colored_and_uncolored do |color_enabled|
418
427
  snippet = <<~TEST.strip
@@ -431,7 +440,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
431
440
  plain "Expected raised exception "
432
441
  actual %|#<RuntimeError "boo">|
433
442
  plain " not to match "
434
- expected %|#<Exception "boo">|
443
+ expected %|a kind of Exception with message "boo"|
435
444
  plain "."
436
445
  end
437
446
  end
@@ -444,7 +453,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
444
453
  end
445
454
  end
446
455
 
447
- context "when the message is long" do
456
+ context "when the expected and/or actual message is long" do
448
457
  context "but contains no line breaks" do
449
458
  it "produces the correct failure message" do
450
459
  as_both_colored_and_uncolored do |color_enabled|
@@ -470,7 +479,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
470
479
 
471
480
  line do
472
481
  plain " not to match "
473
- expected %|#<Exception "some really long message">|
482
+ expected %|a kind of Exception with message "some really long message"|
474
483
  end
475
484
  end
476
485
  )
@@ -487,8 +496,9 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
487
496
  as_both_colored_and_uncolored do |color_enabled|
488
497
  snippet = <<~TEST.strip
489
498
  message = <<\~MESSAGE.rstrip
490
- This is fun
491
- So is this
499
+ this is a super super
500
+ super super super
501
+ super long message
492
502
  MESSAGE
493
503
  expect { raise(message) }.not_to raise_error(message)
494
504
  TEST
@@ -505,12 +515,121 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
505
515
  proc do
506
516
  line do
507
517
  plain "Expected raised exception "
508
- actual %|#<RuntimeError "This is fun\\nSo is this">|
518
+ actual %|#<RuntimeError "this is a super super\\nsuper super super\\nsuper long message">|
509
519
  end
510
520
 
511
521
  line do
512
522
  plain " not to match "
513
- expected %|#<Exception "This is fun\\nSo is this">|
523
+ expected %|a kind of Exception with message "this is a super super\\nsuper super super\\nsuper long message"|
524
+ end
525
+ end
526
+ )
527
+
528
+ expect(program).to produce_output_when_run(
529
+ expected_output
530
+ ).in_color(color_enabled)
531
+ end
532
+ end
533
+ end
534
+ end
535
+ end
536
+ end
537
+
538
+ context "given only a regexp message" do
539
+ context "when used in the positive" do
540
+ context "when the block raises a different error than what is given" do
541
+ it "produces the correct failure message" do
542
+ as_both_colored_and_uncolored do |color_enabled|
543
+ snippet = <<~TEST.strip
544
+ expect { raise 'boo' }.to raise_error(/hell/i)
545
+ TEST
546
+ program =
547
+ make_plain_test_program(snippet, color_enabled: color_enabled)
548
+
549
+ expected_output =
550
+ build_expected_output(
551
+ color_enabled: color_enabled,
552
+ snippet: "expect { raise 'boo' }.to raise_error(/hell/i)",
553
+ newline_before_expectation: true,
554
+ expectation:
555
+ proc do
556
+ line do
557
+ plain "Expected raised exception "
558
+ actual %|#<RuntimeError "boo">|
559
+ end
560
+
561
+ line do
562
+ plain " to match "
563
+ expected "a kind of Exception with message matching /hell/i"
564
+ end
565
+ end
566
+ )
567
+
568
+ expect(program).to produce_output_when_run(
569
+ expected_output
570
+ ).in_color(color_enabled)
571
+ end
572
+ end
573
+ end
574
+
575
+ context "when the block raises no error" do
576
+ context "when the expected message is short" do
577
+ it "produces the correct failure message" do
578
+ as_both_colored_and_uncolored do |color_enabled|
579
+ snippet = <<~TEST.strip
580
+ expect { }.to raise_error(/hell/i)
581
+ TEST
582
+ program =
583
+ make_plain_test_program(snippet, color_enabled: color_enabled)
584
+
585
+ expected_output =
586
+ build_expected_output(
587
+ color_enabled: color_enabled,
588
+ snippet: "expect { }.to raise_error(/hell/i)",
589
+ expectation:
590
+ proc do
591
+ line do
592
+ plain "Expected "
593
+ actual "exception-free block"
594
+ plain " to raise "
595
+ expected "a kind of Exception with message matching /hell/i"
596
+ plain "."
597
+ end
598
+ end
599
+ )
600
+
601
+ expect(program).to produce_output_when_run(
602
+ expected_output
603
+ ).in_color(color_enabled)
604
+ end
605
+ end
606
+ end
607
+
608
+ context "when the expected message is long" do
609
+ it "produces the correct failure message" do
610
+ as_both_colored_and_uncolored do |color_enabled|
611
+ snippet = <<~TEST.strip
612
+ expect { }.to raise_error(/this is a super super super super super super long message/i)
613
+ TEST
614
+ program =
615
+ make_plain_test_program(snippet, color_enabled: color_enabled)
616
+
617
+ expected_output =
618
+ build_expected_output(
619
+ color_enabled: color_enabled,
620
+ snippet:
621
+ "expect { }.to raise_error(/this is a super super super super super super long message/i)",
622
+ newline_before_expectation: true,
623
+ expectation:
624
+ proc do
625
+ line do
626
+ plain "Expected "
627
+ actual "exception-free block"
628
+ end
629
+
630
+ line do
631
+ plain "to raise "
632
+ expected "a kind of Exception with message matching /this is a super super super super super super long message/i"
514
633
  end
515
634
  end
516
635
  )
@@ -523,12 +642,47 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
523
642
  end
524
643
  end
525
644
  end
645
+
646
+ context "when used in the negative" do
647
+ it "produces the correct failure message" do
648
+ as_both_colored_and_uncolored do |color_enabled|
649
+ snippet = <<~TEST.strip
650
+ expect { raise 'boo' }.not_to raise_error(/boo/i)
651
+ TEST
652
+ program =
653
+ make_plain_test_program(snippet, color_enabled: color_enabled)
654
+
655
+ expected_output =
656
+ build_expected_output(
657
+ color_enabled: color_enabled,
658
+ snippet: "expect { raise 'boo' }.not_to raise_error(/boo/i)",
659
+ newline_before_expectation: true,
660
+ expectation:
661
+ proc do
662
+ line do
663
+ plain "Expected raised exception "
664
+ actual %|#<RuntimeError "boo">|
665
+ end
666
+
667
+ line do
668
+ plain " not to match "
669
+ expected "a kind of Exception with message matching /boo/i"
670
+ end
671
+ end
672
+ )
673
+
674
+ expect(program).to produce_output_when_run(expected_output).in_color(
675
+ color_enabled
676
+ )
677
+ end
678
+ end
679
+ end
526
680
  end
527
681
 
528
- context "with both an exception and a message" do
682
+ context "given both an exception class and string message" do
529
683
  context "when used in the positive" do
530
684
  context "when the block raises a different error than what is given" do
531
- context "when the message is short" do
685
+ context "when the expected and/or actual message is short" do
532
686
  it "produces the correct failure message" do
533
687
  as_both_colored_and_uncolored do |color_enabled|
534
688
  snippet = <<~TEST.strip
@@ -548,7 +702,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
548
702
  plain "Expected raised exception "
549
703
  actual %|#<StandardError "a">|
550
704
  plain " to match "
551
- expected %|#<RuntimeError "b">|
705
+ expected %|a kind of RuntimeError with message "b"|
552
706
  plain "."
553
707
  end
554
708
  end
@@ -561,7 +715,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
561
715
  end
562
716
  end
563
717
 
564
- context "when the message is long" do
718
+ context "when the expected and/or actual message is long" do
565
719
  it "produces the correct failure message" do
566
720
  as_both_colored_and_uncolored do |color_enabled|
567
721
  snippet = <<~TEST.strip
@@ -586,7 +740,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
586
740
 
587
741
  line do
588
742
  plain " to match "
589
- expected %|#<RuntimeError "this is another long message">|
743
+ expected %|a kind of RuntimeError with message "this is another long message"|
590
744
  end
591
745
  end
592
746
  )
@@ -600,7 +754,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
600
754
  end
601
755
 
602
756
  context "when the block raises no error" do
603
- context "when the message is short" do
757
+ context "when the expected message is short" do
604
758
  it "produces the correct failure message" do
605
759
  as_both_colored_and_uncolored do |color_enabled|
606
760
  snippet = <<~TEST.strip
@@ -616,8 +770,10 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
616
770
  expectation:
617
771
  proc do
618
772
  line do
619
- plain "Expected block to raise error "
620
- expected %|#<RuntimeError "b">|
773
+ plain "Expected "
774
+ actual "exception-free block"
775
+ plain " to raise "
776
+ expected %|a kind of RuntimeError with message "b"|
621
777
  plain "."
622
778
  end
623
779
  end
@@ -630,7 +786,7 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
630
786
  end
631
787
  end
632
788
 
633
- context "when the message is long" do
789
+ context "when the expected message is long" do
634
790
  it "produces the correct failure message" do
635
791
  as_both_colored_and_uncolored do |color_enabled|
636
792
  snippet = <<~TEST.strip
@@ -648,13 +804,13 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
648
804
  expectation:
649
805
  proc do
650
806
  line do
651
- plain " Expected "
652
- plain "block"
807
+ plain "Expected "
808
+ actual "exception-free block"
653
809
  end
654
810
 
655
811
  line do
656
- plain "to raise error "
657
- expected %|#<RuntimeError "this is a super super super super super super long message">|
812
+ plain "to raise "
813
+ expected %|a kind of RuntimeError with message "this is a super super super super super super long message"|
658
814
  end
659
815
  end
660
816
  )
@@ -669,12 +825,50 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
669
825
  end
670
826
 
671
827
  context "when used in the negative" do
672
- context "when the message is short" do
828
+ it "produces the correct failure message" do
829
+ as_both_colored_and_uncolored do |color_enabled|
830
+ snippet = <<~TEST.strip
831
+ block = -> { raise StandardError.new('a') }
832
+ expect(&block).not_to raise_error(StandardError, 'a')
833
+ TEST
834
+ program =
835
+ make_plain_test_program(snippet, color_enabled: color_enabled)
836
+
837
+ expected_output =
838
+ build_expected_output(
839
+ color_enabled: color_enabled,
840
+ snippet: "expect(&block).not_to raise_error(StandardError, 'a')",
841
+ newline_before_expectation: true,
842
+ expectation:
843
+ proc do
844
+ line do
845
+ plain "Expected raised exception "
846
+ actual %|#<StandardError "a">|
847
+ end
848
+
849
+ line do
850
+ plain " not to match "
851
+ expected %|a kind of StandardError with message "a"|
852
+ end
853
+ end
854
+ )
855
+
856
+ expect(program).to produce_output_when_run(expected_output).in_color(
857
+ color_enabled
858
+ )
859
+ end
860
+ end
861
+ end
862
+ end
863
+
864
+ context "given both an exception class and regexp message" do
865
+ context "when used in the positive" do
866
+ context "when the block raises a different error than what is given" do
673
867
  it "produces the correct failure message" do
674
868
  as_both_colored_and_uncolored do |color_enabled|
675
869
  snippet = <<~TEST.strip
676
870
  block = -> { raise StandardError.new('a') }
677
- expect(&block).not_to raise_error(StandardError, 'a')
871
+ expect(&block).to raise_error(RuntimeError, /b/i)
678
872
  TEST
679
873
  program =
680
874
  make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -682,16 +876,18 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
682
876
  expected_output =
683
877
  build_expected_output(
684
878
  color_enabled: color_enabled,
685
- snippet:
686
- "expect(&block).not_to raise_error(StandardError, 'a')",
879
+ snippet: "expect(&block).to raise_error(RuntimeError, /b/i)",
880
+ newline_before_expectation: true,
687
881
  expectation:
688
882
  proc do
689
883
  line do
690
884
  plain "Expected raised exception "
691
885
  actual %|#<StandardError "a">|
692
- plain " not to match "
693
- expected %|#<StandardError "a">|
694
- plain "."
886
+ end
887
+
888
+ line do
889
+ plain " to match "
890
+ expected "a kind of RuntimeError with message matching /b/i"
695
891
  end
696
892
  end
697
893
  )
@@ -703,12 +899,191 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
703
899
  end
704
900
  end
705
901
 
706
- context "when the message is long" do
902
+ context "when the block raises no error" do
903
+ context "when the expected message is short" do
904
+ it "produces the correct failure message" do
905
+ as_both_colored_and_uncolored do |color_enabled|
906
+ snippet = <<~TEST.strip
907
+ expect { }.to raise_error(RuntimeError, /b/i)
908
+ TEST
909
+ program =
910
+ make_plain_test_program(snippet, color_enabled: color_enabled)
911
+
912
+ expected_output =
913
+ build_expected_output(
914
+ color_enabled: color_enabled,
915
+ snippet: "expect { }.to raise_error(RuntimeError, /b/i)",
916
+ expectation:
917
+ proc do
918
+ line do
919
+ plain "Expected "
920
+ actual "exception-free block"
921
+ plain " to raise "
922
+ expected "a kind of RuntimeError with message matching /b/i"
923
+ end
924
+ end
925
+ )
926
+
927
+ expect(program).to produce_output_when_run(
928
+ expected_output
929
+ ).in_color(color_enabled)
930
+ end
931
+ end
932
+ end
933
+
934
+ context "when the expected message is long" do
935
+ it "produces the correct failure message" do
936
+ as_both_colored_and_uncolored do |color_enabled|
937
+ snippet = <<~TEST.strip
938
+ expect { }.to raise_error(RuntimeError, /this is a super super super super super super long message/i)
939
+ TEST
940
+ program =
941
+ make_plain_test_program(snippet, color_enabled: color_enabled)
942
+
943
+ expected_output =
944
+ build_expected_output(
945
+ color_enabled: color_enabled,
946
+ snippet:
947
+ "expect { }.to raise_error(RuntimeError, /this is a super super super super super super long message/i)",
948
+ newline_before_expectation: true,
949
+ expectation:
950
+ proc do
951
+ line do
952
+ plain "Expected "
953
+ actual "exception-free block"
954
+ end
955
+
956
+ line do
957
+ plain "to raise "
958
+ expected "a kind of RuntimeError with message matching /this is a super super super super super super long message/i"
959
+ end
960
+ end
961
+ )
962
+
963
+ expect(program).to produce_output_when_run(
964
+ expected_output
965
+ ).in_color(color_enabled)
966
+ end
967
+ end
968
+ end
969
+ end
970
+ end
971
+
972
+ context "when used in the negative" do
973
+ it "produces the correct failure message" do
974
+ as_both_colored_and_uncolored do |color_enabled|
975
+ snippet = <<~TEST.strip
976
+ block = -> { raise StandardError.new('a') }
977
+ expect(&block).not_to raise_error(StandardError, /a/i)
978
+ TEST
979
+ program =
980
+ make_plain_test_program(snippet, color_enabled: color_enabled)
981
+
982
+ expected_output =
983
+ build_expected_output(
984
+ color_enabled: color_enabled,
985
+ snippet: "expect(&block).not_to raise_error(StandardError, /a/i)",
986
+ newline_before_expectation: true,
987
+ expectation:
988
+ proc do
989
+ line do
990
+ plain "Expected raised exception "
991
+ actual %|#<StandardError "a">|
992
+ end
993
+
994
+ line do
995
+ plain " not to match "
996
+ expected "a kind of StandardError with message matching /a/i"
997
+ end
998
+ end
999
+ )
1000
+
1001
+ expect(program).to produce_output_when_run(expected_output).in_color(
1002
+ color_enabled
1003
+ )
1004
+ end
1005
+ end
1006
+ end
1007
+ end
1008
+
1009
+ context "given a simple RSpec matcher" do
1010
+ context "when used in the positive" do
1011
+ context "when the block raises a different error than what is given" do
1012
+ context "when the expected error and/or actual message is short" do
1013
+ it "produces the correct failure message" do
1014
+ as_both_colored_and_uncolored do |color_enabled|
1015
+ snippet = <<~TEST.strip
1016
+ expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array))
1017
+ TEST
1018
+ program =
1019
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1020
+
1021
+ expected_output =
1022
+ build_expected_output(
1023
+ color_enabled: color_enabled,
1024
+ snippet:
1025
+ "expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array))",
1026
+ expectation:
1027
+ proc do
1028
+ line do
1029
+ plain "Expected raised exception "
1030
+ actual %|#<StandardError "boo">|
1031
+ plain " to match "
1032
+ expected "#<a kind of Array>"
1033
+ plain "."
1034
+ end
1035
+ end
1036
+ )
1037
+
1038
+ expect(program).to produce_output_when_run(
1039
+ expected_output
1040
+ ).in_color(color_enabled)
1041
+ end
1042
+ end
1043
+ end
1044
+
1045
+ context "when the expected error and/or actual message is long" do
1046
+ it "produces the correct failure message" do
1047
+ as_both_colored_and_uncolored do |color_enabled|
1048
+ snippet = <<~TEST.strip
1049
+ expect { raise StandardError.new('this is a super super super long message') }.to raise_error(a_kind_of(RuntimeError))
1050
+ TEST
1051
+ program =
1052
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1053
+
1054
+ expected_output =
1055
+ build_expected_output(
1056
+ color_enabled: color_enabled,
1057
+ snippet:
1058
+ "expect { raise StandardError.new('this is a super super super long message') }.to raise_error(a_kind_of(RuntimeError))",
1059
+ newline_before_expectation: true,
1060
+ expectation:
1061
+ proc do
1062
+ line do
1063
+ plain "Expected raised exception "
1064
+ actual %|#<StandardError "this is a super super super long message">|
1065
+ end
1066
+
1067
+ line do
1068
+ plain " to match "
1069
+ expected "#<a kind of RuntimeError>"
1070
+ end
1071
+ end
1072
+ )
1073
+
1074
+ expect(program).to produce_output_when_run(
1075
+ expected_output
1076
+ ).in_color(color_enabled)
1077
+ end
1078
+ end
1079
+ end
1080
+ end
1081
+
1082
+ context "when the block raises no error" do
707
1083
  it "produces the correct failure message" do
708
1084
  as_both_colored_and_uncolored do |color_enabled|
709
1085
  snippet = <<~TEST.strip
710
- block = -> { raise StandardError.new('this is a long message') }
711
- expect(&block).not_to raise_error(StandardError, 'this is a long message')
1086
+ expect { }.to raise_error(a_kind_of(RuntimeError))
712
1087
  TEST
713
1088
  program =
714
1089
  make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -716,19 +1091,388 @@ RSpec.describe "Integration with RSpec's #raise_error matcher",
716
1091
  expected_output =
717
1092
  build_expected_output(
718
1093
  color_enabled: color_enabled,
719
- snippet:
720
- "expect(&block).not_to raise_error(StandardError, 'this is a long message')",
721
- newline_before_expectation: true,
1094
+ snippet: "expect { }.to raise_error(a_kind_of(RuntimeError))",
1095
+ expectation:
1096
+ proc do
1097
+ line do
1098
+ plain "Expected "
1099
+ actual "exception-free block"
1100
+ plain " to raise "
1101
+ expected "#<a kind of RuntimeError>"
1102
+ plain "."
1103
+ end
1104
+ end
1105
+ )
1106
+
1107
+ expect(program).to produce_output_when_run(
1108
+ expected_output
1109
+ ).in_color(color_enabled)
1110
+ end
1111
+ end
1112
+ end
1113
+ end
1114
+
1115
+ context "when used in the negative" do
1116
+ context "when the expected error and/or actual message is short" do
1117
+ it "produces the correct failure message" do
1118
+ as_both_colored_and_uncolored do |color_enabled|
1119
+ snippet = <<~TEST.strip
1120
+ expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError))
1121
+ TEST
1122
+ program =
1123
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1124
+
1125
+ expected_output =
1126
+ build_expected_output(
1127
+ color_enabled: color_enabled,
1128
+ snippet:
1129
+ "expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError))",
1130
+ expectation:
1131
+ proc do
1132
+ line do
1133
+ plain "Expected raised exception "
1134
+ actual %|#<StandardError "boo">|
1135
+ plain " not to match "
1136
+ expected "#<a kind of StandardError>"
1137
+ plain "."
1138
+ end
1139
+ end
1140
+ )
1141
+
1142
+ expect(program).to produce_output_when_run(
1143
+ expected_output
1144
+ ).in_color(color_enabled)
1145
+ end
1146
+ end
1147
+ end
1148
+
1149
+ context "when the expected error and/or actual message is long" do
1150
+ it "produces the correct failure message" do
1151
+ as_both_colored_and_uncolored do |color_enabled|
1152
+ snippet = <<~TEST.strip
1153
+ expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError))
1154
+ TEST
1155
+ program =
1156
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1157
+
1158
+ expected_output =
1159
+ build_expected_output(
1160
+ color_enabled: color_enabled,
1161
+ snippet:
1162
+ "expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError))",
1163
+ newline_before_expectation: true,
1164
+ expectation:
1165
+ proc do
1166
+ line do
1167
+ plain "Expected raised exception "
1168
+ actual %|#<StandardError "this is a super super long message">|
1169
+ end
1170
+
1171
+ line do
1172
+ plain " not to match "
1173
+ expected "#<a kind of StandardError>"
1174
+ end
1175
+ end
1176
+ )
1177
+
1178
+ expect(program).to produce_output_when_run(
1179
+ expected_output
1180
+ ).in_color(color_enabled)
1181
+ end
1182
+ end
1183
+ end
1184
+ end
1185
+ end
1186
+
1187
+ context "given only a simple RSpec matcher and string message" do
1188
+ context "when used in the positive" do
1189
+ context "when the block raises a different error than what is given" do
1190
+ it "produces the correct failure message" do
1191
+ as_both_colored_and_uncolored do |color_enabled|
1192
+ snippet = <<~TEST.strip
1193
+ expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), "boo")
1194
+ TEST
1195
+ program =
1196
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1197
+
1198
+ expected_output =
1199
+ build_expected_output(
1200
+ color_enabled: color_enabled,
1201
+ snippet:
1202
+ %|expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), "boo")|,
1203
+ newline_before_expectation: true,
1204
+ expectation:
1205
+ proc do
1206
+ line do
1207
+ plain "Expected raised exception "
1208
+ actual %|#<StandardError "boo">|
1209
+ end
1210
+
1211
+ line do
1212
+ plain " to match "
1213
+ expected %|#<a kind of RuntimeError> with message "boo"|
1214
+ end
1215
+ end
1216
+ )
1217
+
1218
+ expect(program).to produce_output_when_run(
1219
+ expected_output
1220
+ ).in_color(color_enabled)
1221
+ end
1222
+ end
1223
+ end
1224
+ end
1225
+
1226
+ context "when used in the negative" do
1227
+ it "produces the correct failure message" do
1228
+ as_both_colored_and_uncolored do |color_enabled|
1229
+ snippet = <<~TEST.strip
1230
+ expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), "boo")
1231
+ TEST
1232
+ program =
1233
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1234
+
1235
+ expected_output =
1236
+ build_expected_output(
1237
+ color_enabled: color_enabled,
1238
+ snippet:
1239
+ %|expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), "boo")|,
1240
+ newline_before_expectation: true,
1241
+ expectation:
1242
+ proc do
1243
+ line do
1244
+ plain "Expected raised exception "
1245
+ actual %|#<StandardError "boo">|
1246
+ end
1247
+
1248
+ line do
1249
+ plain " not to match "
1250
+ expected %|#<a kind of StandardError> with message "boo"|
1251
+ end
1252
+ end
1253
+ )
1254
+
1255
+ expect(program).to produce_output_when_run(expected_output).in_color(
1256
+ color_enabled
1257
+ )
1258
+ end
1259
+ end
1260
+ end
1261
+ end
1262
+
1263
+ context "given only a simple RSpec matcher and regexp message" do
1264
+ context "when used in the positive" do
1265
+ context "when the block raises a different error than what is given" do
1266
+ it "produces the correct failure message" do
1267
+ as_both_colored_and_uncolored do |color_enabled|
1268
+ snippet = <<~TEST.strip
1269
+ expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), /boo/i)
1270
+ TEST
1271
+ program =
1272
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1273
+
1274
+ expected_output =
1275
+ build_expected_output(
1276
+ color_enabled: color_enabled,
1277
+ snippet:
1278
+ "expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), /boo/i)",
1279
+ newline_before_expectation: true,
722
1280
  expectation:
723
1281
  proc do
724
1282
  line do
725
1283
  plain "Expected raised exception "
726
- actual %|#<StandardError "this is a long message">|
1284
+ actual %|#<StandardError "boo">|
1285
+ end
1286
+
1287
+ line do
1288
+ plain " to match "
1289
+ expected "#<a kind of RuntimeError> with message matching /boo/i"
1290
+ end
1291
+ end
1292
+ )
1293
+
1294
+ expect(program).to produce_output_when_run(
1295
+ expected_output
1296
+ ).in_color(color_enabled)
1297
+ end
1298
+ end
1299
+ end
1300
+ end
1301
+
1302
+ context "when used in the negative" do
1303
+ it "produces the correct failure message" do
1304
+ as_both_colored_and_uncolored do |color_enabled|
1305
+ snippet = <<~TEST.strip
1306
+ expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), /boo/i)
1307
+ TEST
1308
+ program =
1309
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1310
+
1311
+ expected_output =
1312
+ build_expected_output(
1313
+ color_enabled: color_enabled,
1314
+ snippet:
1315
+ "expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), /boo/i)",
1316
+ newline_before_expectation: true,
1317
+ expectation:
1318
+ proc do
1319
+ line do
1320
+ plain "Expected raised exception "
1321
+ actual %|#<StandardError "boo">|
1322
+ end
1323
+
1324
+ line do
1325
+ plain " not to match "
1326
+ expected "#<a kind of StandardError> with message matching /boo/i"
1327
+ end
1328
+ end
1329
+ )
1330
+
1331
+ expect(program).to produce_output_when_run(expected_output).in_color(
1332
+ color_enabled
1333
+ )
1334
+ end
1335
+ end
1336
+ end
1337
+ end
1338
+
1339
+ # NOTE: No need to test this using a string or regexp message — we've tested
1340
+ # it enough above
1341
+ context "given a compound RSpec matcher" do
1342
+ context "when used in the positive" do
1343
+ context "when the block raises a different error than what is given" do
1344
+ context "when the expected error and/or actual message is short" do
1345
+ it "produces the correct failure message" do
1346
+ as_both_colored_and_uncolored do |color_enabled|
1347
+ snippet = <<~TEST.strip
1348
+ expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array).or eq(true))
1349
+ TEST
1350
+ program =
1351
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1352
+
1353
+ expected_output =
1354
+ build_expected_output(
1355
+ color_enabled: color_enabled,
1356
+ snippet:
1357
+ "expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array).or eq(true))",
1358
+ expectation:
1359
+ proc do
1360
+ line do
1361
+ plain "Expected raised exception "
1362
+ actual %|#<StandardError "boo">|
1363
+ plain " to match "
1364
+ expected "#<a kind of Array or eq true>"
1365
+ plain "."
1366
+ end
1367
+ end
1368
+ )
1369
+
1370
+ expect(program).to produce_output_when_run(
1371
+ expected_output
1372
+ ).in_color(color_enabled)
1373
+ end
1374
+ end
1375
+ end
1376
+
1377
+ context "when the expected error and/or actual message is long"
1378
+ end
1379
+
1380
+ context "when the block raises no error" do
1381
+ it "produces the correct failure message" do
1382
+ as_both_colored_and_uncolored do |color_enabled|
1383
+ snippet = <<~TEST.strip
1384
+ expect { }.to raise_error(a_kind_of(RuntimeError).and having_attributes(beep: :boop))
1385
+ TEST
1386
+ program =
1387
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1388
+
1389
+ expected_output =
1390
+ build_expected_output(
1391
+ color_enabled: color_enabled,
1392
+ snippet:
1393
+ "expect { }.to raise_error(a_kind_of(RuntimeError).and having_attributes(beep: :boop))",
1394
+ newline_before_expectation: true,
1395
+ expectation:
1396
+ proc do
1397
+ line do
1398
+ plain "Expected "
1399
+ actual "exception-free block"
1400
+ end
1401
+
1402
+ line do
1403
+ plain "to raise "
1404
+ expected "#<a kind of RuntimeError and having attributes (beep: :boop)>"
1405
+ end
1406
+ end
1407
+ )
1408
+
1409
+ expect(program).to produce_output_when_run(
1410
+ expected_output
1411
+ ).in_color(color_enabled)
1412
+ end
1413
+ end
1414
+ end
1415
+ end
1416
+
1417
+ context "when used in the negative" do
1418
+ context "when the expected and/or actual message is short" do
1419
+ it "produces the correct failure message" do
1420
+ as_both_colored_and_uncolored do |color_enabled|
1421
+ snippet = <<~TEST.strip
1422
+ expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError).or eq(true))
1423
+ TEST
1424
+ program =
1425
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1426
+
1427
+ expected_output =
1428
+ build_expected_output(
1429
+ color_enabled: color_enabled,
1430
+ snippet:
1431
+ "expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError).or eq(true))",
1432
+ expectation:
1433
+ proc do
1434
+ line do
1435
+ plain "Expected raised exception "
1436
+ actual %|#<StandardError "boo">|
1437
+ plain " not to match "
1438
+ expected "#<a kind of StandardError or eq true>"
1439
+ plain "."
1440
+ end
1441
+ end
1442
+ )
1443
+
1444
+ expect(program).to produce_output_when_run(
1445
+ expected_output
1446
+ ).in_color(color_enabled)
1447
+ end
1448
+ end
1449
+ end
1450
+
1451
+ context "when the expected and/or actual message is long" do
1452
+ it "produces the correct failure message" do
1453
+ as_both_colored_and_uncolored do |color_enabled|
1454
+ snippet = <<~TEST.strip
1455
+ expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError).and having_attributes(message: kind_of(String)))
1456
+ TEST
1457
+ program =
1458
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1459
+
1460
+ expected_output =
1461
+ build_expected_output(
1462
+ color_enabled: color_enabled,
1463
+ snippet:
1464
+ "expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError).and having_attributes(message: kind_of(String)))",
1465
+ newline_before_expectation: true,
1466
+ expectation:
1467
+ proc do
1468
+ line do
1469
+ plain "Expected raised exception "
1470
+ actual %|#<StandardError "this is a super super long message">|
727
1471
  end
728
1472
 
729
1473
  line do
730
1474
  plain " not to match "
731
- expected %|#<StandardError "this is a long message">|
1475
+ expected "#<a kind of StandardError and having attributes (message: #<a kind of String>)>"
732
1476
  end
733
1477
  end
734
1478
  )