super_diff 0.2.0 → 0.5.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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +108 -74
  3. data/lib/super_diff.rb +20 -11
  4. data/lib/super_diff/active_record.rb +21 -23
  5. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
  6. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
  7. data/lib/super_diff/active_record/monkey_patches.rb +9 -0
  8. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
  9. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
  10. data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
  11. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
  12. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
  13. data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
  14. data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
  15. data/lib/super_diff/active_support.rb +16 -19
  16. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
  17. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
  18. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
  19. data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
  20. data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
  21. data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
  22. data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
  23. data/lib/super_diff/configuration.rb +60 -0
  24. data/lib/super_diff/csi.rb +4 -0
  25. data/lib/super_diff/diff_formatters.rb +3 -3
  26. data/lib/super_diff/diff_formatters/array.rb +3 -3
  27. data/lib/super_diff/diff_formatters/base.rb +3 -2
  28. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  29. data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
  30. data/lib/super_diff/diff_formatters/default_object.rb +6 -8
  31. data/lib/super_diff/diff_formatters/defaults.rb +10 -0
  32. data/lib/super_diff/diff_formatters/hash.rb +3 -3
  33. data/lib/super_diff/diff_formatters/main.rb +41 -0
  34. data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
  35. data/lib/super_diff/differs.rb +4 -9
  36. data/lib/super_diff/differs/array.rb +2 -11
  37. data/lib/super_diff/differs/base.rb +20 -3
  38. data/lib/super_diff/differs/custom_object.rb +2 -11
  39. data/lib/super_diff/differs/default_object.rb +2 -8
  40. data/lib/super_diff/differs/defaults.rb +12 -0
  41. data/lib/super_diff/differs/hash.rb +2 -11
  42. data/lib/super_diff/differs/main.rb +48 -0
  43. data/lib/super_diff/differs/multiline_string.rb +2 -14
  44. data/lib/super_diff/differs/time_like.rb +15 -0
  45. data/lib/super_diff/equality_matchers.rb +3 -9
  46. data/lib/super_diff/equality_matchers/array.rb +1 -7
  47. data/lib/super_diff/equality_matchers/base.rb +1 -1
  48. data/lib/super_diff/equality_matchers/default.rb +2 -8
  49. data/lib/super_diff/equality_matchers/defaults.rb +12 -0
  50. data/lib/super_diff/equality_matchers/hash.rb +1 -7
  51. data/lib/super_diff/equality_matchers/main.rb +21 -0
  52. data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
  53. data/lib/super_diff/errors.rb +16 -0
  54. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
  55. data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
  56. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
  57. data/lib/super_diff/implementation_checks.rb +19 -0
  58. data/lib/super_diff/object_inspection.rb +1 -10
  59. data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
  60. data/lib/super_diff/object_inspection/inspectors.rb +5 -0
  61. data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
  62. data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
  63. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
  64. data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
  65. data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
  66. data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
  67. data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
  68. data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
  69. data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
  70. data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
  72. data/lib/super_diff/operation_tree_builders.rb +18 -0
  73. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
  74. data/lib/super_diff/operation_tree_builders/base.rb +98 -0
  75. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
  76. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
  78. data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
  79. data/lib/super_diff/operation_tree_builders/main.rb +42 -0
  80. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
  82. data/lib/super_diff/operation_trees.rb +13 -0
  83. data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
  84. data/lib/super_diff/operation_trees/base.rb +31 -0
  85. data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
  86. data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
  87. data/lib/super_diff/operation_trees/defaults.rb +5 -0
  88. data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
  89. data/lib/super_diff/operation_trees/main.rb +35 -0
  90. data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
  91. data/lib/super_diff/operations/unary_operation.rb +3 -0
  92. data/lib/super_diff/rspec.rb +54 -22
  93. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  94. data/lib/super_diff/rspec/differ.rb +2 -17
  95. data/lib/super_diff/rspec/differs.rb +9 -3
  96. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
  97. data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
  98. data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
  99. data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
  100. data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
  101. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
  102. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
  103. data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
  104. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
  106. data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
  107. data/lib/super_diff/rspec/monkey_patches.rb +226 -115
  108. data/lib/super_diff/rspec/object_inspection.rb +0 -1
  109. data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
  110. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
  111. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
  112. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
  113. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
  114. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
  115. data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
  116. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
  117. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
  118. data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
  119. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
  120. data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
  121. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
  122. data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
  123. data/lib/super_diff/version.rb +1 -1
  124. data/spec/examples.txt +397 -328
  125. data/spec/integration/rails/active_record_spec.rb +1 -1
  126. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
  127. data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
  128. data/spec/integration/rspec/eq_matcher_spec.rb +139 -3
  129. data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  130. data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
  131. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  132. data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
  133. data/spec/integration/rspec/match_matcher_spec.rb +8 -8
  134. data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
  135. data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
  136. data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
  137. data/spec/spec_helper.rb +18 -7
  138. data/spec/support/command_runner.rb +3 -0
  139. data/spec/support/integration/helpers.rb +14 -90
  140. data/spec/support/integration/matchers.rb +143 -0
  141. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
  142. data/spec/support/integration/test_programs/base.rb +120 -0
  143. data/spec/support/integration/test_programs/plain.rb +13 -0
  144. data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
  145. data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
  146. data/spec/support/models/active_record/person.rb +4 -11
  147. data/spec/support/models/active_record/query.rb +15 -0
  148. data/spec/support/models/active_record/shipping_address.rb +10 -14
  149. data/spec/support/object_id.rb +27 -0
  150. data/spec/support/ruby_versions.rb +4 -0
  151. data/spec/support/shared_examples/active_record.rb +71 -0
  152. data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
  153. data/spec/tmp/integration_spec.rb +15 -0
  154. data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
  155. data/spec/unit/object_inspection_spec.rb +94 -18
  156. data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
  157. data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
  158. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  159. data/super_diff.gemspec +3 -6
  160. metadata +99 -91
  161. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  162. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  163. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  164. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  165. data/lib/super_diff/diff_formatter.rb +0 -32
  166. data/lib/super_diff/differ.rb +0 -51
  167. data/lib/super_diff/equality_matcher.rb +0 -32
  168. data/lib/super_diff/no_differ_available_error.rb +0 -22
  169. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  170. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  171. data/lib/super_diff/object_inspection/map.rb +0 -28
  172. data/lib/super_diff/operation_sequences.rb +0 -9
  173. data/lib/super_diff/operation_sequences/base.rb +0 -11
  174. data/lib/super_diff/operational_sequencer.rb +0 -48
  175. data/lib/super_diff/operational_sequencers.rb +0 -16
  176. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  177. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  178. data/lib/super_diff/rspec/configuration.rb +0 -31
  179. data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
  180. data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
  181. data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
  182. data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
  183. data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
  184. data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
  185. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  186. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
  187. data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
@@ -2,138 +2,113 @@ require "spec_helper"
2
2
 
3
3
  RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integration do
4
4
  context "given only an exception class" do
5
- it "produces the correct failure message when used in the positive" do
6
- as_both_colored_and_uncolored do |color_enabled|
7
- snippet = <<~TEST.strip
8
- expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)
9
- TEST
10
- program = make_plain_test_program(
11
- snippet,
12
- color_enabled: color_enabled,
13
- )
14
-
15
- expected_output = build_expected_output(
16
- color_enabled: color_enabled,
17
- snippet: %|expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)|,
18
- expectation: proc {
19
- line do
20
- plain "Expected raised exception "
21
- beta %|#<StandardError "boo">|
22
- plain " to match "
23
- alpha %|#<RuntimeError>|
24
- plain "."
5
+ context "when used in the positive" do
6
+ context "when the block raises a different error than what is given" do
7
+ context "when the message is short" do
8
+ it "produces the correct failure message" do
9
+ as_both_colored_and_uncolored do |color_enabled|
10
+ snippet = <<~TEST.strip
11
+ expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)
12
+ TEST
13
+ program = make_plain_test_program(
14
+ snippet,
15
+ color_enabled: color_enabled,
16
+ )
17
+
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
+ beta %|#<StandardError "boo">|
25
+ plain " to match "
26
+ alpha %|#<RuntimeError>|
27
+ plain "."
28
+ end
29
+ },
30
+ )
31
+
32
+ expect(program).
33
+ to produce_output_when_run(expected_output).
34
+ in_color(color_enabled)
25
35
  end
26
- },
27
- )
28
-
29
- expect(program).
30
- to produce_output_when_run(expected_output).
31
- in_color(color_enabled)
32
- end
33
- end
36
+ end
37
+ end
34
38
 
35
- it "produces the correct failure message when used in the negative" do
36
- as_both_colored_and_uncolored do |color_enabled|
37
- snippet = <<~TEST.strip
38
- expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)
39
- TEST
40
- program = make_plain_test_program(
41
- snippet,
42
- color_enabled: color_enabled,
43
- )
44
-
45
- expected_output = build_expected_output(
46
- color_enabled: color_enabled,
47
- snippet: %|expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)|,
48
- expectation: proc {
49
- line do
50
- plain "Expected raised exception "
51
- beta %|#<StandardError "boo">|
52
- plain " not to match "
53
- alpha %|#<StandardError>|
54
- plain "."
39
+ context "when the message is long" do
40
+ it "produces the correct failure message" do
41
+ as_both_colored_and_uncolored do |color_enabled|
42
+ snippet = <<~TEST.strip
43
+ expect { raise StandardError.new('this is a super super super long message') }.to raise_error(RuntimeError)
44
+ 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
+ beta %|#<StandardError "this is a super super super long message">|
58
+ end
59
+
60
+ line do
61
+ plain " to match "
62
+ alpha %|#<RuntimeError>|
63
+ end
64
+ },
65
+ )
66
+
67
+ expect(program).
68
+ to produce_output_when_run(expected_output).
69
+ in_color(color_enabled)
55
70
  end
56
- },
57
- )
58
-
59
- expect(program).
60
- to produce_output_when_run(expected_output).
61
- in_color(color_enabled)
62
- end
63
- end
64
- end
65
-
66
- context "with only a message (and assuming a RuntimeError)" do
67
- context "when the message is short" do
68
- it "produces the correct failure message when used in the positive" do
69
- as_both_colored_and_uncolored do |color_enabled|
70
- snippet = <<~TEST.strip
71
- expect { raise 'boo' }.to raise_error('hell')
72
- TEST
73
- program = make_plain_test_program(
74
- snippet,
75
- color_enabled: color_enabled,
76
- )
77
-
78
- expected_output = build_expected_output(
79
- color_enabled: color_enabled,
80
- snippet: %|expect { raise 'boo' }.to raise_error('hell')|,
81
- expectation: proc {
82
- line do
83
- plain "Expected raised exception "
84
- beta %|#<RuntimeError "boo">|
85
- plain " to match "
86
- alpha %|#<Exception "hell">|
87
- plain "."
88
- end
89
- },
90
- )
91
-
92
- expect(program).
93
- to produce_output_when_run(expected_output).
94
- in_color(color_enabled)
71
+ end
95
72
  end
96
73
  end
97
74
 
98
- it "produces the correct failure message when used in the negative" do
99
- as_both_colored_and_uncolored do |color_enabled|
100
- snippet = <<~TEST.strip
101
- expect { raise 'boo' }.not_to raise_error('boo')
102
- TEST
103
- program = make_plain_test_program(
104
- snippet,
105
- color_enabled: color_enabled,
106
- )
107
-
108
- expected_output = build_expected_output(
109
- color_enabled: color_enabled,
110
- snippet: %|expect { raise 'boo' }.not_to raise_error('boo')|,
111
- expectation: proc {
112
- line do
113
- plain "Expected raised exception "
114
- beta %|#<RuntimeError "boo">|
115
- plain " not to match "
116
- alpha %|#<Exception "boo">|
117
- plain "."
118
- end
119
- },
120
- )
75
+ context "when the block raises no error" do
76
+ it "produces the correct failure message" do
77
+ as_both_colored_and_uncolored do |color_enabled|
78
+ snippet = <<~TEST.strip
79
+ expect { }.to raise_error(RuntimeError)
80
+ TEST
81
+ program = make_plain_test_program(
82
+ snippet,
83
+ color_enabled: color_enabled,
84
+ )
121
85
 
122
- expect(program).
123
- to produce_output_when_run(expected_output).
124
- in_color(color_enabled)
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
+ alpha %|#<RuntimeError>|
93
+ plain "."
94
+ end
95
+ },
96
+ )
97
+
98
+ expect(program).
99
+ to produce_output_when_run(expected_output).
100
+ in_color(color_enabled)
101
+ end
125
102
  end
126
103
  end
127
104
  end
128
105
 
129
- context "when the message is long" do
130
- context "but contains no line breaks" do
131
- it "produces the correct failure message when used in the positive" do
106
+ context "when used in the negative" do
107
+ context "when the message is short" do
108
+ it "produces the correct failure message" do
132
109
  as_both_colored_and_uncolored do |color_enabled|
133
110
  snippet = <<~TEST.strip
134
- actual_message = "some really really really long message"
135
- expected_message = "whatever"
136
- expect { raise(actual_message) }.to raise_error(expected_message)
111
+ expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)
137
112
  TEST
138
113
  program = make_plain_test_program(
139
114
  snippet,
@@ -142,17 +117,14 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
142
117
 
143
118
  expected_output = build_expected_output(
144
119
  color_enabled: color_enabled,
145
- snippet: %|expect { raise(actual_message) }.to raise_error(expected_message)|,
146
- newline_before_expectation: true,
120
+ snippet: %|expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)|,
147
121
  expectation: proc {
148
122
  line do
149
123
  plain "Expected raised exception "
150
- beta %|#<RuntimeError "some really really really long message">|
151
- end
152
-
153
- line do
154
- plain " to match "
155
- alpha %|#<Exception "whatever">|
124
+ beta %|#<StandardError "boo">|
125
+ plain " not to match "
126
+ alpha %|#<StandardError>|
127
+ plain "."
156
128
  end
157
129
  },
158
130
  )
@@ -162,12 +134,13 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
162
134
  in_color(color_enabled)
163
135
  end
164
136
  end
137
+ end
165
138
 
166
- it "produces the correct failure message when used in the negative" do
139
+ context "when the message is long" do
140
+ it "produces the correct failure message" do
167
141
  as_both_colored_and_uncolored do |color_enabled|
168
142
  snippet = <<~TEST.strip
169
- message = "some really long message"
170
- expect { raise(message) }.not_to raise_error(message)
143
+ expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(StandardError)
171
144
  TEST
172
145
  program = make_plain_test_program(
173
146
  snippet,
@@ -176,17 +149,17 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
176
149
 
177
150
  expected_output = build_expected_output(
178
151
  color_enabled: color_enabled,
179
- snippet: %|expect { raise(message) }.not_to raise_error(message)|,
152
+ snippet: %|expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(StandardError)|,
180
153
  newline_before_expectation: true,
181
154
  expectation: proc {
182
155
  line do
183
156
  plain "Expected raised exception "
184
- beta %|#<RuntimeError "some really long message">|
157
+ beta %|#<StandardError "this is a super super long message">|
185
158
  end
186
159
 
187
160
  line do
188
161
  plain " not to match "
189
- alpha %|#<Exception "some really long message">|
162
+ alpha %|#<StandardError>|
190
163
  end
191
164
  },
192
165
  )
@@ -197,20 +170,244 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
197
170
  end
198
171
  end
199
172
  end
173
+ end
174
+ end
175
+
176
+ context "with only a message (and assuming a RuntimeError)" do
177
+ context "when used in the positive" do
178
+ context "when the block raises a different error than what is given" do
179
+ context "when the message is short" do
180
+ it "produces the correct failure message" do
181
+ as_both_colored_and_uncolored do |color_enabled|
182
+ snippet = <<~TEST.strip
183
+ expect { raise 'boo' }.to raise_error('hell')
184
+ TEST
185
+ program = make_plain_test_program(
186
+ snippet,
187
+ color_enabled: color_enabled,
188
+ )
189
+
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
+ beta %|#<RuntimeError "boo">|
197
+ plain " to match "
198
+ alpha %|#<Exception "hell">|
199
+ plain "."
200
+ end
201
+ },
202
+ )
203
+
204
+ expect(program).
205
+ to produce_output_when_run(expected_output).
206
+ in_color(color_enabled)
207
+ end
208
+ end
209
+ end
210
+
211
+ context "when the message is long" do
212
+ context "but contains no line breaks" do
213
+ it "produces the correct failure message when used in the positive" do
214
+ as_both_colored_and_uncolored do |color_enabled|
215
+ snippet = <<~TEST.strip
216
+ actual_message = "some really really really long message"
217
+ expected_message = "whatever"
218
+ expect { raise(actual_message) }.to raise_error(expected_message)
219
+ 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
+ beta %|#<RuntimeError "some really really really long message">|
233
+ end
234
+
235
+ line do
236
+ plain " to match "
237
+ alpha %|#<Exception "whatever">|
238
+ end
239
+ },
240
+ )
241
+
242
+ expect(program).
243
+ to produce_output_when_run(expected_output).
244
+ in_color(color_enabled)
245
+ end
246
+ end
247
+ end
248
+
249
+ context "but contains line breaks" do
250
+ it "produces the correct failure message when used in the positive" do
251
+ as_both_colored_and_uncolored do |color_enabled|
252
+ snippet = <<~TEST.strip
253
+ actual_message = <<\~MESSAGE.rstrip
254
+ This is fun
255
+ So is this
256
+ MESSAGE
257
+ expected_message = <<\~MESSAGE.rstrip
258
+ This is fun
259
+ And so is this
260
+ MESSAGE
261
+ expect { raise(actual_message) }.to raise_error(expected_message)
262
+ 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
+ beta %|#<RuntimeError "This is fun\\nSo is this">|
275
+ end
276
+
277
+ line do
278
+ plain " to match "
279
+ alpha %|#<Exception "This is fun\\nAnd so is this">|
280
+ end
281
+ },
282
+ diff: proc {
283
+ plain_line %| This is fun\\n|
284
+ alpha_line %|- And so is this|
285
+ beta_line %|+ So is this|
286
+ },
287
+ )
288
+
289
+ expect(program).
290
+ to produce_output_when_run(expected_output).
291
+ in_color(color_enabled)
292
+ end
293
+ end
294
+ end
295
+ end
296
+ end
297
+
298
+ context "when the block raises no error" do
299
+ context "when the message is short" do
300
+ it "produces the correct failure message" do
301
+ as_both_colored_and_uncolored do |color_enabled|
302
+ snippet = <<~TEST.strip
303
+ expect { }.to raise_error('hell')
304
+ TEST
305
+ program = make_plain_test_program(
306
+ snippet,
307
+ color_enabled: color_enabled,
308
+ )
309
+
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
+ alpha %|#<Exception "hell">|
317
+ plain "."
318
+ end
319
+ },
320
+ )
321
+
322
+ expect(program).
323
+ to produce_output_when_run(expected_output).
324
+ in_color(color_enabled)
325
+ end
326
+ end
327
+
328
+ end
329
+
330
+ context "when the message is long" do
331
+ context "but contains no line breaks" do
332
+ it "produces the correct failure message" do
333
+ as_both_colored_and_uncolored do |color_enabled|
334
+ snippet = <<~TEST.strip
335
+ expect { }.to raise_error("this is a super super super super super super long message")
336
+ 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
+ alpha %|#<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)
362
+ end
363
+ end
364
+ end
365
+
366
+ context "but contains line breaks" do
367
+ it "produces the correct failure message when used in the negative" do
368
+ as_both_colored_and_uncolored do |color_enabled|
369
+ snippet = <<~TEST.strip
370
+ message = "some really long message"
371
+ expect { raise(message) }.not_to raise_error(message)
372
+ 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
+ beta %|#<RuntimeError "some really long message">|
386
+ end
387
+
388
+ line do
389
+ plain " not to match "
390
+ alpha %|#<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)
398
+ end
399
+ end
400
+ end
401
+ end
402
+ end
403
+ end
200
404
 
201
- context "but contains line breaks" do
202
- it "produces the correct failure message when used in the positive" do
405
+ context "when used in the negative" do
406
+ context "when the message is short" do
407
+ it "produces the correct failure message" do
203
408
  as_both_colored_and_uncolored do |color_enabled|
204
409
  snippet = <<~TEST.strip
205
- actual_message = <<\~MESSAGE.rstrip
206
- This is fun
207
- So is this
208
- MESSAGE
209
- expected_message = <<\~MESSAGE.rstrip
210
- This is fun
211
- And so is this
212
- MESSAGE
213
- expect { raise(actual_message) }.to raise_error(expected_message)
410
+ expect { raise 'boo' }.not_to raise_error('boo')
214
411
  TEST
215
412
  program = make_plain_test_program(
216
413
  snippet,
@@ -219,23 +416,270 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
219
416
 
220
417
  expected_output = build_expected_output(
221
418
  color_enabled: color_enabled,
222
- snippet: %|expect { raise(actual_message) }.to raise_error(expected_message)|,
419
+ snippet: %|expect { raise 'boo' }.not_to raise_error('boo')|,
223
420
  expectation: proc {
224
421
  line do
225
422
  plain "Expected raised exception "
226
- beta %|#<RuntimeError "This is fun\\nSo is this">|
423
+ beta %|#<RuntimeError "boo">|
424
+ plain " not to match "
425
+ alpha %|#<Exception "boo">|
426
+ plain "."
227
427
  end
428
+ },
429
+ )
430
+
431
+ expect(program).
432
+ to produce_output_when_run(expected_output).
433
+ in_color(color_enabled)
434
+ end
435
+ end
436
+ end
228
437
 
438
+ context "when the message is long" do
439
+ context "but contains no line breaks" do
440
+ it "produces the correct failure message" do
441
+ as_both_colored_and_uncolored do |color_enabled|
442
+ snippet = <<~TEST.strip
443
+ message = "some really long message"
444
+ expect { raise(message) }.not_to raise_error(message)
445
+ 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
+ beta %|#<RuntimeError "some really long message">|
459
+ end
460
+
461
+ line do
462
+ plain " not to match "
463
+ alpha %|#<Exception "some really long message">|
464
+ end
465
+ },
466
+ )
467
+
468
+ expect(program).
469
+ to produce_output_when_run(expected_output).
470
+ in_color(color_enabled)
471
+ end
472
+ end
473
+ end
474
+
475
+ context "but contains line breaks" do
476
+ it "produces the correct failure message" do
477
+ as_both_colored_and_uncolored do |color_enabled|
478
+ snippet = <<~TEST.strip
479
+ message = <<\~MESSAGE.rstrip
480
+ This is fun
481
+ So is this
482
+ MESSAGE
483
+ expect { raise(message) }.not_to raise_error(message)
484
+ TEST
485
+ program = make_plain_test_program(
486
+ snippet,
487
+ color_enabled: color_enabled,
488
+ )
489
+
490
+ expected_output = build_expected_output(
491
+ color_enabled: color_enabled,
492
+ snippet: %|expect { raise(message) }.not_to raise_error(message)|,
493
+ newline_before_expectation: true,
494
+ expectation: proc {
495
+ line do
496
+ plain "Expected raised exception "
497
+ beta %|#<RuntimeError "This is fun\\nSo is this">|
498
+ end
499
+
500
+ line do
501
+ plain " not to match "
502
+ alpha %|#<Exception "This is fun\\nSo is this">|
503
+ end
504
+ },
505
+ )
506
+
507
+ expect(program).
508
+ to produce_output_when_run(expected_output).
509
+ in_color(color_enabled)
510
+ end
511
+ end
512
+ end
513
+ end
514
+ end
515
+ end
516
+
517
+ context "with both an exception and a message" do
518
+ context "when used in the positive" do
519
+ context "when the block raises a different error than what is given" do
520
+ context "when the message is short" do
521
+ it "produces the correct failure message" do
522
+ as_both_colored_and_uncolored do |color_enabled|
523
+ snippet = <<~TEST.strip
524
+ block = -> { raise StandardError.new('a') }
525
+ expect(&block).to raise_error(RuntimeError, 'b')
526
+ TEST
527
+ program = make_plain_test_program(
528
+ snippet,
529
+ color_enabled: color_enabled,
530
+ )
531
+
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
+ beta %|#<StandardError "a">|
539
+ plain " to match "
540
+ alpha %|#<RuntimeError "b">|
541
+ plain "."
542
+ end
543
+ },
544
+ )
545
+
546
+ expect(program).
547
+ to produce_output_when_run(expected_output).
548
+ in_color(color_enabled)
549
+ end
550
+ end
551
+ end
552
+
553
+ context "when the message is long" do
554
+ it "produces the correct failure message" do
555
+ as_both_colored_and_uncolored do |color_enabled|
556
+ snippet = <<~TEST.strip
557
+ block = -> { raise StandardError.new('this is a long message') }
558
+ expect(&block).to raise_error(RuntimeError, 'this is another long message')
559
+ TEST
560
+ program = make_plain_test_program(
561
+ snippet,
562
+ color_enabled: color_enabled,
563
+ )
564
+
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
+ beta %|#<StandardError "this is a long message">|
573
+ end
574
+
575
+ line do
576
+ plain " to match "
577
+ alpha %|#<RuntimeError "this is another long message">|
578
+ end
579
+ },
580
+ )
581
+
582
+ expect(program).
583
+ to produce_output_when_run(expected_output).
584
+ in_color(color_enabled)
585
+ end
586
+ end
587
+ end
588
+ end
589
+
590
+ context "when the block raises no error" do
591
+ context "when the message is short" do
592
+ it "produces the correct failure message" do
593
+ as_both_colored_and_uncolored do |color_enabled|
594
+ snippet = <<~TEST.strip
595
+ expect { }.to raise_error(RuntimeError, 'b')
596
+ TEST
597
+ program = make_plain_test_program(
598
+ snippet,
599
+ color_enabled: color_enabled,
600
+ )
601
+
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
+ alpha %|#<RuntimeError "b">|
609
+ plain "."
610
+ end
611
+ },
612
+ )
613
+
614
+ expect(program).
615
+ to produce_output_when_run(expected_output).
616
+ in_color(color_enabled)
617
+ end
618
+ end
619
+ end
620
+
621
+ context "when the message is long" do
622
+ it "produces the correct failure message" do
623
+ as_both_colored_and_uncolored do |color_enabled|
624
+ snippet = <<~TEST.strip
625
+ expect { }.to raise_error(RuntimeError, 'this is a super super super super super super long message')
626
+ TEST
627
+ program = make_plain_test_program(
628
+ snippet,
629
+ color_enabled: color_enabled,
630
+ )
631
+
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 {
637
+ line do
638
+ plain " Expected "
639
+ plain "block"
640
+ end
641
+
642
+ line do
643
+ plain "to raise error "
644
+ alpha %|#<RuntimeError "this is a super super super super super super long message">|
645
+ end
646
+ },
647
+ )
648
+
649
+ expect(program).
650
+ to produce_output_when_run(expected_output).
651
+ in_color(color_enabled)
652
+ end
653
+ end
654
+ end
655
+ end
656
+ end
657
+
658
+ context "when used in the negative" do
659
+ context "when the message is short" do
660
+ it "produces the correct failure message" do
661
+ as_both_colored_and_uncolored do |color_enabled|
662
+ snippet = <<~TEST.strip
663
+ block = -> { raise StandardError.new('a') }
664
+ expect(&block).not_to raise_error(StandardError, 'a')
665
+ TEST
666
+ program = make_plain_test_program(
667
+ snippet,
668
+ color_enabled: color_enabled,
669
+ )
670
+
671
+ expected_output = build_expected_output(
672
+ color_enabled: color_enabled,
673
+ snippet: %|expect(&block).not_to raise_error(StandardError, 'a')|,
674
+ expectation: proc {
229
675
  line do
230
- plain " to match "
231
- alpha %|#<Exception "This is fun\\nAnd so is this">|
676
+ plain "Expected raised exception "
677
+ beta %|#<StandardError "a">|
678
+ plain " not to match "
679
+ alpha %|#<StandardError "a">|
680
+ plain "."
232
681
  end
233
682
  },
234
- diff: proc {
235
- plain_line %| This is fun\\n|
236
- alpha_line %|- And so is this|
237
- beta_line %|+ So is this|
238
- },
239
683
  )
240
684
 
241
685
  expect(program).
@@ -243,15 +687,14 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
243
687
  in_color(color_enabled)
244
688
  end
245
689
  end
690
+ end
246
691
 
247
- it "produces the correct failure message when used in the negative" do
692
+ context "when the message is long" do
693
+ it "produces the correct failure message" do
248
694
  as_both_colored_and_uncolored do |color_enabled|
249
695
  snippet = <<~TEST.strip
250
- message = <<\~MESSAGE.rstrip
251
- This is fun
252
- So is this
253
- MESSAGE
254
- expect { raise(message) }.not_to raise_error(message)
696
+ block = -> { raise StandardError.new('this is a long message') }
697
+ expect(&block).not_to raise_error(StandardError, 'this is a long message')
255
698
  TEST
256
699
  program = make_plain_test_program(
257
700
  snippet,
@@ -260,17 +703,17 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
260
703
 
261
704
  expected_output = build_expected_output(
262
705
  color_enabled: color_enabled,
263
- snippet: %|expect { raise(message) }.not_to raise_error(message)|,
706
+ snippet: %|expect(&block).not_to raise_error(StandardError, 'this is a long message')|,
264
707
  newline_before_expectation: true,
265
708
  expectation: proc {
266
709
  line do
267
710
  plain "Expected raised exception "
268
- beta %|#<RuntimeError "This is fun\\nSo is this">|
711
+ beta %|#<StandardError "this is a long message">|
269
712
  end
270
713
 
271
714
  line do
272
715
  plain " not to match "
273
- alpha %|#<Exception "This is fun\\nSo is this">|
716
+ alpha %|#<StandardError "this is a long message">|
274
717
  end
275
718
  },
276
719
  )
@@ -283,68 +726,4 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
283
726
  end
284
727
  end
285
728
  end
286
-
287
- context "with both an exception and a message" do
288
- it "produces the correct failure message when used in the positive" do
289
- as_both_colored_and_uncolored do |color_enabled|
290
- snippet = <<~TEST.strip
291
- block = -> { raise StandardError.new('a') }
292
- expect(&block).to raise_error(RuntimeError, 'b')
293
- TEST
294
- program = make_plain_test_program(
295
- snippet,
296
- color_enabled: color_enabled,
297
- )
298
-
299
- expected_output = build_expected_output(
300
- color_enabled: color_enabled,
301
- snippet: %|expect(&block).to raise_error(RuntimeError, 'b')|,
302
- expectation: proc {
303
- line do
304
- plain "Expected raised exception "
305
- beta %|#<StandardError "a">|
306
- plain " to match "
307
- alpha %|#<RuntimeError "b">|
308
- plain "."
309
- end
310
- },
311
- )
312
-
313
- expect(program).
314
- to produce_output_when_run(expected_output).
315
- in_color(color_enabled)
316
- end
317
- end
318
-
319
- it "produces the correct failure message when used in the negative" do
320
- as_both_colored_and_uncolored do |color_enabled|
321
- snippet = <<~TEST.strip
322
- block = -> { raise StandardError.new('a') }
323
- expect(&block).not_to raise_error(StandardError, 'a')
324
- TEST
325
- program = make_plain_test_program(
326
- snippet,
327
- color_enabled: color_enabled,
328
- )
329
-
330
- expected_output = build_expected_output(
331
- color_enabled: color_enabled,
332
- snippet: %|expect(&block).not_to raise_error(StandardError, 'a')|,
333
- expectation: proc {
334
- line do
335
- plain "Expected raised exception "
336
- beta %|#<StandardError "a">|
337
- plain " not to match "
338
- alpha %|#<StandardError "a">|
339
- plain "."
340
- end
341
- },
342
- )
343
-
344
- expect(program).
345
- to produce_output_when_run(expected_output).
346
- in_color(color_enabled)
347
- end
348
- end
349
- end
350
729
  end