super_diff 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +117 -89
  3. data/lib/super_diff.rb +33 -47
  4. data/lib/super_diff/active_record.rb +41 -0
  5. data/lib/super_diff/active_record/diff_formatters.rb +10 -0
  6. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +23 -0
  7. data/lib/super_diff/active_record/differs.rb +10 -0
  8. data/lib/super_diff/active_record/differs/active_record_relation.rb +30 -0
  9. data/lib/super_diff/active_record/object_inspection.rb +14 -0
  10. data/lib/super_diff/active_record/object_inspection/inspectors.rb +16 -0
  11. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +38 -0
  12. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +18 -0
  13. data/lib/super_diff/active_record/object_inspection/map_extension.rb +18 -0
  14. data/lib/super_diff/active_record/operation_sequences.rb +10 -0
  15. data/lib/super_diff/active_record/operation_sequences/active_record_relation.rb +16 -0
  16. data/lib/super_diff/active_record/operational_sequencers.rb +14 -0
  17. data/lib/super_diff/active_record/operational_sequencers/active_record_model.rb +19 -0
  18. data/lib/super_diff/active_record/operational_sequencers/active_record_relation.rb +24 -0
  19. data/lib/super_diff/active_support.rb +33 -0
  20. data/lib/super_diff/active_support/diff_formatters.rb +10 -0
  21. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +36 -0
  22. data/lib/super_diff/active_support/differs.rb +10 -0
  23. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +36 -0
  24. data/lib/super_diff/active_support/object_inspection.rb +14 -0
  25. data/lib/super_diff/active_support/object_inspection/inspectors.rb +12 -0
  26. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +18 -0
  27. data/lib/super_diff/active_support/object_inspection/map_extension.rb +15 -0
  28. data/lib/super_diff/active_support/operation_sequences.rb +10 -0
  29. data/lib/super_diff/active_support/operation_sequences/hash_with_indifferent_access.rb +16 -0
  30. data/lib/super_diff/active_support/operational_sequencers.rb +10 -0
  31. data/lib/super_diff/active_support/operational_sequencers/hash_with_indifferent_access.rb +21 -0
  32. data/lib/super_diff/colorized_document_extensions.rb +17 -0
  33. data/lib/super_diff/csi.rb +45 -15
  34. data/lib/super_diff/csi/bold_sequence.rb +9 -0
  35. data/lib/super_diff/csi/color.rb +62 -0
  36. data/lib/super_diff/csi/color_sequence_block.rb +28 -0
  37. data/lib/super_diff/csi/colorized_document.rb +72 -0
  38. data/lib/super_diff/csi/document.rb +183 -0
  39. data/lib/super_diff/csi/eight_bit_color.rb +72 -26
  40. data/lib/super_diff/csi/four_bit_color.rb +63 -29
  41. data/lib/super_diff/csi/twenty_four_bit_color.rb +79 -18
  42. data/lib/super_diff/csi/uncolorized_document.rb +29 -0
  43. data/lib/super_diff/diff_formatter.rb +10 -15
  44. data/lib/super_diff/diff_formatters.rb +10 -1
  45. data/lib/super_diff/diff_formatters/base.rb +12 -17
  46. data/lib/super_diff/diff_formatters/collection.rb +81 -50
  47. data/lib/super_diff/diff_formatters/{object.rb → custom_object.rb} +12 -9
  48. data/lib/super_diff/diff_formatters/default_object.rb +48 -0
  49. data/lib/super_diff/diff_formatters/multiline_string.rb +31 -0
  50. data/lib/super_diff/differ.rb +35 -32
  51. data/lib/super_diff/differs.rb +16 -1
  52. data/lib/super_diff/differs/array.rb +2 -2
  53. data/lib/super_diff/differs/base.rb +11 -21
  54. data/lib/super_diff/differs/custom_object.rb +26 -0
  55. data/lib/super_diff/differs/default_object.rb +25 -0
  56. data/lib/super_diff/differs/empty.rb +1 -1
  57. data/lib/super_diff/differs/hash.rb +2 -2
  58. data/lib/super_diff/differs/{multi_line_string.rb → multiline_string.rb} +6 -5
  59. data/lib/super_diff/equality_matcher.rb +9 -22
  60. data/lib/super_diff/equality_matchers.rb +19 -1
  61. data/lib/super_diff/equality_matchers/array.rb +6 -4
  62. data/lib/super_diff/equality_matchers/base.rb +8 -16
  63. data/lib/super_diff/equality_matchers/default.rb +60 -0
  64. data/lib/super_diff/equality_matchers/hash.rb +6 -4
  65. data/lib/super_diff/equality_matchers/{multi_line_string.rb → multiline_string.rb} +9 -6
  66. data/lib/super_diff/equality_matchers/primitive.rb +34 -0
  67. data/lib/super_diff/equality_matchers/{single_line_string.rb → singleline_string.rb} +7 -5
  68. data/lib/super_diff/helpers.rb +17 -81
  69. data/lib/super_diff/no_differ_available_error.rb +22 -0
  70. data/lib/super_diff/{errors.rb → no_operational_sequencer_available_error.rb} +0 -0
  71. data/lib/super_diff/object_inspection.rb +24 -0
  72. data/lib/super_diff/object_inspection/inspection_tree.rb +144 -0
  73. data/lib/super_diff/object_inspection/inspector.rb +27 -0
  74. data/lib/super_diff/object_inspection/inspectors.rb +18 -0
  75. data/lib/super_diff/object_inspection/inspectors/array.rb +22 -0
  76. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +27 -0
  77. data/lib/super_diff/object_inspection/inspectors/default_object.rb +47 -0
  78. data/lib/super_diff/object_inspection/inspectors/hash.rb +22 -0
  79. data/lib/super_diff/object_inspection/inspectors/primitive.rb +13 -0
  80. data/lib/super_diff/object_inspection/inspectors/string.rb +13 -0
  81. data/lib/super_diff/object_inspection/map.rb +28 -0
  82. data/lib/super_diff/object_inspection/nodes.rb +49 -0
  83. data/lib/super_diff/object_inspection/nodes/base.rb +86 -0
  84. data/lib/super_diff/object_inspection/nodes/break.rb +15 -0
  85. data/lib/super_diff/object_inspection/nodes/inspection.rb +15 -0
  86. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -0
  87. data/lib/super_diff/object_inspection/nodes/text.rb +15 -0
  88. data/lib/super_diff/object_inspection/nodes/when_empty.rb +30 -0
  89. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +22 -0
  90. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +30 -0
  91. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +24 -0
  92. data/lib/super_diff/operation_sequences.rb +9 -0
  93. data/lib/super_diff/operation_sequences/base.rb +1 -1
  94. data/lib/super_diff/operation_sequences/{object.rb → custom_object.rb} +4 -3
  95. data/lib/super_diff/operation_sequences/default_object.rb +25 -0
  96. data/lib/super_diff/operational_sequencer.rb +23 -18
  97. data/lib/super_diff/operational_sequencers.rb +12 -1
  98. data/lib/super_diff/operational_sequencers/array.rb +65 -62
  99. data/lib/super_diff/operational_sequencers/base.rb +18 -26
  100. data/lib/super_diff/operational_sequencers/custom_object.rb +35 -0
  101. data/lib/super_diff/operational_sequencers/{object.rb → default_object.rb} +21 -11
  102. data/lib/super_diff/operational_sequencers/hash.rb +8 -5
  103. data/lib/super_diff/operational_sequencers/{multi_line_string.rb → multiline_string.rb} +11 -6
  104. data/lib/super_diff/operations.rb +6 -0
  105. data/lib/super_diff/operations/binary_operation.rb +14 -34
  106. data/lib/super_diff/operations/unary_operation.rb +11 -2
  107. data/lib/super_diff/rails.rb +1 -0
  108. data/lib/super_diff/recursion_guard.rb +47 -0
  109. data/lib/super_diff/rspec-rails.rb +2 -0
  110. data/lib/super_diff/rspec.rb +52 -8
  111. data/lib/super_diff/rspec/augmented_matcher.rb +98 -0
  112. data/lib/super_diff/rspec/configuration.rb +31 -0
  113. data/lib/super_diff/rspec/differ.rb +60 -16
  114. data/lib/super_diff/rspec/differs.rb +13 -0
  115. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +23 -0
  116. data/lib/super_diff/rspec/differs/partial_array.rb +22 -0
  117. data/lib/super_diff/rspec/differs/partial_hash.rb +22 -0
  118. data/lib/super_diff/rspec/differs/partial_object.rb +22 -0
  119. data/lib/super_diff/rspec/matcher_text_builders.rb +24 -0
  120. data/lib/super_diff/rspec/matcher_text_builders/base.rb +155 -0
  121. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +78 -0
  122. data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +14 -0
  123. data/lib/super_diff/rspec/matcher_text_builders/match.rb +23 -0
  124. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -0
  125. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +99 -0
  126. data/lib/super_diff/rspec/matcher_text_template.rb +240 -0
  127. data/lib/super_diff/rspec/monkey_patches.rb +601 -98
  128. data/lib/super_diff/rspec/object_inspection.rb +8 -0
  129. data/lib/super_diff/rspec/object_inspection/inspectors.rb +24 -0
  130. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +19 -0
  131. data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +22 -0
  132. data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +21 -0
  133. data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +21 -0
  134. data/lib/super_diff/rspec/object_inspection/map_extension.rb +23 -0
  135. data/lib/super_diff/rspec/operational_sequencers.rb +22 -0
  136. data/lib/super_diff/rspec/operational_sequencers/collection_containing_exactly.rb +97 -0
  137. data/lib/super_diff/rspec/operational_sequencers/partial_array.rb +23 -0
  138. data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +32 -0
  139. data/lib/super_diff/rspec/operational_sequencers/partial_object.rb +64 -0
  140. data/lib/super_diff/version.rb +1 -1
  141. data/spec/examples.txt +328 -46
  142. data/spec/integration/rails/active_record_spec.rb +19 -0
  143. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +19 -0
  144. data/spec/integration/rspec/be_falsey_matcher_spec.rb +53 -0
  145. data/spec/integration/rspec/be_matcher_spec.rb +565 -0
  146. data/spec/integration/rspec/be_nil_matcher_spec.rb +53 -0
  147. data/spec/integration/rspec/be_predicate_matcher_spec.rb +546 -0
  148. data/spec/integration/rspec/be_truthy_matcher_spec.rb +57 -0
  149. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +368 -0
  150. data/spec/integration/rspec/eq_matcher_spec.rb +874 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +299 -0
  152. data/spec/integration/rspec/include_matcher_spec.rb +350 -0
  153. data/spec/integration/rspec/match_matcher_spec.rb +1258 -0
  154. data/spec/integration/rspec/raise_error_matcher_spec.rb +350 -0
  155. data/spec/integration/rspec/respond_to_matcher_spec.rb +994 -0
  156. data/spec/integration/rspec/unhandled_errors_spec.rb +94 -0
  157. data/spec/spec_helper.rb +19 -4
  158. data/spec/support/colorizer.rb +9 -0
  159. data/spec/support/command_runner.rb +4 -0
  160. data/spec/support/integration/helpers.rb +179 -0
  161. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +79 -41
  162. data/spec/support/models/a.rb +11 -0
  163. data/spec/support/models/active_record/person.rb +26 -0
  164. data/spec/support/models/active_record/shipping_address.rb +29 -0
  165. data/spec/support/models/customer.rb +24 -0
  166. data/spec/support/models/empty_class.rb +6 -0
  167. data/spec/support/models/item.rb +10 -0
  168. data/spec/support/models/order.rb +9 -0
  169. data/spec/support/models/person.rb +20 -0
  170. data/spec/support/models/player.rb +33 -0
  171. data/spec/support/models/shipping_address.rb +34 -0
  172. data/spec/support/ruby_versions.rb +7 -0
  173. data/spec/support/shared_examples/active_record.rb +338 -0
  174. data/spec/support/shared_examples/hash_with_indifferent_access.rb +233 -0
  175. data/spec/unit/equality_matcher_spec.rb +579 -171
  176. data/spec/unit/object_inspection_spec.rb +1092 -0
  177. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +23 -0
  178. data/spec/unit/rspec/matchers/be_falsey_spec.rb +9 -0
  179. data/spec/unit/rspec/matchers/be_nil_spec.rb +9 -0
  180. data/spec/unit/rspec/matchers/be_predicate_spec.rb +31 -0
  181. data/spec/unit/rspec/matchers/be_spec.rb +17 -0
  182. data/spec/unit/rspec/matchers/be_truthy_spec.rb +9 -0
  183. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +11 -0
  184. data/spec/unit/rspec/matchers/eq_spec.rb +9 -0
  185. data/spec/unit/rspec/matchers/have_attributes_spec.rb +11 -0
  186. data/spec/unit/rspec/matchers/include_spec.rb +21 -0
  187. data/spec/unit/rspec/matchers/match_spec.rb +9 -0
  188. data/spec/unit/rspec/matchers/raise_error_spec.rb +29 -0
  189. data/spec/unit/rspec/matchers/respond_to_spec.rb +78 -0
  190. data/super_diff.gemspec +4 -2
  191. metadata +231 -34
  192. data/lib/super_diff/csi/color_helper.rb +0 -52
  193. data/lib/super_diff/csi/eight_bit_sequence.rb +0 -27
  194. data/lib/super_diff/csi/four_bit_sequence.rb +0 -24
  195. data/lib/super_diff/csi/sequence.rb +0 -22
  196. data/lib/super_diff/csi/twenty_four_bit_sequence.rb +0 -27
  197. data/lib/super_diff/diff_formatters/multi_line_string.rb +0 -31
  198. data/lib/super_diff/differs/object.rb +0 -68
  199. data/lib/super_diff/equality_matchers/object.rb +0 -18
  200. data/lib/super_diff/value_inspection.rb +0 -11
  201. data/spec/integration/rspec_spec.rb +0 -261
  202. data/spec/support/color_helper.rb +0 -49
  203. data/spec/support/person.rb +0 -23
  204. data/spec/support/person_diff_formatter.rb +0 -15
  205. data/spec/support/person_operation_sequence.rb +0 -14
  206. data/spec/support/person_operational_sequencer.rb +0 -19
@@ -0,0 +1,233 @@
1
+ shared_examples_for "integration with HashWithIndifferentAccess" do
2
+ describe "and RSpec's #eq matcher" do
3
+ context "when the actual value is a HashWithIndifferentAccess" do
4
+ it "produces the correct output" do
5
+ as_both_colored_and_uncolored do |color_enabled|
6
+ snippet = <<~TEST.strip
7
+ expected = {
8
+ line_1: "123 Main St.",
9
+ city: "Hill Valley",
10
+ state: "CA",
11
+ zip: "90382",
12
+ }
13
+ actual = HashWithIndifferentAccess.new({
14
+ line_1: "456 Ponderosa Ct.",
15
+ city: "Oakland",
16
+ state: "CA",
17
+ zip: "91234",
18
+ })
19
+ expect(actual).to eq(expected)
20
+ TEST
21
+ program = make_rspec_rails_test_program(
22
+ snippet,
23
+ color_enabled: color_enabled,
24
+ )
25
+
26
+ expected_output = build_expected_output(
27
+ color_enabled: color_enabled,
28
+ snippet: "expect(actual).to eq(expected)",
29
+ expectation: proc {
30
+ line do
31
+ plain "Expected "
32
+ beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
33
+ end
34
+
35
+ line do
36
+ plain " to eq "
37
+ alpha %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
38
+ end
39
+ },
40
+ diff: proc {
41
+ plain_line %| #<HashWithIndifferentAccess {|
42
+ alpha_line %|- "line_1" => "123 Main St.",|
43
+ beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
44
+ alpha_line %|- "city" => "Hill Valley",|
45
+ beta_line %|+ "city" => "Oakland",|
46
+ plain_line %| "state" => "CA",|
47
+ alpha_line %|- "zip" => "90382"|
48
+ beta_line %|+ "zip" => "91234"|
49
+ plain_line %| }>|
50
+ },
51
+ )
52
+
53
+ expect(program).
54
+ to produce_output_when_run(expected_output).
55
+ in_color(color_enabled)
56
+ end
57
+ end
58
+ end
59
+
60
+ context "when the expected value is a HashWithIndifferentAccess" do
61
+ it "produces the correct output" do
62
+ as_both_colored_and_uncolored do |color_enabled|
63
+ snippet = <<~TEST.strip
64
+ expected = HashWithIndifferentAccess.new({
65
+ line_1: "456 Ponderosa Ct.",
66
+ city: "Oakland",
67
+ state: "CA",
68
+ zip: "91234",
69
+ })
70
+ actual = {
71
+ line_1: "123 Main St.",
72
+ city: "Hill Valley",
73
+ state: "CA",
74
+ zip: "90382",
75
+ }
76
+ expect(actual).to eq(expected)
77
+ TEST
78
+ program = make_rspec_rails_test_program(
79
+ snippet,
80
+ color_enabled: color_enabled,
81
+ )
82
+
83
+ expected_output = build_expected_output(
84
+ color_enabled: color_enabled,
85
+ snippet: "expect(actual).to eq(expected)",
86
+ expectation: proc {
87
+ line do
88
+ plain "Expected "
89
+ beta %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
90
+ end
91
+
92
+ line do
93
+ plain " to eq "
94
+ alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
95
+ end
96
+ },
97
+ diff: proc {
98
+ plain_line %| #<HashWithIndifferentAccess {|
99
+ alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
100
+ beta_line %|+ "line_1" => "123 Main St.",|
101
+ alpha_line %|- "city" => "Oakland",|
102
+ beta_line %|+ "city" => "Hill Valley",|
103
+ plain_line %| "state" => "CA",|
104
+ alpha_line %|- "zip" => "91234"|
105
+ beta_line %|+ "zip" => "90382"|
106
+ plain_line %| }>|
107
+ },
108
+ )
109
+
110
+ expect(program).
111
+ to produce_output_when_run(expected_output).
112
+ in_color(color_enabled)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "and RSpec's #match matcher" do
119
+ context "when the actual value is a HashWithIndifferentAccess" do
120
+ it "produces the correct output" do
121
+ as_both_colored_and_uncolored do |color_enabled|
122
+ snippet = <<~TEST.strip
123
+ expected = {
124
+ line_1: "123 Main St.",
125
+ city: "Hill Valley",
126
+ state: "CA",
127
+ zip: "90382",
128
+ }
129
+ actual = HashWithIndifferentAccess.new({
130
+ line_1: "456 Ponderosa Ct.",
131
+ city: "Oakland",
132
+ state: "CA",
133
+ zip: "91234",
134
+ })
135
+ expect(actual).to match(expected)
136
+ TEST
137
+ program = make_rspec_rails_test_program(
138
+ snippet,
139
+ color_enabled: color_enabled,
140
+ )
141
+
142
+ expected_output = build_expected_output(
143
+ color_enabled: color_enabled,
144
+ snippet: "expect(actual).to match(expected)",
145
+ expectation: proc {
146
+ line do
147
+ plain "Expected "
148
+ beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
149
+ end
150
+
151
+ line do
152
+ plain "to match "
153
+ alpha %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
154
+ end
155
+ },
156
+ diff: proc {
157
+ plain_line %| #<HashWithIndifferentAccess {|
158
+ alpha_line %|- "line_1" => "123 Main St.",|
159
+ beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
160
+ alpha_line %|- "city" => "Hill Valley",|
161
+ beta_line %|+ "city" => "Oakland",|
162
+ plain_line %| "state" => "CA",|
163
+ alpha_line %|- "zip" => "90382"|
164
+ beta_line %|+ "zip" => "91234"|
165
+ plain_line %| }>|
166
+ },
167
+ )
168
+
169
+ expect(program).
170
+ to produce_output_when_run(expected_output).
171
+ in_color(color_enabled)
172
+ end
173
+ end
174
+ end
175
+
176
+ context "when the expected value is a HashWithIndifferentAccess" do
177
+ it "produces the correct output" do
178
+ as_both_colored_and_uncolored do |color_enabled|
179
+ snippet = <<~TEST.strip
180
+ expected = HashWithIndifferentAccess.new({
181
+ line_1: "456 Ponderosa Ct.",
182
+ city: "Oakland",
183
+ state: "CA",
184
+ zip: "91234",
185
+ })
186
+ actual = {
187
+ line_1: "123 Main St.",
188
+ city: "Hill Valley",
189
+ state: "CA",
190
+ zip: "90382",
191
+ }
192
+ expect(actual).to match(expected)
193
+ TEST
194
+ program = make_rspec_rails_test_program(
195
+ snippet,
196
+ color_enabled: color_enabled,
197
+ )
198
+
199
+ expected_output = build_expected_output(
200
+ color_enabled: color_enabled,
201
+ snippet: "expect(actual).to match(expected)",
202
+ expectation: proc {
203
+ line do
204
+ plain "Expected "
205
+ beta %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
206
+ end
207
+
208
+ line do
209
+ plain "to match "
210
+ alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
211
+ end
212
+ },
213
+ diff: proc {
214
+ plain_line %| #<HashWithIndifferentAccess {|
215
+ alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
216
+ beta_line %|+ "line_1" => "123 Main St.",|
217
+ alpha_line %|- "city" => "Oakland",|
218
+ beta_line %|+ "city" => "Hill Valley",|
219
+ plain_line %| "state" => "CA",|
220
+ alpha_line %|- "zip" => "91234"|
221
+ beta_line %|+ "zip" => "90382"|
222
+ plain_line %| }>|
223
+ },
224
+ )
225
+
226
+ expect(program).
227
+ to produce_output_when_run(expected_output).
228
+ in_color(color_enabled)
229
+ end
230
+ end
231
+ end
232
+ end
233
+ end
@@ -27,8 +27,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
27
27
 
28
28
  #{
29
29
  colored do
30
- red_line %(Expected: 42)
31
- green_line %( Actual: 1)
30
+ alpha_line %(Expected: 42)
31
+ beta_line %( Actual: 1)
32
32
  end
33
33
  }
34
34
  STR
@@ -54,8 +54,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
54
54
 
55
55
  #{
56
56
  colored do
57
- red_line %(Expected: :foo)
58
- green_line %( Actual: :bar)
57
+ alpha_line %(Expected: :foo)
58
+ beta_line %( Actual: :bar)
59
59
  end
60
60
  }
61
61
  STR
@@ -84,8 +84,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
84
84
 
85
85
  #{
86
86
  colored do
87
- red_line %(Expected: "Marty")
88
- green_line %( Actual: "Jennifer")
87
+ alpha_line %(Expected: "Marty")
88
+ beta_line %( Actual: "Jennifer")
89
89
  end
90
90
  }
91
91
  STR
@@ -106,8 +106,52 @@ RSpec.describe SuperDiff::EqualityMatcher do
106
106
 
107
107
  #{
108
108
  colored do
109
- red_line %(Expected: "Marty")
110
- green_line %( Actual: "Marty McFly")
109
+ alpha_line %(Expected: "Marty")
110
+ beta_line %( Actual: "Marty McFly")
111
+ end
112
+ }
113
+ STR
114
+
115
+ expect(actual_output).to eq(expected_output)
116
+ end
117
+ end
118
+
119
+ context "given a single-line string and a multi-line string" do
120
+ it "returns a message along with the diff" do
121
+ actual_output = described_class.call(
122
+ expected: "Something entirely different",
123
+ actual: "This is a line\nAnd that's another line\n",
124
+ )
125
+
126
+ expected_output = <<~STR.strip
127
+ Differing strings.
128
+
129
+ #{
130
+ colored do
131
+ alpha_line %(Expected: "Something entirely different")
132
+ beta_line %( Actual: "This is a line\\nAnd that's another line\\n")
133
+ end
134
+ }
135
+ STR
136
+
137
+ expect(actual_output).to eq(expected_output)
138
+ end
139
+ end
140
+
141
+ context "given a multi-line string and a single-line string" do
142
+ it "returns a message along with the diff" do
143
+ actual_output = described_class.call(
144
+ expected: "This is a line\nAnd that's another line\n",
145
+ actual: "Something entirely different",
146
+ )
147
+
148
+ expected_output = <<~STR.strip
149
+ Differing strings.
150
+
151
+ #{
152
+ colored do
153
+ alpha_line %(Expected: "This is a line\\nAnd that's another line\\n")
154
+ beta_line %( Actual: "Something entirely different")
111
155
  end
112
156
  }
113
157
  STR
@@ -128,8 +172,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
128
172
 
129
173
  #{
130
174
  colored do
131
- red_line %(Expected: "This is a line⏎And that's a line⏎And there's a line too")
132
- green_line %( Actual: "This is a line⏎Something completely different⏎And there's a line too")
175
+ alpha_line %(Expected: "This is a line\\nAnd that's a line\\nAnd there's a line too")
176
+ beta_line %( Actual: "This is a line\\nSomething completely different\\nAnd there's a line too")
133
177
  end
134
178
  }
135
179
 
@@ -137,9 +181,9 @@ RSpec.describe SuperDiff::EqualityMatcher do
137
181
 
138
182
  #{
139
183
  colored do
140
- plain_line %( This is a line)
141
- red_line %(- And that's a line)
142
- green_line %(+ Something completely different)
184
+ plain_line %( This is a line\\n)
185
+ alpha_line %(- And that's a line\\n)
186
+ beta_line %(+ Something completely different\\n)
143
187
  plain_line %( And there's a line too)
144
188
  end
145
189
  }
@@ -161,8 +205,74 @@ RSpec.describe SuperDiff::EqualityMatcher do
161
205
 
162
206
  #{
163
207
  colored do
164
- red_line %(Expected: "This is a line⏎And that's a line")
165
- green_line %( Actual: "Something completely different⏎And something else too")
208
+ alpha_line %(Expected: "This is a line\\nAnd that's a line\\n")
209
+ beta_line %( Actual: "Something completely different\\nAnd something else too\\n")
210
+ end
211
+ }
212
+
213
+ Diff:
214
+
215
+ #{
216
+ colored do
217
+ alpha_line %(- This is a line\\n)
218
+ alpha_line %(- And that's a line\\n)
219
+ beta_line %(+ Something completely different\\n)
220
+ beta_line %(+ And something else too\\n)
221
+ end
222
+ }
223
+ STR
224
+
225
+ expect(actual_output).to eq(expected_output)
226
+ end
227
+ end
228
+
229
+ context "given multi-line strings that contain color codes" do
230
+ it "escapes the color codes" do
231
+ colors = [
232
+ SuperDiff::Csi::FourBitColor.new(:blue, layer: :foreground),
233
+ SuperDiff::Csi::EightBitColor.new(
234
+ red: 3,
235
+ green: 8,
236
+ blue: 4,
237
+ layer: :foreground,
238
+ ),
239
+ SuperDiff::Csi::TwentyFourBitColor.new(
240
+ red: 47,
241
+ green: 164,
242
+ blue: 59,
243
+ layer: :foreground,
244
+ ),
245
+ ]
246
+
247
+ expected =
248
+ colored("This is a line", colors[0]) + "\n" +
249
+ colored("And that's a line", colors[1]) + "\n" +
250
+ colored("And there's a line too", colors[2]) + "\n"
251
+
252
+ actual =
253
+ colored("This is a line", colors[0]) + "\n" +
254
+ colored("Something completely different", colors[1]) + "\n" +
255
+ colored("And there's a line too", colors[2]) + "\n"
256
+
257
+ actual_output = described_class.call(
258
+ expected: expected,
259
+ actual: actual,
260
+ )
261
+
262
+ expected_output = <<~STR.strip
263
+ Differing strings.
264
+
265
+ #{
266
+ colored do
267
+ alpha_line do
268
+ text "Expected: "
269
+ text %("\\e[34mThis is a line\\e[0m\\n\\e[38;5;176mAnd that's a line\\e[0m\\n\\e[38;2;47;59;164mAnd there's a line too\\e[0m\\n")
270
+ end
271
+
272
+ beta_line do
273
+ text " Actual: "
274
+ text %("\\e[34mThis is a line\\e[0m\\n\\e[38;5;176mSomething completely different\\e[0m\\n\\e[38;2;47;59;164mAnd there's a line too\\e[0m\\n")
275
+ end
166
276
  end
167
277
  }
168
278
 
@@ -170,10 +280,10 @@ RSpec.describe SuperDiff::EqualityMatcher do
170
280
 
171
281
  #{
172
282
  colored do
173
- red_line %(- This is a line)
174
- red_line %(- And that's a line)
175
- green_line %(+ Something completely different)
176
- green_line %(+ And something else too)
283
+ plain_line %( \\e[34mThis is a line\\e[0m\\n)
284
+ alpha_line %(- \\e[38;5;176mAnd that's a line\\e[0m\\n)
285
+ beta_line %(+ \\e[38;5;176mSomething completely different\\e[0m\\n)
286
+ plain_line %( \\e[38;2;47;59;164mAnd there's a line too\\e[0m\\n)
177
287
  end
178
288
  }
179
289
  STR
@@ -205,8 +315,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
205
315
 
206
316
  #{
207
317
  colored do
208
- red_line %(Expected: [1, 2, 3, 4])
209
- green_line %( Actual: [1, 2, 99, 4])
318
+ alpha_line %(Expected: [1, 2, 3, 4])
319
+ beta_line %( Actual: [1, 2, 99, 4])
210
320
  end
211
321
  }
212
322
 
@@ -217,8 +327,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
217
327
  plain_line %( [)
218
328
  plain_line %( 1,)
219
329
  plain_line %( 2,)
220
- red_line %(- 3,)
221
- green_line %(+ 99,)
330
+ alpha_line %(- 3,)
331
+ beta_line %(+ 99,)
222
332
  plain_line %( 4)
223
333
  plain_line %( ])
224
334
  end
@@ -241,8 +351,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
241
351
 
242
352
  #{
243
353
  colored do
244
- red_line %(Expected: [:one, :fish, :two, :fish])
245
- green_line %( Actual: [:one, :FISH, :two, :fish])
354
+ alpha_line %(Expected: [:one, :fish, :two, :fish])
355
+ beta_line %( Actual: [:one, :FISH, :two, :fish])
246
356
  end
247
357
  }
248
358
 
@@ -252,8 +362,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
252
362
  colored do
253
363
  plain_line %( [)
254
364
  plain_line %( :one,)
255
- red_line %(- :fish,)
256
- green_line %(+ :FISH,)
365
+ alpha_line %(- :fish,)
366
+ beta_line %(+ :FISH,)
257
367
  plain_line %( :two,)
258
368
  plain_line %( :fish)
259
369
  plain_line %( ])
@@ -277,8 +387,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
277
387
 
278
388
  #{
279
389
  colored do
280
- red_line %(Expected: ["sausage", "egg", "cheese"])
281
- green_line %( Actual: ["bacon", "egg", "cheese"])
390
+ alpha_line %(Expected: ["sausage", "egg", "cheese"])
391
+ beta_line %( Actual: ["bacon", "egg", "cheese"])
282
392
  end
283
393
  }
284
394
 
@@ -287,8 +397,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
287
397
  #{
288
398
  colored do
289
399
  plain_line %( [)
290
- red_line %(- "sausage",)
291
- green_line %(+ "bacon",)
400
+ alpha_line %(- "sausage",)
401
+ beta_line %(+ "bacon",)
292
402
  plain_line %( "egg",)
293
403
  plain_line %( "cheese")
294
404
  plain_line %( ])
@@ -304,18 +414,12 @@ RSpec.describe SuperDiff::EqualityMatcher do
304
414
  it "returns a message along with the diff" do
305
415
  actual_output = described_class.call(
306
416
  expected: [
307
- SuperDiff::Test::Person.new(name: "Marty"),
308
- SuperDiff::Test::Person.new(name: "Jennifer"),
417
+ SuperDiff::Test::Person.new(name: "Marty", age: 18),
418
+ SuperDiff::Test::Person.new(name: "Jennifer", age: 17),
309
419
  ],
310
420
  actual: [
311
- SuperDiff::Test::Person.new(name: "Marty"),
312
- SuperDiff::Test::Person.new(name: "Doc"),
313
- ],
314
- extra_operational_sequencer_classes: [
315
- SuperDiff::Test::PersonOperationalSequencer,
316
- ],
317
- extra_diff_formatter_classes: [
318
- SuperDiff::Test::PersonDiffFormatter,
421
+ SuperDiff::Test::Person.new(name: "Marty", age: 18),
422
+ SuperDiff::Test::Person.new(name: "Doc", age: 50),
319
423
  ],
320
424
  )
321
425
 
@@ -324,8 +428,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
324
428
 
325
429
  #{
326
430
  colored do
327
- red_line %(Expected: [#<SuperDiff::Test::Person name: "Marty">, #<SuperDiff::Test::Person name: "Jennifer">])
328
- green_line %( Actual: [#<SuperDiff::Test::Person name: "Marty">, #<SuperDiff::Test::Person name: "Doc">])
431
+ alpha_line %(Expected: [#<SuperDiff::Test::Person name: "Marty", age: 18>, #<SuperDiff::Test::Person name: "Jennifer", age: 17>])
432
+ beta_line %( Actual: [#<SuperDiff::Test::Person name: "Marty", age: 18>, #<SuperDiff::Test::Person name: "Doc", age: 50>])
329
433
  end
330
434
  }
331
435
 
@@ -335,11 +439,14 @@ RSpec.describe SuperDiff::EqualityMatcher do
335
439
  colored do
336
440
  plain_line %( [)
337
441
  plain_line %( #<SuperDiff::Test::Person {)
338
- plain_line %( name: "Marty")
442
+ plain_line %( name: "Marty",)
443
+ plain_line %( age: 18)
339
444
  plain_line %( }>,)
340
445
  plain_line %( #<SuperDiff::Test::Person {)
341
- red_line %(- name: "Jennifer")
342
- green_line %(+ name: "Doc")
446
+ alpha_line %(- name: "Jennifer",)
447
+ beta_line %(+ name: "Doc",)
448
+ alpha_line %(- age: 17)
449
+ beta_line %(+ age: 50)
343
450
  plain_line %( }>)
344
451
  plain_line %( ])
345
452
  end
@@ -362,8 +469,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
362
469
 
363
470
  #{
364
471
  colored do
365
- red_line %(Expected: ["bread"])
366
- green_line %( Actual: ["bread", "eggs", "milk"])
472
+ alpha_line %(Expected: ["bread"])
473
+ beta_line %( Actual: ["bread", "eggs", "milk"])
367
474
  end
368
475
  }
369
476
 
@@ -373,8 +480,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
373
480
  colored do
374
481
  plain_line %( [)
375
482
  plain_line %( "bread",)
376
- green_line %(+ "eggs",)
377
- green_line %(+ "milk")
483
+ beta_line %(+ "eggs",)
484
+ beta_line %(+ "milk")
378
485
  plain_line %( ])
379
486
  end
380
487
  }
@@ -396,8 +503,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
396
503
 
397
504
  #{
398
505
  colored do
399
- red_line %(Expected: ["bread", "eggs", "milk"])
400
- green_line %( Actual: ["bread"])
506
+ alpha_line %(Expected: ["bread", "eggs", "milk"])
507
+ beta_line %( Actual: ["bread"])
401
508
  end
402
509
  }
403
510
 
@@ -407,8 +514,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
407
514
  colored do
408
515
  plain_line %( [)
409
516
  plain_line %( "bread")
410
- red_line %(- "eggs",)
411
- red_line %(- "milk")
517
+ alpha_line %(- "eggs",)
518
+ alpha_line %(- "milk")
412
519
  plain_line %( ])
413
520
  end
414
521
  }
@@ -430,8 +537,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
430
537
 
431
538
  #{
432
539
  colored do
433
- red_line %(Expected: ["milk"])
434
- green_line %( Actual: ["bread", "eggs", "milk"])
540
+ alpha_line %(Expected: ["milk"])
541
+ beta_line %( Actual: ["bread", "eggs", "milk"])
435
542
  end
436
543
  }
437
544
 
@@ -440,8 +547,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
440
547
  #{
441
548
  colored do
442
549
  plain_line %( [)
443
- green_line %(+ "bread",)
444
- green_line %(+ "eggs",)
550
+ beta_line %(+ "bread",)
551
+ beta_line %(+ "eggs",)
445
552
  plain_line %( "milk")
446
553
  plain_line %( ])
447
554
  end
@@ -464,8 +571,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
464
571
 
465
572
  #{
466
573
  colored do
467
- red_line %(Expected: ["bread", "eggs", "milk"])
468
- green_line %( Actual: ["milk"])
574
+ alpha_line %(Expected: ["bread", "eggs", "milk"])
575
+ beta_line %( Actual: ["milk"])
469
576
  end
470
577
  }
471
578
 
@@ -474,8 +581,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
474
581
  #{
475
582
  colored do
476
583
  plain_line %( [)
477
- red_line %(- "bread",)
478
- red_line %(- "eggs",)
584
+ alpha_line %(- "bread",)
585
+ alpha_line %(- "eggs",)
479
586
  plain_line %( "milk")
480
587
  plain_line %( ])
481
588
  end
@@ -498,8 +605,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
498
605
 
499
606
  #{
500
607
  colored do
501
- red_line %(Expected: [1, 2, [:a, :b, :c], 4])
502
- green_line %( Actual: [1, 2, [:a, :x, :c], 4])
608
+ alpha_line %(Expected: [1, 2, [:a, :b, :c], 4])
609
+ beta_line %( Actual: [1, 2, [:a, :x, :c], 4])
503
610
  end
504
611
  }
505
612
 
@@ -512,8 +619,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
512
619
  plain_line %( 2,)
513
620
  plain_line %( [)
514
621
  plain_line %( :a,)
515
- red_line %(- :b,)
516
- green_line %(+ :x,)
622
+ alpha_line %(- :b,)
623
+ beta_line %(+ :x,)
517
624
  plain_line %( :c)
518
625
  plain_line %( ],)
519
626
  plain_line %( 4)
@@ -538,8 +645,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
538
645
 
539
646
  #{
540
647
  colored do
541
- red_line %(Expected: [1, 2, { foo: "bar", baz: "qux" }, 4])
542
- green_line %( Actual: [1, 2, { foo: "bar", baz: "qox" }, 4])
648
+ alpha_line %(Expected: [1, 2, { foo: "bar", baz: "qux" }, 4])
649
+ beta_line %( Actual: [1, 2, { foo: "bar", baz: "qox" }, 4])
543
650
  end
544
651
  }
545
652
 
@@ -552,8 +659,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
552
659
  plain_line %( 2,)
553
660
  plain_line %( {)
554
661
  plain_line %( foo: "bar",)
555
- red_line %(- baz: "qux")
556
- green_line %(+ baz: "qox")
662
+ alpha_line %(- baz: "qux")
663
+ beta_line %(+ baz: "qox")
557
664
  plain_line %( },)
558
665
  plain_line %( 4)
559
666
  plain_line %( ])
@@ -568,14 +675,13 @@ RSpec.describe SuperDiff::EqualityMatcher do
568
675
  context "given two arrays containing custom objects with differing attributes" do
569
676
  it "returns a message along with the diff" do
570
677
  actual_output = described_class.call(
571
- expected: [1, 2, SuperDiff::Test::Person.new(name: "Marty"), 4],
572
- actual: [1, 2, SuperDiff::Test::Person.new(name: "Doc"), 4],
573
- extra_operational_sequencer_classes: [
574
- SuperDiff::Test::PersonOperationalSequencer,
575
- ],
576
- extra_diff_formatter_classes: [
577
- SuperDiff::Test::PersonDiffFormatter,
678
+ expected: [
679
+ 1,
680
+ 2,
681
+ SuperDiff::Test::Person.new(name: "Marty", age: 18),
682
+ 4,
578
683
  ],
684
+ actual: [1, 2, SuperDiff::Test::Person.new(name: "Doc", age: 50), 4],
579
685
  )
580
686
 
581
687
  expected_output = <<~STR.strip
@@ -583,8 +689,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
583
689
 
584
690
  #{
585
691
  colored do
586
- red_line %(Expected: [1, 2, #<SuperDiff::Test::Person name: "Marty">, 4])
587
- green_line %( Actual: [1, 2, #<SuperDiff::Test::Person name: "Doc">, 4])
692
+ alpha_line %(Expected: [1, 2, #<SuperDiff::Test::Person name: "Marty", age: 18>, 4])
693
+ beta_line %( Actual: [1, 2, #<SuperDiff::Test::Person name: "Doc", age: 50>, 4])
588
694
  end
589
695
  }
590
696
 
@@ -596,8 +702,10 @@ RSpec.describe SuperDiff::EqualityMatcher do
596
702
  plain_line %( 1,)
597
703
  plain_line %( 2,)
598
704
  plain_line %( #<SuperDiff::Test::Person {)
599
- red_line %(- name: "Marty")
600
- green_line %(+ name: "Doc")
705
+ alpha_line %(- name: "Marty",)
706
+ beta_line %(+ name: "Doc",)
707
+ alpha_line %(- age: 18)
708
+ beta_line %(+ age: 50)
601
709
  plain_line %( }>,)
602
710
  plain_line %( 4)
603
711
  plain_line %( ])
@@ -641,8 +749,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
641
749
 
642
750
  #{
643
751
  colored do
644
- red_line %(Expected: [[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true } }]])
645
- green_line %( Actual: [[:h2, [:span, [:text, "Goodbye world"]], { id: "hero", class: "header", data: { "sticky" => false, role: "deprecated" } }], :br])
752
+ alpha_line %(Expected: [[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true } }]])
753
+ beta_line %( Actual: [[:h2, [:span, [:text, "Goodbye world"]], { id: "hero", class: "header", data: { "sticky" => false, :role => "deprecated" } }], :br])
646
754
  end
647
755
  }
648
756
 
@@ -652,27 +760,27 @@ RSpec.describe SuperDiff::EqualityMatcher do
652
760
  colored do
653
761
  plain_line %( [)
654
762
  plain_line %( [)
655
- red_line %(- :h1,)
656
- green_line %(+ :h2,)
763
+ alpha_line %(- :h1,)
764
+ beta_line %(+ :h2,)
657
765
  plain_line %( [)
658
766
  plain_line %( :span,)
659
767
  plain_line %( [)
660
768
  plain_line %( :text,)
661
- red_line %(- "Hello world")
662
- green_line %(+ "Goodbye world")
769
+ alpha_line %(- "Hello world")
770
+ beta_line %(+ "Goodbye world")
663
771
  plain_line %( ])
664
772
  plain_line %( ],)
665
773
  plain_line %( {)
774
+ beta_line %(+ id: "hero",)
666
775
  plain_line %( class: "header",)
667
776
  plain_line %( data: {)
668
- red_line %(- "sticky" => true)
669
- green_line %(+ "sticky" => false,)
670
- green_line %(+ role: "deprecated")
671
- plain_line %( },)
672
- green_line %(+ id: "hero")
777
+ alpha_line %(- "sticky" => true)
778
+ beta_line %(+ "sticky" => false,)
779
+ beta_line %(+ role: "deprecated")
780
+ plain_line %( })
673
781
  plain_line %( })
674
782
  plain_line %( ],)
675
- green_line %(+ :br)
783
+ beta_line %(+ :br)
676
784
  plain_line %( ])
677
785
  end
678
786
  }
@@ -705,8 +813,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
705
813
 
706
814
  #{
707
815
  colored do
708
- red_line %(Expected: { tall: 12, grande: 19, venti: 20 })
709
- green_line %( Actual: { tall: 12, grande: 16, venti: 20 })
816
+ alpha_line %(Expected: { tall: 12, grande: 19, venti: 20 })
817
+ beta_line %( Actual: { tall: 12, grande: 16, venti: 20 })
710
818
  end
711
819
  }
712
820
 
@@ -716,8 +824,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
716
824
  colored do
717
825
  plain_line %( {)
718
826
  plain_line %( tall: 12,)
719
- red_line %(- grande: 19,)
720
- green_line %(+ grande: 16,)
827
+ alpha_line %(- grande: 19,)
828
+ beta_line %(+ grande: 16,)
721
829
  plain_line %( venti: 20)
722
830
  plain_line %( })
723
831
  end
@@ -740,8 +848,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
740
848
 
741
849
  #{
742
850
  colored do
743
- red_line %(Expected: { "tall" => 12, "grande" => 19, "venti" => 20 })
744
- green_line %( Actual: { "tall" => 12, "grande" => 16, "venti" => 20 })
851
+ alpha_line %(Expected: { "tall" => 12, "grande" => 19, "venti" => 20 })
852
+ beta_line %( Actual: { "tall" => 12, "grande" => 16, "venti" => 20 })
745
853
  end
746
854
  }
747
855
 
@@ -751,8 +859,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
751
859
  colored do
752
860
  plain_line %( {)
753
861
  plain_line %( "tall" => 12,)
754
- red_line %(- "grande" => 19,)
755
- green_line %(+ "grande" => 16,)
862
+ alpha_line %(- "grande" => 19,)
863
+ beta_line %(+ "grande" => 16,)
756
864
  plain_line %( "venti" => 20)
757
865
  plain_line %( })
758
866
  end
@@ -775,8 +883,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
775
883
 
776
884
  #{
777
885
  colored do
778
- red_line %(Expected: { tall: :small, grande: :grand, venti: :large })
779
- green_line %( Actual: { tall: :small, grande: :medium, venti: :large })
886
+ alpha_line %(Expected: { tall: :small, grande: :grand, venti: :large })
887
+ beta_line %( Actual: { tall: :small, grande: :medium, venti: :large })
780
888
  end
781
889
  }
782
890
 
@@ -786,8 +894,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
786
894
  colored do
787
895
  plain_line %( {)
788
896
  plain_line %( tall: :small,)
789
- red_line %(- grande: :grand,)
790
- green_line %(+ grande: :medium,)
897
+ alpha_line %(- grande: :grand,)
898
+ beta_line %(+ grande: :medium,)
791
899
  plain_line %( venti: :large)
792
900
  plain_line %( })
793
901
  end
@@ -810,8 +918,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
810
918
 
811
919
  #{
812
920
  colored do
813
- red_line %(Expected: { tall: "small", grande: "grand", venti: "large" })
814
- green_line %( Actual: { tall: "small", grande: "medium", venti: "large" })
921
+ alpha_line %(Expected: { tall: "small", grande: "grand", venti: "large" })
922
+ beta_line %( Actual: { tall: "small", grande: "medium", venti: "large" })
815
923
  end
816
924
  }
817
925
 
@@ -821,8 +929,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
821
929
  colored do
822
930
  plain_line %( {)
823
931
  plain_line %( tall: "small",)
824
- red_line %(- grande: "grand",)
825
- green_line %(+ grande: "medium",)
932
+ alpha_line %(- grande: "grand",)
933
+ beta_line %(+ grande: "medium",)
826
934
  plain_line %( venti: "large")
827
935
  plain_line %( })
828
936
  end
@@ -837,19 +945,13 @@ RSpec.describe SuperDiff::EqualityMatcher do
837
945
  it "returns a message along with the diff" do
838
946
  actual_output = described_class.call(
839
947
  expected: {
840
- steve: SuperDiff::Test::Person.new(name: "Jobs"),
841
- susan: SuperDiff::Test::Person.new(name: "Kare"),
948
+ steve: SuperDiff::Test::Person.new(name: "Jobs", age: 30),
949
+ susan: SuperDiff::Test::Person.new(name: "Kare", age: 27),
842
950
  },
843
951
  actual: {
844
- steve: SuperDiff::Test::Person.new(name: "Wozniak"),
845
- susan: SuperDiff::Test::Person.new(name: "Kare"),
952
+ steve: SuperDiff::Test::Person.new(name: "Wozniak", age: 33),
953
+ susan: SuperDiff::Test::Person.new(name: "Kare", age: 27),
846
954
  },
847
- extra_operational_sequencer_classes: [
848
- SuperDiff::Test::PersonOperationalSequencer,
849
- ],
850
- extra_diff_formatter_classes: [
851
- SuperDiff::Test::PersonDiffFormatter,
852
- ],
853
955
  )
854
956
 
855
957
  expected_output = <<~STR.strip
@@ -857,8 +959,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
857
959
 
858
960
  #{
859
961
  colored do
860
- red_line %(Expected: { steve: #<SuperDiff::Test::Person name: "Jobs">, susan: #<SuperDiff::Test::Person name: "Kare"> })
861
- green_line %( Actual: { steve: #<SuperDiff::Test::Person name: "Wozniak">, susan: #<SuperDiff::Test::Person name: "Kare"> })
962
+ alpha_line %(Expected: { steve: #<SuperDiff::Test::Person name: "Jobs", age: 30>, susan: #<SuperDiff::Test::Person name: "Kare", age: 27> })
963
+ beta_line %( Actual: { steve: #<SuperDiff::Test::Person name: "Wozniak", age: 33>, susan: #<SuperDiff::Test::Person name: "Kare", age: 27> })
862
964
  end
863
965
  }
864
966
 
@@ -868,11 +970,14 @@ RSpec.describe SuperDiff::EqualityMatcher do
868
970
  colored do
869
971
  plain_line %( {)
870
972
  plain_line %( steve: #<SuperDiff::Test::Person {)
871
- red_line %(- name: "Jobs")
872
- green_line %(+ name: "Wozniak")
973
+ alpha_line %(- name: "Jobs",)
974
+ beta_line %(+ name: "Wozniak",)
975
+ alpha_line %(- age: 30)
976
+ beta_line %(+ age: 33)
873
977
  plain_line %( }>,)
874
978
  plain_line %( susan: #<SuperDiff::Test::Person {)
875
- plain_line %( name: "Kare")
979
+ plain_line %( name: "Kare",)
980
+ plain_line %( age: 27)
876
981
  plain_line %( }>)
877
982
  plain_line %( })
878
983
  end
@@ -895,8 +1000,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
895
1000
 
896
1001
  #{
897
1002
  colored do
898
- red_line %(Expected: { latte: 4.5 })
899
- green_line %( Actual: { latte: 4.5, mocha: 3.5, cortado: 3 })
1003
+ alpha_line %(Expected: { latte: 4.5 })
1004
+ beta_line %( Actual: { latte: 4.5, mocha: 3.5, cortado: 3 })
900
1005
  end
901
1006
  }
902
1007
 
@@ -906,8 +1011,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
906
1011
  colored do
907
1012
  plain_line %( {)
908
1013
  plain_line %( latte: 4.5,)
909
- green_line %(+ mocha: 3.5,)
910
- green_line %(+ cortado: 3)
1014
+ beta_line %(+ mocha: 3.5,)
1015
+ beta_line %(+ cortado: 3)
911
1016
  plain_line %( })
912
1017
  end
913
1018
  }
@@ -929,8 +1034,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
929
1034
 
930
1035
  #{
931
1036
  colored do
932
- red_line %(Expected: { latte: 4.5, mocha: 3.5, cortado: 3 })
933
- green_line %( Actual: { latte: 4.5 })
1037
+ alpha_line %(Expected: { latte: 4.5, mocha: 3.5, cortado: 3 })
1038
+ beta_line %( Actual: { latte: 4.5 })
934
1039
  end
935
1040
  }
936
1041
 
@@ -940,8 +1045,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
940
1045
  colored do
941
1046
  plain_line %( {)
942
1047
  plain_line %( latte: 4.5)
943
- red_line %(- mocha: 3.5,)
944
- red_line %(- cortado: 3)
1048
+ alpha_line %(- mocha: 3.5,)
1049
+ alpha_line %(- cortado: 3)
945
1050
  plain_line %( })
946
1051
  end
947
1052
  }
@@ -971,8 +1076,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
971
1076
 
972
1077
  #{
973
1078
  colored do
974
- red_line %(Expected: { name: "Elliot", interests: ["music", "football", "programming"], age: 30 })
975
- green_line %( Actual: { name: "Elliot", interests: ["music", "travel", "programming"], age: 30 })
1079
+ alpha_line %(Expected: { name: "Elliot", interests: ["music", "football", "programming"], age: 30 })
1080
+ beta_line %( Actual: { name: "Elliot", interests: ["music", "travel", "programming"], age: 30 })
976
1081
  end
977
1082
  }
978
1083
 
@@ -984,8 +1089,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
984
1089
  plain_line %( name: "Elliot",)
985
1090
  plain_line %( interests: [)
986
1091
  plain_line %( "music",)
987
- red_line %(- "football",)
988
- green_line %(+ "travel",)
1092
+ alpha_line %(- "football",)
1093
+ beta_line %(+ "travel",)
989
1094
  plain_line %( "programming")
990
1095
  plain_line %( ],)
991
1096
  plain_line %( age: 30)
@@ -1026,8 +1131,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
1026
1131
 
1027
1132
  #{
1028
1133
  colored do
1029
- red_line %(Expected: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Buns, ribs, and bacon", "YMMV" => "Your mileage may vary" }, check_grammar: false })
1030
- green_line %( Actual: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Be right back", "YMMV" => "Your mileage may vary" }, check_grammar: false })
1134
+ alpha_line %(Expected: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Buns, ribs, and bacon", "YMMV" => "Your mileage may vary" }, check_grammar: false })
1135
+ beta_line %( Actual: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Be right back", "YMMV" => "Your mileage may vary" }, check_grammar: false })
1031
1136
  end
1032
1137
  }
1033
1138
 
@@ -1039,8 +1144,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
1039
1144
  plain_line %( check_spelling: true,)
1040
1145
  plain_line %( substitutions: {)
1041
1146
  plain_line %( "YOLO" => "You only live once",)
1042
- red_line %(- "BRB" => "Buns, ribs, and bacon",)
1043
- green_line %(+ "BRB" => "Be right back",)
1147
+ alpha_line %(- "BRB" => "Buns, ribs, and bacon",)
1148
+ beta_line %(+ "BRB" => "Be right back",)
1044
1149
  plain_line %( "YMMV" => "Your mileage may vary")
1045
1150
  plain_line %( },)
1046
1151
  plain_line %( check_grammar: false)
@@ -1058,20 +1163,14 @@ RSpec.describe SuperDiff::EqualityMatcher do
1058
1163
  actual_output = described_class.call(
1059
1164
  expected: {
1060
1165
  order_id: 1234,
1061
- person: SuperDiff::Test::Person.new(name: "Marty"),
1166
+ person: SuperDiff::Test::Person.new(name: "Marty", age: 18),
1062
1167
  amount: 350_00,
1063
1168
  },
1064
1169
  actual: {
1065
1170
  order_id: 1234,
1066
- person: SuperDiff::Test::Person.new(name: "Doc"),
1171
+ person: SuperDiff::Test::Person.new(name: "Doc", age: 50),
1067
1172
  amount: 350_00,
1068
1173
  },
1069
- extra_operational_sequencer_classes: [
1070
- SuperDiff::Test::PersonOperationalSequencer,
1071
- ],
1072
- extra_diff_formatter_classes: [
1073
- SuperDiff::Test::PersonDiffFormatter,
1074
- ],
1075
1174
  )
1076
1175
 
1077
1176
  expected_output = <<~STR.strip
@@ -1079,8 +1178,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
1079
1178
 
1080
1179
  #{
1081
1180
  colored do
1082
- red_line %(Expected: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Marty">, amount: 35000 })
1083
- green_line %( Actual: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Doc">, amount: 35000 })
1181
+ alpha_line %(Expected: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Marty", age: 18>, amount: 35000 })
1182
+ beta_line %( Actual: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Doc", age: 50>, amount: 35000 })
1084
1183
  end
1085
1184
  }
1086
1185
 
@@ -1091,8 +1190,10 @@ RSpec.describe SuperDiff::EqualityMatcher do
1091
1190
  plain_line %( {)
1092
1191
  plain_line %( order_id: 1234,)
1093
1192
  plain_line %( person: #<SuperDiff::Test::Person {)
1094
- red_line %(- name: "Marty")
1095
- green_line %(+ name: "Doc")
1193
+ alpha_line %(- name: "Marty",)
1194
+ beta_line %(+ name: "Doc",)
1195
+ alpha_line %(- age: 18)
1196
+ beta_line %(+ age: 50)
1096
1197
  plain_line %( }>,)
1097
1198
  plain_line %( amount: 35000)
1098
1199
  plain_line %( })
@@ -1152,8 +1253,8 @@ RSpec.describe SuperDiff::EqualityMatcher do
1152
1253
 
1153
1254
  #{
1154
1255
  colored do
1155
- red_line %(Expected: { customer: { name: "Marty McFly", shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] })
1156
- green_line %( Actual: { customer: { name: "Marty McFly, Jr.", shipping_address: { line_1: "456 Ponderosa Ct.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Mattel Hoverboard" }] })
1256
+ alpha_line %(Expected: { customer: { name: "Marty McFly", shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] })
1257
+ beta_line %( Actual: { customer: { name: "Marty McFly, Jr.", shipping_address: { line_1: "456 Ponderosa Ct.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Mattel Hoverboard" }] })
1157
1258
  end
1158
1259
  }
1159
1260
 
@@ -1163,11 +1264,11 @@ RSpec.describe SuperDiff::EqualityMatcher do
1163
1264
  colored do
1164
1265
  plain_line %( {)
1165
1266
  plain_line %( customer: {)
1166
- red_line %(- name: "Marty McFly",)
1167
- green_line %(+ name: "Marty McFly, Jr.",)
1267
+ alpha_line %(- name: "Marty McFly",)
1268
+ beta_line %(+ name: "Marty McFly, Jr.",)
1168
1269
  plain_line %( shipping_address: {)
1169
- red_line %(- line_1: "123 Main St.",)
1170
- green_line %(+ line_1: "456 Ponderosa Ct.",)
1270
+ alpha_line %(- line_1: "123 Main St.",)
1271
+ beta_line %(+ line_1: "456 Ponderosa Ct.",)
1171
1272
  plain_line %( city: "Hill Valley",)
1172
1273
  plain_line %( state: "CA",)
1173
1274
  plain_line %( zip: "90382")
@@ -1177,11 +1278,15 @@ RSpec.describe SuperDiff::EqualityMatcher do
1177
1278
  plain_line %( {)
1178
1279
  plain_line %( name: "Fender Stratocaster",)
1179
1280
  plain_line %( cost: 100000,)
1180
- plain_line %( options: ["red", "blue", "green"])
1281
+ plain_line %( options: [)
1282
+ plain_line %( "red",)
1283
+ plain_line %( "blue",)
1284
+ plain_line %( "green")
1285
+ plain_line %( ])
1181
1286
  plain_line %( },)
1182
1287
  plain_line %( {)
1183
- red_line %(- name: "Chevy 4x4")
1184
- green_line %(+ name: "Mattel Hoverboard")
1288
+ alpha_line %(- name: "Chevy 4x4")
1289
+ beta_line %(+ name: "Mattel Hoverboard")
1185
1290
  plain_line %( })
1186
1291
  plain_line %( ])
1187
1292
  plain_line %( })
@@ -1193,10 +1298,10 @@ RSpec.describe SuperDiff::EqualityMatcher do
1193
1298
  end
1194
1299
  end
1195
1300
 
1196
- context "given two objects which == each other" do
1301
+ context "given two custom objects which == each other" do
1197
1302
  it "returns an empty string" do
1198
- expected = SuperDiff::Test::Person.new(name: "Marty")
1199
- actual = SuperDiff::Test::Person.new(name: "Marty")
1303
+ expected = SuperDiff::Test::Person.new(name: "Marty", age: 18)
1304
+ actual = SuperDiff::Test::Person.new(name: "Marty", age: 18)
1200
1305
 
1201
1306
  output = described_class.call(expected: expected, actual: actual)
1202
1307
 
@@ -1204,10 +1309,121 @@ RSpec.describe SuperDiff::EqualityMatcher do
1204
1309
  end
1205
1310
  end
1206
1311
 
1207
- context "given two objects which do not == each other" do
1312
+ context "given two different versions of the same custom class" do
1208
1313
  it "returns a message along with a comparison" do
1209
- expected = SuperDiff::Test::Person.new(name: "Marty")
1210
- actual = SuperDiff::Test::Person.new(name: "Doc")
1314
+ expected = SuperDiff::Test::Person.new(name: "Marty", age: 18)
1315
+ actual = SuperDiff::Test::Person.new(name: "Doc", age: 50)
1316
+
1317
+ actual_output = described_class.call(
1318
+ expected: expected,
1319
+ actual: actual,
1320
+ )
1321
+
1322
+ expected_output = <<~STR.strip
1323
+ Differing objects.
1324
+
1325
+ #{
1326
+ colored do
1327
+ alpha_line %(Expected: #<SuperDiff::Test::Person name: "Marty", age: 18>)
1328
+ beta_line %( Actual: #<SuperDiff::Test::Person name: "Doc", age: 50>)
1329
+ end
1330
+ }
1331
+
1332
+ Diff:
1333
+
1334
+ #{
1335
+ colored do
1336
+ plain_line %( #<SuperDiff::Test::Person {)
1337
+ alpha_line %(- name: "Marty",)
1338
+ beta_line %(+ name: "Doc",)
1339
+ alpha_line %(- age: 18)
1340
+ beta_line %(+ age: 50)
1341
+ plain_line %( }>)
1342
+ end
1343
+ }
1344
+ STR
1345
+
1346
+ expect(actual_output).to eq(expected_output)
1347
+ end
1348
+ end
1349
+
1350
+ context "given two different versions of the same non-custom class" do
1351
+ it "returns a message along with the diff" do
1352
+ expected = SuperDiff::Test::Player.new(
1353
+ handle: "martymcfly",
1354
+ character: "mirage",
1355
+ inventory: ["flatline", "purple body shield"],
1356
+ shields: 0.6,
1357
+ health: 0.3,
1358
+ ultimate: 0.8,
1359
+ )
1360
+ actual = SuperDiff::Test::Player.new(
1361
+ handle: "docbrown",
1362
+ character: "lifeline",
1363
+ inventory: ["wingman", "mastiff"],
1364
+ shields: 0.6,
1365
+ health: 0.3,
1366
+ ultimate: 0.8,
1367
+ )
1368
+
1369
+ actual_output = described_class.call(expected: expected, actual: actual)
1370
+
1371
+ expected_output = <<~STR.strip
1372
+ Differing objects.
1373
+
1374
+ #{
1375
+ if SuperDiff::Test.jruby?
1376
+ # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
1377
+ colored do
1378
+ alpha_line %(Expected: #<SuperDiff::Test::Player:#{"0x%x" % expected.hash} @inventory=["flatline", "purple body shield"], @character="mirage", @handle="martymcfly", @ultimate=0.8, @shields=0.6, @health=0.3>)
1379
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%x" % actual.hash} @inventory=["wingman", "mastiff"], @character="lifeline", @handle="docbrown", @ultimate=0.8, @shields=0.6, @health=0.3>)
1380
+ end
1381
+ else
1382
+ colored do
1383
+ alpha_line %(Expected: #<SuperDiff::Test::Player:#{"0x%016x" % (expected.object_id * 2)} @handle="martymcfly", @character="mirage", @inventory=["flatline", "purple body shield"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1384
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%016x" % (actual.object_id * 2)} @handle="docbrown", @character="lifeline", @inventory=["wingman", "mastiff"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1385
+ end
1386
+ end
1387
+ }
1388
+
1389
+ Diff:
1390
+
1391
+ #{
1392
+ colored do
1393
+ plain_line %( #<SuperDiff::Test::Player {)
1394
+ alpha_line %(- @character="mirage",)
1395
+ beta_line %(+ @character="lifeline",)
1396
+ alpha_line %(- @handle="martymcfly",)
1397
+ beta_line %(+ @handle="docbrown",)
1398
+ plain_line %( @health=0.3,)
1399
+ plain_line %( @inventory=[)
1400
+ alpha_line %(- "flatline",)
1401
+ beta_line %(+ "wingman",)
1402
+ alpha_line %(- "purple body shield")
1403
+ beta_line %(+ "mastiff")
1404
+ plain_line %( ],)
1405
+ plain_line %( @shields=0.6,)
1406
+ plain_line %( @ultimate=0.8)
1407
+ plain_line %( }>)
1408
+ end
1409
+ }
1410
+ STR
1411
+
1412
+ expect(actual_output).to eq(expected_output)
1413
+ end
1414
+ end
1415
+
1416
+ context "given two completely different kinds of custom objects" do
1417
+ it "returns a message along with the diff" do
1418
+ expected = SuperDiff::Test::Person.new(
1419
+ name: "Marty",
1420
+ age: 31,
1421
+ )
1422
+ actual = SuperDiff::Test::Customer.new(
1423
+ name: "Doc",
1424
+ shipping_address: :some_shipping_address,
1425
+ phone: "1234567890",
1426
+ )
1211
1427
 
1212
1428
  actual_output = described_class.call(expected: expected, actual: actual)
1213
1429
 
@@ -1216,8 +1432,200 @@ RSpec.describe SuperDiff::EqualityMatcher do
1216
1432
 
1217
1433
  #{
1218
1434
  colored do
1219
- red_line %(Expected: #<SuperDiff::Test::Person name: "Marty">)
1220
- green_line %( Actual: #<SuperDiff::Test::Person name: "Doc">)
1435
+ alpha_line %(Expected: #<SuperDiff::Test::Person name: "Marty", age: 31>)
1436
+ beta_line %( Actual: #<SuperDiff::Test::Customer name: "Doc", shipping_address: :some_shipping_address, phone: "1234567890">)
1437
+ end
1438
+ }
1439
+ STR
1440
+
1441
+ expect(actual_output).to eq(expected_output)
1442
+ end
1443
+ end
1444
+
1445
+ context "given two completely different kinds of non-custom objects" do
1446
+ it "returns a message along with the diff" do
1447
+ expected = SuperDiff::Test::Item.new(
1448
+ name: "camera",
1449
+ quantity: 3,
1450
+ )
1451
+ actual = SuperDiff::Test::Player.new(
1452
+ handle: "mcmire",
1453
+ character: "Jon",
1454
+ inventory: ["sword"],
1455
+ shields: 11.4,
1456
+ health: 4,
1457
+ ultimate: true,
1458
+ )
1459
+
1460
+ actual_output = described_class.call(expected: expected, actual: actual)
1461
+
1462
+ expected_output = <<~STR.strip
1463
+ Differing objects.
1464
+
1465
+ #{
1466
+ if SuperDiff::Test.jruby?
1467
+ # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
1468
+ colored do
1469
+ alpha_line %(Expected: #<SuperDiff::Test::Item:#{"0x%x" % expected.hash} @name="camera", @quantity=3>)
1470
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%x" % actual.hash} @inventory=["sword"], @character="Jon", @handle="mcmire", @ultimate=true, @shields=11.4, @health=4>)
1471
+ end
1472
+ else
1473
+ colored do
1474
+ alpha_line %(Expected: #<SuperDiff::Test::Item:#{"0x%016x" % (expected.object_id * 2)} @name="camera", @quantity=3>)
1475
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%016x" % (actual.object_id * 2)} @handle="mcmire", @character="Jon", @inventory=["sword"], @shields=11.4, @health=4, @ultimate=true>)
1476
+ end
1477
+ end
1478
+ }
1479
+ STR
1480
+
1481
+ expect(actual_output).to eq(expected_output)
1482
+ end
1483
+ end
1484
+
1485
+ context "when the expected value is a data structure that refers to itself somewhere inside of it" do
1486
+ it "replaces the reference with ∙∙∙" do
1487
+ expected = ["a", "b", "c"]
1488
+ expected.insert(1, expected)
1489
+ actual = ["a", "x", "b", "c"]
1490
+
1491
+ actual_output = described_class.call(expected: expected, actual: actual)
1492
+
1493
+ expected_output = <<~STR.strip
1494
+ Differing arrays.
1495
+
1496
+ #{
1497
+ colored do
1498
+ alpha_line %(Expected: ["a", ∙∙∙, "b", "c"])
1499
+ beta_line %( Actual: ["a", "x", "b", "c"])
1500
+ end
1501
+ }
1502
+
1503
+ Diff:
1504
+
1505
+ #{
1506
+ colored do
1507
+ plain_line %( [)
1508
+ plain_line %( "a",)
1509
+ alpha_line %(- ∙∙∙,)
1510
+ beta_line %(+ "x",)
1511
+ plain_line %( "b",)
1512
+ plain_line %( "c")
1513
+ plain_line %( ])
1514
+ end
1515
+ }
1516
+ STR
1517
+
1518
+ expect(actual_output).to eq(expected_output)
1519
+ end
1520
+ end
1521
+
1522
+ context "when the actual value is a data structure that refers to itself somewhere inside of it" do
1523
+ it "replaces the reference with ∙∙∙" do
1524
+ expected = ["a", "x", "b", "c"]
1525
+ actual = ["a", "b", "c"]
1526
+ actual.insert(1, actual)
1527
+
1528
+ actual_output = described_class.call(expected: expected, actual: actual)
1529
+
1530
+ expected_output = <<~STR.strip
1531
+ Differing arrays.
1532
+
1533
+ #{
1534
+ colored do
1535
+ alpha_line %(Expected: ["a", "x", "b", "c"])
1536
+ beta_line %( Actual: ["a", ∙∙∙, "b", "c"])
1537
+ end
1538
+ }
1539
+
1540
+ Diff:
1541
+
1542
+ #{
1543
+ colored do
1544
+ plain_line %( [)
1545
+ plain_line %( "a",)
1546
+ alpha_line %(- "x",)
1547
+ beta_line %(+ ∙∙∙,)
1548
+ plain_line %( "b",)
1549
+ plain_line %( "c")
1550
+ plain_line %( ])
1551
+ end
1552
+ }
1553
+ STR
1554
+
1555
+ expect(actual_output).to eq(expected_output)
1556
+ end
1557
+ end
1558
+
1559
+ context "when the data structure being different is present inside a secondary layer" do
1560
+ it "replaces the reference with ∙∙∙" do
1561
+ expected = { foo: ["a", "x", "b", "c"] }
1562
+ actual = { foo: ["a", "b", "c"] }
1563
+ actual[:foo].insert(1, actual)
1564
+
1565
+ actual_output = described_class.call(expected: expected, actual: actual)
1566
+
1567
+ expected_output = <<~STR.strip
1568
+ Differing hashes.
1569
+
1570
+ #{
1571
+ colored do
1572
+ alpha_line %(Expected: { foo: ["a", "x", "b", "c"] })
1573
+ beta_line %( Actual: { foo: ["a", ∙∙∙, "b", "c"] })
1574
+ end
1575
+ }
1576
+
1577
+ Diff:
1578
+
1579
+ #{
1580
+ colored do
1581
+ plain_line %( {)
1582
+ plain_line %( foo: [)
1583
+ plain_line %( "a",)
1584
+ alpha_line %(- "x",)
1585
+ beta_line %(+ ∙∙∙,)
1586
+ plain_line %( "b",)
1587
+ plain_line %( "c")
1588
+ plain_line %( ])
1589
+ plain_line %( })
1590
+ end
1591
+ }
1592
+ STR
1593
+
1594
+ expect(actual_output).to eq(expected_output)
1595
+ end
1596
+ end
1597
+
1598
+ context "when a secondary layer of a data structure refers to itself" do
1599
+ it "replaces the reference with ∙∙∙" do
1600
+ expected = { foo: ["a", "x", "b", "c"] }
1601
+ actual = { foo: ["a", "b", "c"] }
1602
+ actual[:foo].insert(1, actual[:foo])
1603
+
1604
+ actual_output = described_class.call(expected: expected, actual: actual)
1605
+
1606
+ expected_output = <<~STR.strip
1607
+ Differing hashes.
1608
+
1609
+ #{
1610
+ colored do
1611
+ alpha_line %(Expected: { foo: ["a", "x", "b", "c"] })
1612
+ beta_line %( Actual: { foo: ["a", ∙∙∙, "b", "c"] })
1613
+ end
1614
+ }
1615
+
1616
+ Diff:
1617
+
1618
+ #{
1619
+ colored do
1620
+ plain_line %( {)
1621
+ plain_line %( foo: [)
1622
+ plain_line %( "a",)
1623
+ alpha_line %(- "x",)
1624
+ beta_line %(+ ∙∙∙,)
1625
+ plain_line %( "b",)
1626
+ plain_line %( "c")
1627
+ plain_line %( ])
1628
+ plain_line %( })
1221
1629
  end
1222
1630
  }
1223
1631
  STR
@@ -1227,7 +1635,7 @@ RSpec.describe SuperDiff::EqualityMatcher do
1227
1635
  end
1228
1636
  end
1229
1637
 
1230
- def colored(&block)
1231
- SuperDiff::Tests::Colorizer.call(&block).chomp
1638
+ def colored(*args, **opts, &block)
1639
+ SuperDiff::Helpers.style(*args, **opts, &block).to_s.chomp
1232
1640
  end
1233
1641
  end