super_diff 0.9.0 → 0.11.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.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  19. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
  20. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  21. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  22. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  23. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  24. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  25. data/lib/super_diff/active_support.rb +6 -10
  26. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  27. data/lib/super_diff/configuration.rb +14 -8
  28. data/lib/super_diff/csi/color.rb +4 -4
  29. data/lib/super_diff/csi/colorized_document.rb +12 -16
  30. data/lib/super_diff/csi/document.rb +8 -19
  31. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  32. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  33. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  34. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  35. data/lib/super_diff/csi.rb +10 -14
  36. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  37. data/lib/super_diff/differs/date_like.rb +15 -0
  38. data/lib/super_diff/differs/default_object.rb +1 -1
  39. data/lib/super_diff/differs/defaults.rb +2 -1
  40. data/lib/super_diff/differs/main.rb +2 -13
  41. data/lib/super_diff/differs.rb +1 -0
  42. data/lib/super_diff/equality_matchers/array.rb +10 -12
  43. data/lib/super_diff/equality_matchers/base.rb +1 -1
  44. data/lib/super_diff/equality_matchers/default.rb +2 -4
  45. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  46. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  47. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  48. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  49. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  50. data/lib/super_diff/equality_matchers.rb +1 -1
  51. data/lib/super_diff/errors.rb +2 -6
  52. data/lib/super_diff/gem_version.rb +3 -3
  53. data/lib/super_diff/helpers.rb +10 -10
  54. data/lib/super_diff/implementation_checks.rb +2 -2
  55. data/lib/super_diff/line.rb +3 -3
  56. data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  60. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
  61. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
  62. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
  63. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  64. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
  65. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
  66. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
  67. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  68. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  69. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  70. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  72. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  74. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  75. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  76. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  77. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  78. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  79. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  80. data/lib/super_diff/object_inspection.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  82. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  83. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  84. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  85. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  86. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  87. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  88. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  89. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  90. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  91. data/lib/super_diff/operation_tree_builders.rb +2 -1
  92. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  93. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  94. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  95. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  96. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  97. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  98. data/lib/super_diff/operation_trees/base.rb +3 -5
  99. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  100. data/lib/super_diff/operations/binary_operation.rb +2 -2
  101. data/lib/super_diff/operations/unary_operation.rb +1 -1
  102. data/lib/super_diff/rails.rb +2 -1
  103. data/lib/super_diff/recursion_guard.rb +5 -4
  104. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  105. data/lib/super_diff/rspec/differ.rb +6 -13
  106. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  107. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  108. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  109. data/lib/super_diff/rspec/differs.rb +3 -3
  110. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  111. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  112. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  113. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
  114. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  115. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  116. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  117. data/lib/super_diff/rspec/monkey_patches.rb +180 -123
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
  120. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
  121. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  122. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
  123. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
  124. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
  125. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  126. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  127. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
  128. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  129. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  130. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  131. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  132. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  133. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  134. data/lib/super_diff/rspec.rb +17 -18
  135. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  136. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  137. data/lib/super_diff/version.rb +1 -1
  138. data/lib/super_diff.rb +13 -9
  139. data/spec/examples.txt +541 -483
  140. data/spec/integration/rails/active_record_spec.rb +3 -1
  141. data/spec/integration/rails/engines_spec.rb +25 -0
  142. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  143. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  144. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  145. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  146. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  147. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  148. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
  149. data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
  150. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
  152. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  153. data/spec/integration/rspec/include_matcher_spec.rb +327 -225
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
  156. data/spec/integration/rspec/match_matcher_spec.rb +916 -903
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
  158. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  159. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  160. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  161. data/spec/internal/log/test.log +0 -0
  162. data/spec/spec_helper.rb +20 -20
  163. data/spec/support/command_runner.rb +34 -57
  164. data/spec/support/integration/helpers.rb +44 -32
  165. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  166. data/spec/support/integration/matchers.rb +34 -0
  167. data/spec/support/integration/test_programs/base.rb +17 -22
  168. data/spec/support/integration/test_programs/plain.rb +6 -0
  169. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  170. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  171. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  172. data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
  173. data/spec/support/models/active_record/person.rb +6 -4
  174. data/spec/support/models/active_record/shipping_address.rb +9 -10
  175. data/spec/support/models/customer.rb +2 -4
  176. data/spec/support/models/player.rb +3 -6
  177. data/spec/support/models/shipping_address.rb +4 -13
  178. data/spec/support/shared_examples/active_record.rb +258 -240
  179. data/spec/support/shared_examples/active_support.rb +174 -51
  180. data/spec/support/shared_examples/elided_diffs.rb +447 -423
  181. data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
  182. data/spec/support/shared_examples/key.rb +123 -0
  183. data/spec/support/unit/helpers.rb +1 -3
  184. data/spec/support/unit/matchers/match_output.rb +12 -13
  185. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  186. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  187. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  188. data/spec/unit/helpers_spec.rb +14 -21
  189. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  190. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  191. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  192. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  193. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  194. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  195. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  196. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  197. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  198. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  199. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  200. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  201. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  202. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  203. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  204. data/spec/unit/rspec/object_inspection_spec.rb +351 -326
  205. data/spec/unit/super_diff_spec.rb +1594 -1437
  206. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  207. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  208. data/super_diff.gemspec +13 -12
  209. metadata +88 -75
  210. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  211. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
  212. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -1,72 +1,75 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integration do
3
+ RSpec.describe "Integration with RSpec's #raise_error matcher",
4
+ type: :integration do
4
5
  context "given only an exception class" do
5
6
  context "when used in the positive" do
6
7
  context "when the block raises a different error than what is given" do
7
- context "when the message is short" do
8
+ context "when the actual message is short" do
8
9
  it "produces the correct failure message" do
9
10
  as_both_colored_and_uncolored do |color_enabled|
10
11
  snippet = <<~TEST.strip
11
12
  expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)
12
13
  TEST
13
- program = make_plain_test_program(
14
- snippet,
15
- color_enabled: color_enabled,
16
- )
14
+ program =
15
+ make_plain_test_program(snippet, color_enabled: color_enabled)
17
16
 
18
- expected_output = build_expected_output(
19
- color_enabled: color_enabled,
20
- snippet: %|expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)|,
21
- expectation: proc {
22
- line do
23
- plain %|Expected raised exception |
24
- actual %|#<StandardError "boo">|
25
- plain %| to match |
26
- expected %|#<RuntimeError>|
27
- plain %|.|
28
- end
29
- },
30
- )
17
+ expected_output =
18
+ build_expected_output(
19
+ color_enabled: color_enabled,
20
+ snippet:
21
+ "expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)",
22
+ expectation:
23
+ proc do
24
+ line do
25
+ plain "Expected raised exception "
26
+ actual %|#<StandardError "boo">|
27
+ plain " to match "
28
+ expected "a kind of RuntimeError"
29
+ plain "."
30
+ end
31
+ end
32
+ )
31
33
 
32
- expect(program).
33
- to produce_output_when_run(expected_output).
34
- in_color(color_enabled)
34
+ expect(program).to produce_output_when_run(
35
+ expected_output
36
+ ).in_color(color_enabled)
35
37
  end
36
38
  end
37
39
  end
38
40
 
39
- context "when the message is long" do
41
+ context "when the actual message is long" do
40
42
  it "produces the correct failure message" do
41
43
  as_both_colored_and_uncolored do |color_enabled|
42
44
  snippet = <<~TEST.strip
43
45
  expect { raise StandardError.new('this is a super super super long message') }.to raise_error(RuntimeError)
44
46
  TEST
45
- program = make_plain_test_program(
46
- snippet,
47
- color_enabled: color_enabled,
48
- )
49
-
50
- expected_output = build_expected_output(
51
- color_enabled: color_enabled,
52
- snippet: %|expect { raise StandardError.new('this is a super super super long message') }.to raise_error(RuntimeError)|,
53
- newline_before_expectation: true,
54
- expectation: proc {
55
- line do
56
- plain %|Expected raised exception |
57
- actual %|#<StandardError "this is a super super super long message">|
58
- end
47
+ program =
48
+ make_plain_test_program(snippet, color_enabled: color_enabled)
59
49
 
60
- line do
61
- plain %| to match |
62
- expected %|#<RuntimeError>|
63
- end
64
- },
65
- )
50
+ expected_output =
51
+ build_expected_output(
52
+ color_enabled: color_enabled,
53
+ snippet:
54
+ "expect { raise StandardError.new('this is a super super super long message') }.to raise_error(RuntimeError)",
55
+ newline_before_expectation: true,
56
+ expectation:
57
+ proc do
58
+ line do
59
+ plain "Expected raised exception "
60
+ actual %|#<StandardError "this is a super super super long message">|
61
+ end
62
+
63
+ line do
64
+ plain " to match "
65
+ expected "a kind of RuntimeError"
66
+ end
67
+ end
68
+ )
66
69
 
67
- expect(program).
68
- to produce_output_when_run(expected_output).
69
- in_color(color_enabled)
70
+ expect(program).to produce_output_when_run(
71
+ expected_output
72
+ ).in_color(color_enabled)
70
73
  end
71
74
  end
72
75
  end
@@ -78,137 +81,141 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
78
81
  snippet = <<~TEST.strip
79
82
  expect { }.to raise_error(RuntimeError)
80
83
  TEST
81
- program = make_plain_test_program(
82
- snippet,
83
- color_enabled: color_enabled,
84
- )
84
+ program =
85
+ make_plain_test_program(snippet, color_enabled: color_enabled)
85
86
 
86
- expected_output = build_expected_output(
87
- color_enabled: color_enabled,
88
- snippet: %|expect { }.to raise_error(RuntimeError)|,
89
- expectation: proc {
90
- line do
91
- plain %|Expected block to raise error |
92
- expected %|#<RuntimeError>|
93
- plain %|.|
94
- end
95
- },
96
- )
87
+ expected_output =
88
+ build_expected_output(
89
+ color_enabled: color_enabled,
90
+ snippet: "expect { }.to raise_error(RuntimeError)",
91
+ expectation:
92
+ proc do
93
+ line do
94
+ plain "Expected "
95
+ actual "exception-free block"
96
+ plain " to raise "
97
+ expected "a kind of RuntimeError"
98
+ plain "."
99
+ end
100
+ end
101
+ )
97
102
 
98
- expect(program).
99
- to produce_output_when_run(expected_output).
100
- in_color(color_enabled)
103
+ expect(program).to produce_output_when_run(
104
+ expected_output
105
+ ).in_color(color_enabled)
101
106
  end
102
107
  end
103
108
  end
104
109
  end
105
110
 
106
111
  context "when used in the negative" do
107
- context "when the message is short" do
112
+ context "when the actual message is short" do
108
113
  it "produces the correct failure message" do
109
114
  as_both_colored_and_uncolored do |color_enabled|
110
115
  snippet = <<~TEST.strip
111
116
  expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)
112
117
  TEST
113
- program = make_plain_test_program(
114
- snippet,
115
- color_enabled: color_enabled,
116
- )
118
+ program =
119
+ make_plain_test_program(snippet, color_enabled: color_enabled)
117
120
 
118
- expected_output = build_expected_output(
119
- color_enabled: color_enabled,
120
- snippet: %|expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)|,
121
- expectation: proc {
122
- line do
123
- plain %|Expected raised exception |
124
- actual %|#<StandardError "boo">|
125
- plain %| not to match |
126
- expected %|#<StandardError>|
127
- plain %|.|
128
- end
129
- },
130
- )
121
+ expected_output =
122
+ build_expected_output(
123
+ color_enabled: color_enabled,
124
+ snippet:
125
+ "expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)",
126
+ expectation:
127
+ proc do
128
+ line do
129
+ plain "Expected raised exception "
130
+ actual %|#<StandardError "boo">|
131
+ plain " not to match "
132
+ expected "a kind of StandardError"
133
+ plain "."
134
+ end
135
+ end
136
+ )
131
137
 
132
- expect(program).
133
- to produce_output_when_run(expected_output).
134
- in_color(color_enabled)
138
+ expect(program).to produce_output_when_run(
139
+ expected_output
140
+ ).in_color(color_enabled)
135
141
  end
136
142
  end
137
143
  end
138
144
 
139
- context "when the message is long" do
145
+ context "when the actual message is long" do
140
146
  it "produces the correct failure message" do
141
147
  as_both_colored_and_uncolored do |color_enabled|
142
148
  snippet = <<~TEST.strip
143
149
  expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(StandardError)
144
150
  TEST
145
- program = make_plain_test_program(
146
- snippet,
147
- color_enabled: color_enabled,
148
- )
151
+ program =
152
+ make_plain_test_program(snippet, color_enabled: color_enabled)
149
153
 
150
- expected_output = build_expected_output(
151
- color_enabled: color_enabled,
152
- snippet: %|expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(StandardError)|,
153
- newline_before_expectation: true,
154
- expectation: proc {
155
- line do
156
- plain %|Expected raised exception |
157
- actual %|#<StandardError "this is a super super long message">|
158
- end
154
+ expected_output =
155
+ build_expected_output(
156
+ color_enabled: color_enabled,
157
+ snippet:
158
+ "expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(StandardError)",
159
+ newline_before_expectation: true,
160
+ expectation:
161
+ proc do
162
+ line do
163
+ plain "Expected raised exception "
164
+ actual %|#<StandardError "this is a super super long message">|
165
+ end
159
166
 
160
- line do
161
- plain %| not to match |
162
- expected %|#<StandardError>|
163
- end
164
- },
165
- )
167
+ line do
168
+ plain " not to match "
169
+ expected "a kind of StandardError"
170
+ end
171
+ end
172
+ )
166
173
 
167
- expect(program).
168
- to produce_output_when_run(expected_output).
169
- in_color(color_enabled)
174
+ expect(program).to produce_output_when_run(
175
+ expected_output
176
+ ).in_color(color_enabled)
170
177
  end
171
178
  end
172
179
  end
173
180
  end
174
181
  end
175
182
 
176
- context "with only a message (and assuming a RuntimeError)" do
183
+ context "given only a string message" do
177
184
  context "when used in the positive" do
178
185
  context "when the block raises a different error than what is given" do
179
- context "when the message is short" do
186
+ context "when the expected and/or actual message is short" do
180
187
  it "produces the correct failure message" do
181
188
  as_both_colored_and_uncolored do |color_enabled|
182
189
  snippet = <<~TEST.strip
183
190
  expect { raise 'boo' }.to raise_error('hell')
184
191
  TEST
185
- program = make_plain_test_program(
186
- snippet,
187
- color_enabled: color_enabled,
188
- )
192
+ program =
193
+ make_plain_test_program(snippet, color_enabled: color_enabled)
189
194
 
190
- expected_output = build_expected_output(
191
- color_enabled: color_enabled,
192
- snippet: %|expect { raise 'boo' }.to raise_error('hell')|,
193
- expectation: proc {
194
- line do
195
- plain %|Expected raised exception |
196
- actual %|#<RuntimeError "boo">|
197
- plain %| to match |
198
- expected %|#<Exception "hell">|
199
- plain %|.|
200
- end
201
- },
202
- )
195
+ expected_output =
196
+ build_expected_output(
197
+ color_enabled: color_enabled,
198
+ snippet: "expect { raise 'boo' }.to raise_error('hell')",
199
+ expectation:
200
+ proc do
201
+ line do
202
+ plain "Expected raised exception "
203
+ actual %|#<RuntimeError "boo">|
204
+ plain " to match "
205
+ expected %|a kind of Exception with message "hell"|
206
+ plain "."
207
+ end
208
+ end
209
+ )
203
210
 
204
- expect(program).
205
- to produce_output_when_run(expected_output).
206
- in_color(color_enabled)
211
+ expect(program).to produce_output_when_run(
212
+ expected_output
213
+ ).in_color(color_enabled)
207
214
  end
208
215
  end
209
216
  end
210
217
 
211
- context "when the message is long" do
218
+ context "when the expected and/or actual message is long" do
212
219
  context "but contains no line breaks" do
213
220
  it "produces the correct failure message when used in the positive" do
214
221
  as_both_colored_and_uncolored do |color_enabled|
@@ -217,31 +224,32 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
217
224
  expected_message = "whatever"
218
225
  expect { raise(actual_message) }.to raise_error(expected_message)
219
226
  TEST
220
- program = make_plain_test_program(
221
- snippet,
222
- color_enabled: color_enabled,
223
- )
224
-
225
- expected_output = build_expected_output(
226
- color_enabled: color_enabled,
227
- snippet: %|expect { raise(actual_message) }.to raise_error(expected_message)|,
228
- newline_before_expectation: true,
229
- expectation: proc {
230
- line do
231
- plain %|Expected raised exception |
232
- actual %|#<RuntimeError "some really really really long message">|
233
- end
234
-
235
- line do
236
- plain %| to match |
237
- expected %|#<Exception "whatever">|
238
- end
239
- },
240
- )
241
-
242
- expect(program).
243
- to produce_output_when_run(expected_output).
244
- in_color(color_enabled)
227
+ program =
228
+ make_plain_test_program(snippet, color_enabled: color_enabled)
229
+
230
+ expected_output =
231
+ build_expected_output(
232
+ color_enabled: color_enabled,
233
+ snippet:
234
+ "expect { raise(actual_message) }.to raise_error(expected_message)",
235
+ newline_before_expectation: true,
236
+ expectation:
237
+ proc do
238
+ line do
239
+ plain "Expected raised exception "
240
+ actual %|#<RuntimeError "some really really really long message">|
241
+ end
242
+
243
+ line do
244
+ plain " to match "
245
+ expected %|a kind of Exception with message "whatever"|
246
+ end
247
+ end
248
+ )
249
+
250
+ expect(program).to produce_output_when_run(
251
+ expected_output
252
+ ).in_color(color_enabled)
245
253
  end
246
254
  end
247
255
  end
@@ -260,35 +268,37 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
260
268
  MESSAGE
261
269
  expect { raise(actual_message) }.to raise_error(expected_message)
262
270
  TEST
263
- program = make_plain_test_program(
264
- snippet,
265
- color_enabled: color_enabled,
266
- )
267
-
268
- expected_output = build_expected_output(
269
- color_enabled: color_enabled,
270
- snippet: %|expect { raise(actual_message) }.to raise_error(expected_message)|,
271
- expectation: proc {
272
- line do
273
- plain %|Expected raised exception |
274
- actual %|#<RuntimeError "This is fun\\nSo is this">|
275
- end
276
-
277
- line do
278
- plain %| to match |
279
- expected %|#<Exception "This is fun\\nAnd so is this">|
280
- end
281
- },
282
- diff: proc {
283
- plain_line %| This is fun\\n|
284
- expected_line %|- And so is this|
285
- actual_line %|+ So is this|
286
- },
287
- )
288
-
289
- expect(program).
290
- to produce_output_when_run(expected_output).
291
- in_color(color_enabled)
271
+ program =
272
+ make_plain_test_program(snippet, color_enabled: color_enabled)
273
+
274
+ expected_output =
275
+ build_expected_output(
276
+ color_enabled: color_enabled,
277
+ snippet:
278
+ "expect { raise(actual_message) }.to raise_error(expected_message)",
279
+ expectation:
280
+ proc do
281
+ line do
282
+ plain "Expected raised exception "
283
+ actual %|#<RuntimeError "This is fun\\nSo is this">|
284
+ end
285
+
286
+ line do
287
+ plain " to match "
288
+ expected %|a kind of Exception with message "This is fun\\nAnd so is this"|
289
+ end
290
+ end,
291
+ diff:
292
+ proc do
293
+ plain_line %| This is fun\\n|
294
+ expected_line "- And so is this"
295
+ actual_line "+ So is this"
296
+ end
297
+ )
298
+
299
+ expect(program).to produce_output_when_run(
300
+ expected_output
301
+ ).in_color(color_enabled)
292
302
  end
293
303
  end
294
304
  end
@@ -296,105 +306,113 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
296
306
  end
297
307
 
298
308
  context "when the block raises no error" do
299
- context "when the message is short" do
309
+ context "when the expected message is short" do
300
310
  it "produces the correct failure message" do
301
311
  as_both_colored_and_uncolored do |color_enabled|
302
312
  snippet = <<~TEST.strip
303
313
  expect { }.to raise_error('hell')
304
314
  TEST
305
- program = make_plain_test_program(
306
- snippet,
307
- color_enabled: color_enabled,
308
- )
315
+ program =
316
+ make_plain_test_program(snippet, color_enabled: color_enabled)
309
317
 
310
- expected_output = build_expected_output(
311
- color_enabled: color_enabled,
312
- snippet: %|expect { }.to raise_error('hell')|,
313
- expectation: proc {
314
- line do
315
- plain %|Expected block to raise error |
316
- expected %|#<Exception "hell">|
317
- plain %|.|
318
- end
319
- },
320
- )
318
+ expected_output =
319
+ build_expected_output(
320
+ color_enabled: color_enabled,
321
+ snippet: "expect { }.to raise_error('hell')",
322
+ expectation:
323
+ proc do
324
+ line do
325
+ plain "Expected "
326
+ actual "exception-free block"
327
+ plain " to raise "
328
+ expected %|a kind of Exception with message "hell"|
329
+ plain "."
330
+ end
331
+ end
332
+ )
321
333
 
322
- expect(program).
323
- to produce_output_when_run(expected_output).
324
- in_color(color_enabled)
334
+ expect(program).to produce_output_when_run(
335
+ expected_output
336
+ ).in_color(color_enabled)
325
337
  end
326
338
  end
327
-
328
339
  end
329
340
 
330
- context "when the message is long" do
341
+ context "when the expected message is long" do
331
342
  context "but contains no line breaks" do
332
343
  it "produces the correct failure message" do
333
344
  as_both_colored_and_uncolored do |color_enabled|
334
345
  snippet = <<~TEST.strip
335
346
  expect { }.to raise_error("this is a super super super super super super long message")
336
347
  TEST
337
- program = make_plain_test_program(
338
- snippet,
339
- color_enabled: color_enabled,
340
- )
341
-
342
- expected_output = build_expected_output(
343
- color_enabled: color_enabled,
344
- snippet: %|expect { }.to raise_error("this is a super super super super super super long message")|,
345
- newline_before_expectation: true,
346
- expectation: proc {
347
- line do
348
- plain %| Expected |
349
- plain %|block|
350
- end
351
-
352
- line do
353
- plain %|to raise error |
354
- expected %|#<Exception "this is a super super super super super super long message">|
355
- end
356
- },
357
- )
358
-
359
- expect(program).
360
- to produce_output_when_run(expected_output).
361
- in_color(color_enabled)
348
+ program =
349
+ make_plain_test_program(snippet, color_enabled: color_enabled)
350
+
351
+ expected_output =
352
+ build_expected_output(
353
+ color_enabled: color_enabled,
354
+ snippet:
355
+ %|expect { }.to raise_error("this is a super super super super super super long message")|,
356
+ newline_before_expectation: true,
357
+ expectation:
358
+ proc do
359
+ # stree-ignore
360
+ line do
361
+ plain "Expected "
362
+ actual "exception-free block"
363
+ end
364
+
365
+ line do
366
+ plain "to raise "
367
+ expected %|a kind of Exception with message "this is a super super super super super super long message"|
368
+ end
369
+ end
370
+ )
371
+
372
+ expect(program).to produce_output_when_run(
373
+ expected_output
374
+ ).in_color(color_enabled)
362
375
  end
363
376
  end
364
377
  end
365
378
 
366
379
  context "but contains line breaks" do
367
- it "produces the correct failure message when used in the negative" do
380
+ it "produces the correct failure message" do
368
381
  as_both_colored_and_uncolored do |color_enabled|
369
382
  snippet = <<~TEST.strip
370
- message = "some really long message"
371
- 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)
372
389
  TEST
373
- program = make_plain_test_program(
374
- snippet,
375
- color_enabled: color_enabled,
376
- )
377
-
378
- expected_output = build_expected_output(
379
- color_enabled: color_enabled,
380
- snippet: %|expect { raise(message) }.not_to raise_error(message)|,
381
- newline_before_expectation: true,
382
- expectation: proc {
383
- line do
384
- plain %|Expected raised exception |
385
- actual %|#<RuntimeError "some really long message">|
386
- end
387
-
388
- line do
389
- plain %| not to match |
390
- expected %|#<Exception "some really long message">|
391
- end
392
- },
393
- )
394
-
395
- expect(program).
396
- to produce_output_when_run(expected_output).
397
- in_color(color_enabled)
390
+ program =
391
+ make_plain_test_program(snippet, color_enabled: color_enabled)
392
+
393
+ expected_output =
394
+ build_expected_output(
395
+ color_enabled: color_enabled,
396
+ snippet: "expect { }.to raise_error(expected_message)",
397
+ newline_before_expectation: true,
398
+ expectation:
399
+ proc do
400
+ # stree-ignore
401
+ line do
402
+ plain "Expected "
403
+ actual "exception-free block"
404
+ end
405
+
406
+ line do
407
+ plain "to raise "
408
+ expected %|a kind of Exception with message "this is a super super\\nsuper super super\\nsuper long message"|
409
+ end
410
+ end
411
+ )
412
+
413
+ expect(program).to produce_output_when_run(
414
+ expected_output
415
+ ).in_color(color_enabled)
398
416
  end
399
417
  end
400
418
  end
@@ -403,39 +421,39 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
403
421
  end
404
422
 
405
423
  context "when used in the negative" do
406
- context "when the message is short" do
424
+ context "when the expected and/or actual message is short" do
407
425
  it "produces the correct failure message" do
408
426
  as_both_colored_and_uncolored do |color_enabled|
409
427
  snippet = <<~TEST.strip
410
428
  expect { raise 'boo' }.not_to raise_error('boo')
411
429
  TEST
412
- program = make_plain_test_program(
413
- snippet,
414
- color_enabled: color_enabled,
415
- )
430
+ program =
431
+ make_plain_test_program(snippet, color_enabled: color_enabled)
416
432
 
417
- expected_output = build_expected_output(
418
- color_enabled: color_enabled,
419
- snippet: %|expect { raise 'boo' }.not_to raise_error('boo')|,
420
- expectation: proc {
421
- line do
422
- plain %|Expected raised exception |
423
- actual %|#<RuntimeError "boo">|
424
- plain %| not to match |
425
- expected %|#<Exception "boo">|
426
- plain %|.|
427
- end
428
- },
429
- )
433
+ expected_output =
434
+ build_expected_output(
435
+ color_enabled: color_enabled,
436
+ snippet: "expect { raise 'boo' }.not_to raise_error('boo')",
437
+ expectation:
438
+ proc do
439
+ line do
440
+ plain "Expected raised exception "
441
+ actual %|#<RuntimeError "boo">|
442
+ plain " not to match "
443
+ expected %|a kind of Exception with message "boo"|
444
+ plain "."
445
+ end
446
+ end
447
+ )
430
448
 
431
- expect(program).
432
- to produce_output_when_run(expected_output).
433
- in_color(color_enabled)
449
+ expect(program).to produce_output_when_run(
450
+ expected_output
451
+ ).in_color(color_enabled)
434
452
  end
435
453
  end
436
454
  end
437
455
 
438
- context "when the message is long" do
456
+ context "when the expected and/or actual message is long" do
439
457
  context "but contains no line breaks" do
440
458
  it "produces the correct failure message" do
441
459
  as_both_colored_and_uncolored do |color_enabled|
@@ -443,31 +461,32 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
443
461
  message = "some really long message"
444
462
  expect { raise(message) }.not_to raise_error(message)
445
463
  TEST
446
- program = make_plain_test_program(
447
- snippet,
448
- color_enabled: color_enabled,
449
- )
450
-
451
- expected_output = build_expected_output(
452
- color_enabled: color_enabled,
453
- snippet: %|expect { raise(message) }.not_to raise_error(message)|,
454
- newline_before_expectation: true,
455
- expectation: proc {
456
- line do
457
- plain %|Expected raised exception |
458
- actual %|#<RuntimeError "some really long message">|
459
- end
464
+ program =
465
+ make_plain_test_program(snippet, color_enabled: color_enabled)
460
466
 
461
- line do
462
- plain %| not to match |
463
- expected %|#<Exception "some really long message">|
464
- end
465
- },
466
- )
467
+ expected_output =
468
+ build_expected_output(
469
+ color_enabled: color_enabled,
470
+ snippet:
471
+ "expect { raise(message) }.not_to raise_error(message)",
472
+ newline_before_expectation: true,
473
+ expectation:
474
+ proc do
475
+ line do
476
+ plain "Expected raised exception "
477
+ actual %|#<RuntimeError "some really long message">|
478
+ end
479
+
480
+ line do
481
+ plain " not to match "
482
+ expected %|a kind of Exception with message "some really long message"|
483
+ end
484
+ end
485
+ )
467
486
 
468
- expect(program).
469
- to produce_output_when_run(expected_output).
470
- in_color(color_enabled)
487
+ expect(program).to produce_output_when_run(
488
+ expected_output
489
+ ).in_color(color_enabled)
471
490
  end
472
491
  end
473
492
  end
@@ -477,250 +496,990 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
477
496
  as_both_colored_and_uncolored do |color_enabled|
478
497
  snippet = <<~TEST.strip
479
498
  message = <<\~MESSAGE.rstrip
480
- This is fun
481
- So is this
499
+ this is a super super
500
+ super super super
501
+ super long message
482
502
  MESSAGE
483
503
  expect { raise(message) }.not_to raise_error(message)
484
504
  TEST
485
- program = make_plain_test_program(
486
- snippet,
487
- color_enabled: color_enabled,
488
- )
505
+ program =
506
+ make_plain_test_program(snippet, color_enabled: color_enabled)
507
+
508
+ expected_output =
509
+ build_expected_output(
510
+ color_enabled: color_enabled,
511
+ snippet:
512
+ "expect { raise(message) }.not_to raise_error(message)",
513
+ newline_before_expectation: true,
514
+ expectation:
515
+ proc do
516
+ line do
517
+ plain "Expected raised exception "
518
+ actual %|#<RuntimeError "this is a super super\\nsuper super super\\nsuper long message">|
519
+ end
520
+
521
+ line do
522
+ plain " not to match "
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)
489
548
 
490
- expected_output = build_expected_output(
549
+ expected_output =
550
+ build_expected_output(
491
551
  color_enabled: color_enabled,
492
- snippet: %|expect { raise(message) }.not_to raise_error(message)|,
552
+ snippet: "expect { raise 'boo' }.to raise_error(/hell/i)",
493
553
  newline_before_expectation: true,
494
- expectation: proc {
495
- line do
496
- plain %|Expected raised exception |
497
- actual %|#<RuntimeError "This is fun\\nSo is this">|
498
- end
554
+ expectation:
555
+ proc do
556
+ line do
557
+ plain "Expected raised exception "
558
+ actual %|#<RuntimeError "boo">|
559
+ end
499
560
 
500
- line do
501
- plain %| not to match |
502
- expected %|#<Exception "This is fun\\nSo is this">|
561
+ line do
562
+ plain " to match "
563
+ expected "a kind of Exception with message matching /hell/i"
564
+ end
503
565
  end
504
- },
505
566
  )
506
567
 
507
- expect(program).
508
- to produce_output_when_run(expected_output).
509
- in_color(color_enabled)
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)
510
604
  end
511
605
  end
512
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"
633
+ end
634
+ end
635
+ )
636
+
637
+ expect(program).to produce_output_when_run(
638
+ expected_output
639
+ ).in_color(color_enabled)
640
+ end
641
+ end
642
+ end
643
+ end
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
513
678
  end
514
679
  end
515
680
  end
516
681
 
517
- context "with both an exception and a message" do
682
+ context "given both an exception class and string message" do
518
683
  context "when used in the positive" do
519
684
  context "when the block raises a different error than what is given" do
520
- context "when the message is short" do
685
+ context "when the expected and/or actual message is short" do
521
686
  it "produces the correct failure message" do
522
687
  as_both_colored_and_uncolored do |color_enabled|
523
688
  snippet = <<~TEST.strip
524
689
  block = -> { raise StandardError.new('a') }
525
690
  expect(&block).to raise_error(RuntimeError, 'b')
526
691
  TEST
527
- program = make_plain_test_program(
528
- snippet,
529
- color_enabled: color_enabled,
530
- )
692
+ program =
693
+ make_plain_test_program(snippet, color_enabled: color_enabled)
531
694
 
532
- expected_output = build_expected_output(
533
- color_enabled: color_enabled,
534
- snippet: %|expect(&block).to raise_error(RuntimeError, 'b')|,
535
- expectation: proc {
536
- line do
537
- plain %|Expected raised exception |
538
- actual %|#<StandardError "a">|
539
- plain %| to match |
540
- expected %|#<RuntimeError "b">|
541
- plain %|.|
542
- end
543
- },
544
- )
695
+ expected_output =
696
+ build_expected_output(
697
+ color_enabled: color_enabled,
698
+ snippet: "expect(&block).to raise_error(RuntimeError, 'b')",
699
+ expectation:
700
+ proc do
701
+ line do
702
+ plain "Expected raised exception "
703
+ actual %|#<StandardError "a">|
704
+ plain " to match "
705
+ expected %|a kind of RuntimeError with message "b"|
706
+ plain "."
707
+ end
708
+ end
709
+ )
545
710
 
546
- expect(program).
547
- to produce_output_when_run(expected_output).
548
- in_color(color_enabled)
711
+ expect(program).to produce_output_when_run(
712
+ expected_output
713
+ ).in_color(color_enabled)
549
714
  end
550
715
  end
551
716
  end
552
717
 
553
- context "when the message is long" do
718
+ context "when the expected and/or actual message is long" do
554
719
  it "produces the correct failure message" do
555
720
  as_both_colored_and_uncolored do |color_enabled|
556
721
  snippet = <<~TEST.strip
557
722
  block = -> { raise StandardError.new('this is a long message') }
558
723
  expect(&block).to raise_error(RuntimeError, 'this is another long message')
559
724
  TEST
560
- program = make_plain_test_program(
561
- snippet,
562
- color_enabled: color_enabled,
563
- )
725
+ program =
726
+ make_plain_test_program(snippet, color_enabled: color_enabled)
564
727
 
565
- expected_output = build_expected_output(
566
- color_enabled: color_enabled,
567
- snippet: %|expect(&block).to raise_error(RuntimeError, 'this is another long message')|,
568
- newline_before_expectation: true,
569
- expectation: proc {
570
- line do
571
- plain %|Expected raised exception |
572
- actual %|#<StandardError "this is a long message">|
573
- end
574
-
575
- line do
576
- plain %| to match |
577
- expected %|#<RuntimeError "this is another long message">|
578
- end
579
- },
580
- )
728
+ expected_output =
729
+ build_expected_output(
730
+ color_enabled: color_enabled,
731
+ snippet:
732
+ "expect(&block).to raise_error(RuntimeError, 'this is another long message')",
733
+ newline_before_expectation: true,
734
+ expectation:
735
+ proc do
736
+ line do
737
+ plain "Expected raised exception "
738
+ actual %|#<StandardError "this is a long message">|
739
+ end
740
+
741
+ line do
742
+ plain " to match "
743
+ expected %|a kind of RuntimeError with message "this is another long message"|
744
+ end
745
+ end
746
+ )
581
747
 
582
- expect(program).
583
- to produce_output_when_run(expected_output).
584
- in_color(color_enabled)
748
+ expect(program).to produce_output_when_run(
749
+ expected_output
750
+ ).in_color(color_enabled)
585
751
  end
586
752
  end
587
753
  end
588
754
  end
589
755
 
590
756
  context "when the block raises no error" do
591
- context "when the message is short" do
757
+ context "when the expected message is short" do
592
758
  it "produces the correct failure message" do
593
759
  as_both_colored_and_uncolored do |color_enabled|
594
760
  snippet = <<~TEST.strip
595
761
  expect { }.to raise_error(RuntimeError, 'b')
596
762
  TEST
597
- program = make_plain_test_program(
598
- snippet,
599
- color_enabled: color_enabled,
600
- )
763
+ program =
764
+ make_plain_test_program(snippet, color_enabled: color_enabled)
601
765
 
602
- expected_output = build_expected_output(
603
- color_enabled: color_enabled,
604
- snippet: %|expect { }.to raise_error(RuntimeError, 'b')|,
605
- expectation: proc {
606
- line do
607
- plain %|Expected block to raise error |
608
- expected %|#<RuntimeError "b">|
609
- plain %|.|
610
- end
611
- },
612
- )
766
+ expected_output =
767
+ build_expected_output(
768
+ color_enabled: color_enabled,
769
+ snippet: "expect { }.to raise_error(RuntimeError, 'b')",
770
+ expectation:
771
+ proc do
772
+ line do
773
+ plain "Expected "
774
+ actual "exception-free block"
775
+ plain " to raise "
776
+ expected %|a kind of RuntimeError with message "b"|
777
+ plain "."
778
+ end
779
+ end
780
+ )
613
781
 
614
- expect(program).
615
- to produce_output_when_run(expected_output).
616
- in_color(color_enabled)
782
+ expect(program).to produce_output_when_run(
783
+ expected_output
784
+ ).in_color(color_enabled)
617
785
  end
618
786
  end
619
787
  end
620
788
 
621
- context "when the message is long" do
789
+ context "when the expected message is long" do
622
790
  it "produces the correct failure message" do
623
791
  as_both_colored_and_uncolored do |color_enabled|
624
792
  snippet = <<~TEST.strip
625
793
  expect { }.to raise_error(RuntimeError, 'this is a super super super super super super long message')
626
794
  TEST
627
- program = make_plain_test_program(
628
- snippet,
629
- color_enabled: color_enabled,
630
- )
795
+ program =
796
+ make_plain_test_program(snippet, color_enabled: color_enabled)
631
797
 
632
- expected_output = build_expected_output(
633
- color_enabled: color_enabled,
634
- snippet: %|expect { }.to raise_error(RuntimeError, 'this is a super super super super super super long message')|,
635
- newline_before_expectation: true,
636
- expectation: proc {
798
+ expected_output =
799
+ build_expected_output(
800
+ color_enabled: color_enabled,
801
+ snippet:
802
+ "expect { }.to raise_error(RuntimeError, 'this is a super super super super super super long message')",
803
+ newline_before_expectation: true,
804
+ expectation:
805
+ proc do
806
+ line do
807
+ plain "Expected "
808
+ actual "exception-free block"
809
+ end
810
+
811
+ line do
812
+ plain "to raise "
813
+ expected %|a kind of RuntimeError with message "this is a super super super super super super long message"|
814
+ end
815
+ end
816
+ )
817
+
818
+ expect(program).to produce_output_when_run(
819
+ expected_output
820
+ ).in_color(color_enabled)
821
+ end
822
+ end
823
+ end
824
+ end
825
+ end
826
+
827
+ context "when used in the negative" 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
637
844
  line do
638
- plain %| Expected |
639
- plain %|block|
845
+ plain "Expected raised exception "
846
+ actual %|#<StandardError "a">|
640
847
  end
641
848
 
642
849
  line do
643
- plain %|to raise error |
644
- expected %|#<RuntimeError "this is a super super super super super super long message">|
850
+ plain " not to match "
851
+ expected %|a kind of StandardError with message "a"|
645
852
  end
646
- },
647
- )
853
+ end
854
+ )
648
855
 
649
- expect(program).
650
- to produce_output_when_run(expected_output).
651
- in_color(color_enabled)
652
- end
653
- end
856
+ expect(program).to produce_output_when_run(expected_output).in_color(
857
+ color_enabled
858
+ )
654
859
  end
655
860
  end
656
861
  end
862
+ end
657
863
 
658
- context "when used in the negative" do
659
- context "when the message is short" do
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
660
867
  it "produces the correct failure message" do
661
868
  as_both_colored_and_uncolored do |color_enabled|
662
869
  snippet = <<~TEST.strip
663
870
  block = -> { raise StandardError.new('a') }
664
- expect(&block).not_to raise_error(StandardError, 'a')
871
+ expect(&block).to raise_error(RuntimeError, /b/i)
665
872
  TEST
666
- program = make_plain_test_program(
667
- snippet,
668
- color_enabled: color_enabled,
669
- )
873
+ program =
874
+ make_plain_test_program(snippet, color_enabled: color_enabled)
670
875
 
671
- expected_output = build_expected_output(
876
+ expected_output =
877
+ build_expected_output(
878
+ color_enabled: color_enabled,
879
+ snippet: "expect(&block).to raise_error(RuntimeError, /b/i)",
880
+ newline_before_expectation: true,
881
+ expectation:
882
+ proc do
883
+ line do
884
+ plain "Expected raised exception "
885
+ actual %|#<StandardError "a">|
886
+ end
887
+
888
+ line do
889
+ plain " to match "
890
+ expected "a kind of RuntimeError with message matching /b/i"
891
+ end
892
+ end
893
+ )
894
+
895
+ expect(program).to produce_output_when_run(
896
+ expected_output
897
+ ).in_color(color_enabled)
898
+ end
899
+ end
900
+ end
901
+
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(
672
984
  color_enabled: color_enabled,
673
- snippet: %|expect(&block).not_to raise_error(StandardError, 'a')|,
674
- expectation: proc {
675
- line do
676
- plain %|Expected raised exception |
677
- actual %|#<StandardError "a">|
678
- plain %| not to match |
679
- expected %|#<StandardError "a">|
680
- plain %|.|
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
681
998
  end
682
- },
683
999
  )
684
1000
 
685
- expect(program).
686
- to produce_output_when_run(expected_output).
687
- in_color(color_enabled)
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
1083
+ it "produces the correct failure message" do
1084
+ as_both_colored_and_uncolored do |color_enabled|
1085
+ snippet = <<~TEST.strip
1086
+ expect { }.to raise_error(a_kind_of(RuntimeError))
1087
+ TEST
1088
+ program =
1089
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1090
+
1091
+ expected_output =
1092
+ build_expected_output(
1093
+ color_enabled: color_enabled,
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)
688
1110
  end
689
1111
  end
690
1112
  end
1113
+ end
691
1114
 
692
- context "when the message is long" do
1115
+ context "when used in the negative" do
1116
+ context "when the expected error and/or actual message is short" do
693
1117
  it "produces the correct failure message" do
694
1118
  as_both_colored_and_uncolored do |color_enabled|
695
1119
  snippet = <<~TEST.strip
696
- block = -> { raise StandardError.new('this is a long message') }
697
- expect(&block).not_to raise_error(StandardError, 'this is a long message')
1120
+ expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError))
698
1121
  TEST
699
- program = make_plain_test_program(
700
- snippet,
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(
701
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
702
1253
  )
703
1254
 
704
- expected_output = build_expected_output(
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,
1280
+ expectation:
1281
+ proc do
1282
+ line do
1283
+ plain "Expected raised exception "
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(
705
1313
  color_enabled: color_enabled,
706
- snippet: %|expect(&block).not_to raise_error(StandardError, 'this is a long message')|,
1314
+ snippet:
1315
+ "expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), /boo/i)",
707
1316
  newline_before_expectation: true,
708
- expectation: proc {
709
- line do
710
- plain %|Expected raised exception |
711
- actual %|#<StandardError "this is a long message">|
712
- end
1317
+ expectation:
1318
+ proc do
1319
+ line do
1320
+ plain "Expected raised exception "
1321
+ actual %|#<StandardError "boo">|
1322
+ end
713
1323
 
714
- line do
715
- plain %| not to match |
716
- expected %|#<StandardError "this is a long message">|
1324
+ line do
1325
+ plain " not to match "
1326
+ expected "#<a kind of StandardError> with message matching /boo/i"
1327
+ end
717
1328
  end
718
- },
719
1329
  )
720
1330
 
721
- expect(program).
722
- to produce_output_when_run(expected_output).
723
- in_color(color_enabled)
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">|
1471
+ end
1472
+
1473
+ line do
1474
+ plain " not to match "
1475
+ expected "#<a kind of StandardError and having attributes (message: #<a kind of String>)>"
1476
+ end
1477
+ end
1478
+ )
1479
+
1480
+ expect(program).to produce_output_when_run(
1481
+ expected_output
1482
+ ).in_color(color_enabled)
724
1483
  end
725
1484
  end
726
1485
  end