super_diff 0.6.2 → 0.9.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 (186) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
  4. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
  5. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
  7. data/lib/super_diff/active_record/object_inspection.rb +2 -6
  8. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
  9. data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
  10. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
  11. data/lib/super_diff/active_record.rb +7 -7
  12. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
  13. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
  14. data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
  15. data/lib/super_diff/active_support/object_inspection.rb +2 -6
  16. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
  17. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
  18. data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
  19. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
  20. data/lib/super_diff/active_support.rb +8 -8
  21. data/lib/super_diff/colorized_document_extensions.rb +9 -6
  22. data/lib/super_diff/configuration.rb +81 -8
  23. data/lib/super_diff/csi/four_bit_color.rb +0 -2
  24. data/lib/super_diff/csi.rb +1 -2
  25. data/lib/super_diff/differs/array.rb +1 -1
  26. data/lib/super_diff/differs/base.rb +3 -21
  27. data/lib/super_diff/differs/custom_object.rb +1 -1
  28. data/lib/super_diff/differs/default_object.rb +1 -1
  29. data/lib/super_diff/differs/hash.rb +1 -1
  30. data/lib/super_diff/differs/main.rb +1 -7
  31. data/lib/super_diff/differs/multiline_string.rb +1 -1
  32. data/lib/super_diff/differs/time_like.rb +1 -1
  33. data/lib/super_diff/equality_matchers/array.rb +2 -2
  34. data/lib/super_diff/equality_matchers/default.rb +2 -2
  35. data/lib/super_diff/equality_matchers/hash.rb +2 -2
  36. data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
  37. data/lib/super_diff/equality_matchers/primitive.rb +4 -7
  38. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  39. data/lib/super_diff/helpers.rb +56 -2
  40. data/lib/super_diff/line.rb +83 -0
  41. data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
  42. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
  43. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
  44. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
  45. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
  46. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
  47. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
  48. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
  49. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
  50. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
  51. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
  52. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
  53. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
  54. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
  55. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
  56. data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
  57. data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
  58. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
  59. data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
  60. data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
  61. data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
  62. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
  63. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
  64. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
  65. data/lib/super_diff/object_inspection/nodes.rb +33 -32
  66. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
  67. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
  68. data/lib/super_diff/object_inspection.rb +12 -1
  69. data/lib/super_diff/operation_tree_builders/array.rb +7 -10
  70. data/lib/super_diff/operation_tree_builders/base.rb +6 -6
  71. data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
  72. data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
  73. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  74. data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
  75. data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
  76. data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
  77. data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
  78. data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
  79. data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
  80. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
  81. data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
  82. data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
  83. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
  84. data/lib/super_diff/operation_tree_flatteners.rb +20 -0
  85. data/lib/super_diff/operation_trees/array.rb +4 -7
  86. data/lib/super_diff/operation_trees/base.rb +39 -16
  87. data/lib/super_diff/operation_trees/custom_object.rb +4 -8
  88. data/lib/super_diff/operation_trees/default_object.rb +28 -13
  89. data/lib/super_diff/operation_trees/hash.rb +4 -7
  90. data/lib/super_diff/operation_trees/main.rb +1 -1
  91. data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
  92. data/lib/super_diff/operations/binary_operation.rb +1 -6
  93. data/lib/super_diff/operations/unary_operation.rb +2 -30
  94. data/lib/super_diff/recursion_guard.rb +3 -3
  95. data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
  96. data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
  97. data/lib/super_diff/rspec/monkey_patches.rb +2 -2
  98. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
  99. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
  100. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
  101. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
  102. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
  103. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
  104. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
  105. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
  106. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
  107. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
  108. data/lib/super_diff/rspec/object_inspection.rb +4 -1
  109. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
  110. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
  111. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
  112. data/lib/super_diff/rspec.rb +34 -13
  113. data/lib/super_diff/tiered_lines.rb +4 -0
  114. data/lib/super_diff/tiered_lines_elider.rb +490 -0
  115. data/lib/super_diff/tiered_lines_formatter.rb +79 -0
  116. data/lib/super_diff/version.rb +1 -1
  117. data/lib/super_diff.rb +28 -6
  118. data/spec/examples.txt +482 -403
  119. data/spec/integration/rails/active_support_spec.rb +19 -0
  120. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
  121. data/spec/integration/rspec/eq_matcher_spec.rb +33 -87
  122. data/spec/integration/rspec/have_attributes_matcher_spec.rb +17 -8
  123. data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
  124. data/spec/integration/rspec/match_matcher_spec.rb +93 -5
  125. data/spec/spec_helper.rb +4 -1
  126. data/spec/support/command_runner.rb +15 -25
  127. data/spec/support/helpers.rb +21 -0
  128. data/spec/support/integration/helpers.rb +2 -0
  129. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
  130. data/spec/support/integration/test_programs/base.rb +36 -10
  131. data/spec/support/shared_examples/active_record.rb +3 -2
  132. data/spec/support/shared_examples/active_support.rb +65 -0
  133. data/spec/support/shared_examples/elided_diffs.rb +914 -0
  134. data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
  135. data/spec/support/unit/helpers.rb +15 -0
  136. data/spec/support/unit/matchers/match_output.rb +41 -0
  137. data/spec/tmp/warnings_logger/all_warnings.txt +2 -0
  138. data/spec/unit/active_record/object_inspection_spec.rb +273 -0
  139. data/spec/unit/equality_matchers/main_spec.rb +55 -75
  140. data/spec/unit/helpers_spec.rb +75 -0
  141. data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
  142. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
  143. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
  144. data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
  145. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
  146. data/spec/unit/rspec/object_inspection_spec.rb +446 -0
  147. data/spec/unit/super_diff_spec.rb +1530 -800
  148. data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
  149. data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
  150. metadata +91 -52
  151. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
  152. data/lib/super_diff/active_record/diff_formatters.rb +0 -10
  153. data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
  154. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
  155. data/lib/super_diff/active_support/diff_formatters.rb +0 -10
  156. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
  157. data/lib/super_diff/diff_formatters/array.rb +0 -21
  158. data/lib/super_diff/diff_formatters/base.rb +0 -33
  159. data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
  160. data/lib/super_diff/diff_formatters/default_object.rb +0 -46
  161. data/lib/super_diff/diff_formatters/defaults.rb +0 -10
  162. data/lib/super_diff/diff_formatters/hash.rb +0 -34
  163. data/lib/super_diff/diff_formatters/main.rb +0 -41
  164. data/lib/super_diff/diff_formatters.rb +0 -14
  165. data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
  166. data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
  167. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
  168. data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
  169. data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
  170. data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
  171. data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
  172. data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
  173. data/lib/super_diff/object_inspection/inspectors.rb +0 -23
  174. data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
  175. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
  176. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
  177. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
  178. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
  179. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
  180. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
  181. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
  182. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
  183. data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
  184. data/spec/combustion/Gemfile.lock +0 -173
  185. data/spec/support/object_id.rb +0 -27
  186. data/spec/support/ruby_versions.rb +0 -11
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Integration with ActiveSupport", type: :integration do
4
+ context "when using 'super_diff/rspec-rails'" do
5
+ include_context "integration with ActiveSupport"
6
+
7
+ def make_program(test, color_enabled:)
8
+ make_rspec_rails_test_program(test, color_enabled: color_enabled)
9
+ end
10
+ end
11
+
12
+ context "when using 'super_diff/active_support'" do
13
+ include_context "integration with ActiveSupport"
14
+
15
+ def make_program(test, color_enabled:)
16
+ make_rspec_active_record_program(test, color_enabled: color_enabled)
17
+ end
18
+ end
19
+ end
@@ -33,7 +33,8 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher", type: :integ
33
33
  plain_line %| "Marty",|
34
34
  actual_line %|+ "Jennifer",|
35
35
  actual_line %|+ "Doc",|
36
- expected_line %|- "Einie"|
36
+ # expected_line %|- "Einie"| # TODO
37
+ expected_line %|- "Einie",|
37
38
  plain_line %| ]|
38
39
  },
39
40
  )
@@ -132,7 +133,8 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher", type: :integ
132
133
  plain_line %| "Lorraine McFly",|
133
134
  actual_line %|+ "Einie",|
134
135
  expected_line %|- "Biff Tannen",|
135
- expected_line %|- "George McFly"|
136
+ # expected_line %|- "George McFly"| # TODO
137
+ expected_line %|- "George McFly",|
136
138
  plain_line %| ]|
137
139
  },
138
140
  )
@@ -243,7 +245,8 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher", type: :integ
243
245
  actual_line %|+ "Lorraine McFly",|
244
246
  expected_line %|- "Biff Tannen",|
245
247
  expected_line %|- /Georg McFly/,|
246
- expected_line %|- /Lorrain McFly/|
248
+ # expected_line %|- /Lorrain McFly/| # TODO
249
+ expected_line %|- /Lorrain McFly/,|
247
250
  plain_line %| ]|
248
251
  },
249
252
  )
@@ -330,7 +333,7 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher", type: :integ
330
333
  expectation: proc {
331
334
  line do
332
335
  plain %| Expected |
333
- actual %|[{ foo: "bar" }, #<Double (anonymous)>, { blargh: "riddle" }]|
336
+ actual %|[{ foo: "bar" }, #<Double (anonymous) baz: "qux">, { blargh: "riddle" }]|
334
337
  end
335
338
 
336
339
  line do
@@ -347,13 +350,16 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher", type: :integ
347
350
  plain_line %| {|
348
351
  plain_line %| foo: "bar"|
349
352
  plain_line %| },|
350
- plain_line %| #<Double (anonymous)>,|
353
+ plain_line %| #<Double (anonymous) {|
354
+ plain_line %| baz: "qux"|
355
+ plain_line %| }>,|
351
356
  actual_line %|+ {|
352
357
  actual_line %|+ blargh: "riddle"|
353
358
  actual_line %|+ },|
354
359
  expected_line %|- #<a collection containing exactly (|
355
360
  expected_line %|- "zing"|
356
- expected_line %|- )>|
361
+ # expected_line %|- )>| # TODO
362
+ expected_line %|- )>,|
357
363
  plain_line %| ]|
358
364
  },
359
365
  )
@@ -188,10 +188,12 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
188
188
  expectation: proc {
189
189
  line do
190
190
  plain %|Expected |
191
- actual %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
192
- plain %| to eq |
193
- expected %|2011-12-13 14:15:16.500 UTC +00:00 (Time)|
194
- plain %|.|
191
+ actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
192
+ end
193
+
194
+ line do
195
+ plain %| to eq |
196
+ expected %|#<Time 2011-12-13 14:15:16+(1/2) +00:00 (UTC)>|
195
197
  end
196
198
  },
197
199
  diff: proc {
@@ -202,10 +204,10 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
202
204
  plain_line " hour: 14,"
203
205
  plain_line " min: 15,"
204
206
  plain_line " sec: 16,"
205
- expected_line "- nsec: 500000000,"
206
- actual_line "+ nsec: 0,"
207
+ expected_line "- subsec: (1/2),"
208
+ actual_line "+ subsec: 0,"
207
209
  plain_line " zone: \"UTC\","
208
- plain_line " gmt_offset: 0"
210
+ plain_line " utc_offset: 0"
209
211
  plain_line " }>"
210
212
  },
211
213
  )
@@ -234,12 +236,12 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
234
236
  expectation: proc {
235
237
  line do
236
238
  plain %| Expected |
237
- actual %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
239
+ actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
238
240
  end
239
241
 
240
242
  line do
241
243
  plain %|not to eq |
242
- expected %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
244
+ expected %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
243
245
  end
244
246
  },
245
247
  )
@@ -251,60 +253,6 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
251
253
  end
252
254
  end
253
255
 
254
- context "when comparing two different Time and ActiveSupport::TimeWithZone instances", active_record: true do
255
- it "produces the correct failure message when used in the positive" do
256
- as_both_colored_and_uncolored do |color_enabled|
257
- snippet = <<~RUBY
258
- expected = Time.utc(2011, 12, 13, 14, 15, 16)
259
- actual = Time.utc(2011, 12, 13, 15, 15, 16).in_time_zone("Europe/Stockholm")
260
- expect(expected).to eq(actual)
261
- RUBY
262
- program = make_rspec_rails_test_program(
263
- snippet,
264
- color_enabled: color_enabled,
265
- )
266
-
267
- expected_output = build_expected_output(
268
- color_enabled: color_enabled,
269
- snippet: %|expect(expected).to eq(actual)|,
270
- expectation: proc {
271
- line do
272
- plain %|Expected |
273
- actual %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
274
- end
275
-
276
- line do
277
- plain %| to eq |
278
- expected %|2011-12-13 16:15:16.000 CET +01:00 (ActiveSupport::TimeWithZone)|
279
- end
280
- },
281
- diff: proc {
282
- plain_line " #<ActiveSupport::TimeWithZone {"
283
- plain_line " year: 2011,"
284
- plain_line " month: 12,"
285
- plain_line " day: 13,"
286
- expected_line "- hour: 16,"
287
- actual_line "+ hour: 14,"
288
- plain_line " min: 15,"
289
- plain_line " sec: 16,"
290
- plain_line " nsec: 0,"
291
- expected_line "- zone: \"CET\","
292
- actual_line "+ zone: \"UTC\","
293
- expected_line "- gmt_offset: 3600,"
294
- actual_line "+ gmt_offset: 0,"
295
- expected_line "- utc: 2011-12-13 15:15:16.000 UTC +00:00 (Time)"
296
- actual_line "+ utc: 2011-12-13 14:15:16.000 UTC +00:00 (Time)"
297
- plain_line " }>"
298
- },
299
- )
300
-
301
- expect(program).
302
- to produce_output_when_run(expected_output).
303
- in_color(color_enabled)
304
- end
305
- end
306
- end
307
-
308
256
  context "when comparing a single-line string with a multi-line string" do
309
257
  it "produces the correct failure message" do
310
258
  as_both_colored_and_uncolored do |color_enabled|
@@ -517,8 +465,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
517
465
  plain_line %| data: {|
518
466
  expected_line %|- "sticky" => true,|
519
467
  actual_line %|+ "sticky" => false,|
520
- actual_line %|+ role: "deprecated",|
521
- plain_line %| person: #<SuperDiff::Test::Person {|
468
+ actual_line %|+ :role => "deprecated",|
469
+ plain_line %| :person => #<SuperDiff::Test::Person {|
522
470
  expected_line %|- name: "Marty",|
523
471
  actual_line %|+ name: "Doc",|
524
472
  plain_line %| age: 60|
@@ -832,17 +780,14 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
832
780
  snippet: %|expect(actual).to eq(expected)|,
833
781
  newline_before_expectation: true,
834
782
  expectation: proc {
835
- if SuperDiff::Test.jruby?
836
- else
837
- line do
838
- plain %|Expected |
839
- actual %|#<SuperDiff::Test::Player @handle="mcmire", @character="Jon", @inventory=["sword"], @shields=11.4, @health=4, @ultimate=true>|
840
- end
841
-
842
- line do
843
- plain %| to eq |
844
- expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
845
- end
783
+ line do
784
+ plain %|Expected |
785
+ actual %|#<SuperDiff::Test::Player @character="Jon", @handle="mcmire", @health=4, @inventory=["sword"], @shields=11.4, @ultimate=true>|
786
+ end
787
+
788
+ line do
789
+ plain %| to eq |
790
+ expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
846
791
  end
847
792
  },
848
793
  )
@@ -870,17 +815,14 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
870
815
  snippet: %|expect(value).not_to eq(value)|,
871
816
  newline_before_expectation: true,
872
817
  expectation: proc {
873
- if SuperDiff::Test.jruby?
874
- else
875
- line do
876
- plain %| Expected |
877
- actual %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
878
- end
879
-
880
- line do
881
- plain %|not to eq |
882
- expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
883
- end
818
+ line do
819
+ plain %| Expected |
820
+ actual %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
821
+ end
822
+
823
+ line do
824
+ plain %|not to eq |
825
+ expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
884
826
  end
885
827
  },
886
828
  )
@@ -1007,4 +949,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
1007
949
  end
1008
950
  end
1009
951
  end
952
+
953
+ it_behaves_like "a matcher that supports elided diffs" do
954
+ let(:matcher) { :eq }
955
+ end
1010
956
  end
@@ -109,8 +109,8 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
109
109
  plain_line %| name: "a",|
110
110
  # plain_line %| age: 9,| # FIXME
111
111
  plain_line %| age: 9|
112
- # expected_line %|- foo: "bar",| # FIXME
113
- expected_line %|- foo: "bar"|
112
+ # expected_line %|- foo: "bar"| # FIXME
113
+ expected_line %|- foo: "bar",|
114
114
  plain_line %| }>|
115
115
  },
116
116
  )
@@ -170,8 +170,7 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
170
170
  expected_line %|- city: "Oakland",|
171
171
  actual_line %|+ city: "Hill Valley",|
172
172
  plain_line %| state: "CA",|
173
- # expected_line %|- zip: "91234",| # FIXME
174
- expected_line %|- zip: "91234"|
173
+ expected_line %|- zip: "91234",| # FIXME
175
174
  actual_line %|+ zip: "90382"|
176
175
  plain_line %| }>|
177
176
  },
@@ -283,9 +282,9 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
283
282
  plain_line %| state: "CA",|
284
283
  # plain_line %| zip: "90382",| # FIXME
285
284
  plain_line %| zip: "90382"|
286
- # expected_line %|- foo: "bar",| # FIXME
287
- expected_line %|- foo: "bar"|
288
- expected_line %|- baz: "qux"|
285
+ expected_line %|- foo: "bar",|
286
+ # expected_line %|- baz: "qux"| # TODO
287
+ expected_line %|- baz: "qux",|
289
288
  plain_line %| }>|
290
289
  },
291
290
  )
@@ -411,7 +410,17 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
411
410
  expected_line %|- data: #<a hash including (|
412
411
  expected_line %|- active: true|
413
412
  expected_line %|- )>,|
414
- expected_line %|- created_at: #<a value within 1 of 2020-04-09 00:00:00.000 UTC +00:00 (Time)>|
413
+ expected_line %|- created_at: #<a value within 1 of #<Time {|
414
+ expected_line %|- year: 2020,|
415
+ expected_line %|- month: 4,|
416
+ expected_line %|- day: 9,|
417
+ expected_line %|- hour: 0,|
418
+ expected_line %|- min: 0,|
419
+ expected_line %|- sec: 0,|
420
+ expected_line %|- subsec: 0,|
421
+ expected_line %|- zone: "UTC",|
422
+ expected_line %|- utc_offset: 0|
423
+ expected_line %|- }>>|
415
424
  plain_line %| }|
416
425
  },
417
426
  )
@@ -33,7 +33,8 @@ RSpec.describe "Integration with RSpec's #match_array matcher", type: :integrati
33
33
  plain_line %| "Marty",|
34
34
  actual_line %|+ "Jennifer",|
35
35
  actual_line %|+ "Doc",|
36
- expected_line %|- "Einie"|
36
+ # expected_line %|- "Einie"| # TODO
37
+ expected_line %|- "Einie",|
37
38
  plain_line %| ]|
38
39
  },
39
40
  )
@@ -132,7 +133,8 @@ RSpec.describe "Integration with RSpec's #match_array matcher", type: :integrati
132
133
  plain_line %| "Lorraine McFly",|
133
134
  actual_line %|+ "Einie",|
134
135
  expected_line %|- "Biff Tannen",|
135
- expected_line %|- "George McFly"|
136
+ # expected_line %|- "George McFly"| # TODO
137
+ expected_line %|- "George McFly",|
136
138
  plain_line %| ]|
137
139
  },
138
140
  )
@@ -243,7 +245,8 @@ RSpec.describe "Integration with RSpec's #match_array matcher", type: :integrati
243
245
  actual_line %|+ "Lorraine McFly",|
244
246
  expected_line %|- "Biff Tannen",|
245
247
  expected_line %|- /Georg McFly/,|
246
- expected_line %|- /Lorrain McFly/|
248
+ # expected_line %|- /Lorrain McFly/| # TODO
249
+ expected_line %|- /Lorrain McFly/,|
247
250
  plain_line %| ]|
248
251
  },
249
252
  )
@@ -333,7 +336,7 @@ RSpec.describe "Integration with RSpec's #match_array matcher", type: :integrati
333
336
  line do
334
337
  plain %| Expected |
335
338
  # rubocop:disable Metrics/LineLength
336
- actual %|[{ foo: "bar" }, #<Double (anonymous)>, { blargh: "riddle" }]|
339
+ actual %|[{ foo: "bar" }, #<Double (anonymous) baz: "qux">, { blargh: "riddle" }]|
337
340
  # rubocop:enable Metrics/LineLength
338
341
  end
339
342
 
@@ -351,13 +354,16 @@ RSpec.describe "Integration with RSpec's #match_array matcher", type: :integrati
351
354
  plain_line %| {|
352
355
  plain_line %| foo: "bar"|
353
356
  plain_line %| },|
354
- plain_line %| #<Double (anonymous)>,|
357
+ plain_line %| #<Double (anonymous) {|
358
+ plain_line %| baz: "qux"|
359
+ plain_line %| }>,|
355
360
  actual_line %|+ {|
356
361
  actual_line %|+ blargh: "riddle"|
357
362
  actual_line %|+ },|
358
363
  expected_line %|- #<a collection containing exactly (|
359
364
  expected_line %|- "zing"|
360
- expected_line %|- )>|
365
+ # expected_line %|- )>| # TODO
366
+ expected_line %|- )>,|
361
367
  plain_line %| ]|
362
368
  },
363
369
  )
@@ -400,7 +406,8 @@ RSpec.describe "Integration with RSpec's #match_array matcher", type: :integrati
400
406
  actual_line %|+ "Marty",|
401
407
  actual_line %|+ "Jennifer",|
402
408
  actual_line %|+ "Doc",|
403
- expected_line %|- "Einie"|
409
+ # expected_line %|- "Einie"| # TODO
410
+ expected_line %|- "Einie",|
404
411
  plain_line %| ]|
405
412
  },
406
413
  )
@@ -341,6 +341,48 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
341
341
  end
342
342
  end
343
343
 
344
+ # HINT: `a_hash_including` is an alias of `include` in the rspec-expectations gem.
345
+ # `hash_including` is an argument matcher in the rspec-mocks gem.
346
+ context "when the expected value is `hash-including-<something>`, not `a-hash-including-<something>`" do
347
+ it "produces the correct failure message" do
348
+ as_both_colored_and_uncolored do |color_enabled|
349
+ snippet = <<~TEST.strip
350
+ expected = hash_including(city: "Hill Valley")
351
+ actual = { city: "Burbank" }
352
+ expect(actual).to match(expected)
353
+ TEST
354
+ program = make_plain_test_program(
355
+ snippet,
356
+ color_enabled: color_enabled,
357
+ )
358
+
359
+ expected_output = build_expected_output(
360
+ color_enabled: color_enabled,
361
+ snippet: %|expect(actual).to match(expected)|,
362
+ expectation: proc {
363
+ line do
364
+ plain %|Expected |
365
+ actual %|{ city: "Burbank" }|
366
+ plain %| to match |
367
+ expected %|#<a hash including (city: "Hill Valley")>|
368
+ plain %|.|
369
+ end
370
+ },
371
+ diff: proc {
372
+ plain_line %| {|
373
+ expected_line %|- city: "Hill Valley"|
374
+ actual_line %|+ city: "Burbank"|
375
+ plain_line %| }|
376
+ },
377
+ )
378
+
379
+ expect(program).
380
+ to produce_output_when_run(expected_output).
381
+ in_color(color_enabled)
382
+ end
383
+ end
384
+ end
385
+
344
386
  context "when the expected value is a collection-including-<something>" do
345
387
  context "that is small" do
346
388
  it "produces the correct failure message when used in the positive" do
@@ -647,6 +689,47 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
647
689
  end
648
690
  end
649
691
 
692
+ context "when the expected value is an array-including-<something>" do
693
+ it "produces the correct failure message" do
694
+ as_both_colored_and_uncolored do |color_enabled|
695
+ snippet = <<~TEST.strip
696
+ expected = array_including("a")
697
+ actual = ["b"]
698
+ expect(actual).to match(expected)
699
+ TEST
700
+ program = make_plain_test_program(
701
+ snippet,
702
+ color_enabled: color_enabled,
703
+ )
704
+
705
+ expected_output = build_expected_output(
706
+ color_enabled: color_enabled,
707
+ snippet: %|expect(actual).to match(expected)|,
708
+ expectation: proc {
709
+ line do
710
+ plain %|Expected |
711
+ actual %|["b"]|
712
+ plain %| to match |
713
+ expected %|#<a collection including ("a")>|
714
+ plain %|.|
715
+ end
716
+ },
717
+ diff: proc {
718
+ plain_line %| [|
719
+ plain_line %| "b"|
720
+ # expected_line %|- "a",| # FIXME
721
+ expected_line %|- "a"|
722
+ plain_line %| ]|
723
+ },
724
+ )
725
+
726
+ expect(program).
727
+ to produce_output_when_run(expected_output).
728
+ in_color(color_enabled)
729
+ end
730
+ end
731
+ end
732
+
650
733
  context "when the expected value is an object-having-attributes" do
651
734
  context "that is small" do
652
735
  it "produces the correct failure message when used in the positive" do
@@ -772,7 +855,8 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
772
855
  # actual_line %|+ zip: "90382",| # FIXME
773
856
  expected_line %|- zip: "91234"|
774
857
  actual_line %|+ zip: "90382"|
775
- expected_line %|- something_else: "blah"|
858
+ # expected_line %|- something_else: "blah"| # TODO
859
+ expected_line %|- something_else: "blah",|
776
860
  plain_line %| }>|
777
861
  },
778
862
  )
@@ -888,7 +972,8 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
888
972
  # expected_line %|- zip: "91234",| # FIXME
889
973
  expected_line %|- zip: "91234"|
890
974
  actual_line %|+ zip: "90382"|
891
- expected_line %|- something_else: "blah"|
975
+ # expected_line %|- something_else: "blah"| # TODO
976
+ expected_line %|- something_else: "blah",|
892
977
  plain_line %| }>|
893
978
  plain_line %| }|
894
979
  },
@@ -982,7 +1067,8 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
982
1067
  diff: proc {
983
1068
  plain_line %| [|
984
1069
  actual_line %|+ "b",|
985
- expected_line %|- "a"|
1070
+ # expected_line %|- "a"| # TODO
1071
+ expected_line %|- "a",|
986
1072
  plain_line %| ]|
987
1073
  },
988
1074
  )
@@ -1060,7 +1146,8 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1060
1146
  actual_line %|+ "eggs",|
1061
1147
  actual_line %|+ "cheese",|
1062
1148
  actual_line %|+ "English muffins",|
1063
- expected_line %|- "bread"|
1149
+ # expected_line %|- "bread"| # TODO
1150
+ expected_line %|- "bread",|
1064
1151
  plain_line %| ]|
1065
1152
  },
1066
1153
  )
@@ -1149,7 +1236,8 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1149
1236
  plain_line %| "milk",|
1150
1237
  actual_line %|+ "toast",|
1151
1238
  actual_line %|+ "eggs",|
1152
- expected_line %|- "bread"|
1239
+ # expected_line %|- "bread"| # TODO
1240
+ expected_line %|- "bread",|
1153
1241
  plain_line %| ]|
1154
1242
  plain_line %| }|
1155
1243
  },
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "pp"
2
+
1
3
  begin
2
4
  require "pry-byebug"
3
5
  rescue LoadError
@@ -8,7 +10,7 @@ begin
8
10
  rescue LoadError
9
11
  end
10
12
 
11
- require "pp"
13
+ require "climate_control"
12
14
 
13
15
  #---
14
16
 
@@ -41,6 +43,7 @@ Dir.glob(File.expand_path("support/**/*.rb", __dir__)).
41
43
  end
42
44
 
43
45
  RSpec.configure do |config|
46
+ config.include(SuperDiff::UnitTests, type: :unit)
44
47
  config.include(SuperDiff::IntegrationTests, type: :integration)
45
48
 
46
49
  config.expect_with :rspec do |expectations|
@@ -5,24 +5,6 @@ require "shellwords"
5
5
  require "timeout"
6
6
 
7
7
  class CommandRunner
8
- module OutputHelpers
9
- def self.bookended(text)
10
- divider("START") + text + "\n" + divider("END")
11
- end
12
-
13
- def self.divider(title = "")
14
- total_length = 72
15
- start_length = 3
16
-
17
- string = ""
18
- string << ("-" * start_length)
19
- string << title
20
- string << "-" * (total_length - start_length - title.length)
21
- string << "\n"
22
- string
23
- end
24
- end
25
-
26
8
  class CommandFailedError < StandardError
27
9
  def self.create(command:, exit_status:, output:, message: nil)
28
10
  allocate.tap do |error|
@@ -49,7 +31,11 @@ Command #{command.inspect} failed, exiting with status #{exit_status}.
49
31
  if output
50
32
  message << <<-MESSAGE
51
33
  Output:
52
- #{OutputHelpers.divider("START") + output + OutputHelpers.divider("END")}
34
+ #{
35
+ SuperDiff::Test::OutputHelpers.divider("START") +
36
+ output +
37
+ SuperDiff::Test::OutputHelpers.divider("END")
38
+ }
53
39
  MESSAGE
54
40
  end
55
41
 
@@ -83,7 +69,11 @@ Command #{formatted_command.inspect} timed out after #{timeout} seconds.
83
69
  if output
84
70
  message << <<-MESSAGE
85
71
  Output:
86
- #{OutputHelpers.divider("START") + output + OutputHelpers.divider("END")}
72
+ #{
73
+ SuperDiff::Test::OutputHelpers.divider("START") +
74
+ output +
75
+ SuperDiff::Test::OutputHelpers.divider("END")
76
+ }
87
77
  MESSAGE
88
78
  end
89
79
 
@@ -120,9 +110,9 @@ Output:
120
110
  @env = extract_env_from(@options)
121
111
 
122
112
  @process = ChildProcess.build(*command)
123
- # @env.each do |key, value|
124
- # @process.environment[key] = value
125
- # end
113
+ @env.each do |key, value|
114
+ @process.environment[key] = value
115
+ end
126
116
  @process.io.stdout = @process.io.stderr = @writer
127
117
 
128
118
  @wrapper = -> (block) { block.call }
@@ -250,9 +240,9 @@ Output:
250
240
 
251
241
  debug do
252
242
  "\n" +
253
- OutputHelpers.divider("START") +
243
+ SuperDiff::Test::OutputHelpers.divider("START") +
254
244
  output +
255
- OutputHelpers.divider("END")
245
+ SuperDiff::Test::OutputHelpers.divider("END")
256
246
  end
257
247
  end
258
248
 
@@ -0,0 +1,21 @@
1
+ module SuperDiff
2
+ module Test
3
+ module OutputHelpers
4
+ def self.bookended(text)
5
+ divider("START") + text + "\n" + divider("END")
6
+ end
7
+
8
+ def self.divider(title = "")
9
+ total_length = 72
10
+ start_length = 3
11
+
12
+ string = ""
13
+ string << ("-" * start_length)
14
+ string << title
15
+ string << "-" * (total_length - start_length - title.length)
16
+ string << "\n"
17
+ string
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,11 +11,13 @@ module SuperDiff
11
11
  def make_plain_test_program(
12
12
  test,
13
13
  color_enabled:,
14
+ configuration: {},
14
15
  preserve_as_whole_file: false
15
16
  )
16
17
  TestPrograms::Plain.new(
17
18
  test,
18
19
  color_enabled: color_enabled,
20
+ configuration: configuration,
19
21
  preserve_as_whole_file: preserve_as_whole_file,
20
22
  )
21
23
  end