super_diff 0.7.0 → 0.8.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 (174) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/lib/super_diff.rb +27 -6
  4. data/lib/super_diff/active_record.rb +7 -7
  5. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
  6. data/lib/super_diff/active_record/object_inspection.rb +2 -6
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
  8. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
  9. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
  10. data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
  11. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
  12. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
  13. data/lib/super_diff/active_support.rb +8 -8
  14. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
  15. data/lib/super_diff/active_support/object_inspection.rb +2 -6
  16. data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
  18. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
  19. data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
  20. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
  21. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
  22. data/lib/super_diff/colorized_document_extensions.rb +9 -6
  23. data/lib/super_diff/configuration.rb +81 -8
  24. data/lib/super_diff/csi.rb +1 -2
  25. data/lib/super_diff/csi/four_bit_color.rb +0 -2
  26. data/lib/super_diff/differs/array.rb +1 -1
  27. data/lib/super_diff/differs/base.rb +3 -21
  28. data/lib/super_diff/differs/custom_object.rb +1 -1
  29. data/lib/super_diff/differs/default_object.rb +1 -1
  30. data/lib/super_diff/differs/hash.rb +1 -1
  31. data/lib/super_diff/differs/main.rb +1 -7
  32. data/lib/super_diff/differs/multiline_string.rb +1 -1
  33. data/lib/super_diff/differs/time_like.rb +1 -1
  34. data/lib/super_diff/equality_matchers/array.rb +2 -2
  35. data/lib/super_diff/equality_matchers/default.rb +2 -2
  36. data/lib/super_diff/equality_matchers/hash.rb +2 -2
  37. data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
  38. data/lib/super_diff/equality_matchers/primitive.rb +4 -7
  39. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  40. data/lib/super_diff/helpers.rb +52 -2
  41. data/lib/super_diff/line.rb +83 -0
  42. data/lib/super_diff/object_inspection.rb +12 -1
  43. data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
  44. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
  45. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
  46. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
  47. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
  48. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
  49. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
  50. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
  51. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
  52. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
  53. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/time_like.rb +19 -18
  54. data/lib/super_diff/object_inspection/nodes.rb +33 -32
  55. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
  56. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
  57. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
  58. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
  59. data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
  60. data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
  61. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
  62. data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
  63. data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
  64. data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
  65. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
  66. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
  67. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
  68. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
  69. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
  70. data/lib/super_diff/operation_tree_builders/array.rb +7 -10
  71. data/lib/super_diff/operation_tree_builders/base.rb +6 -6
  72. data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
  73. data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
  74. data/lib/super_diff/operation_tree_builders/hash.rb +0 -7
  75. data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
  76. data/lib/super_diff/operation_tree_flatteners.rb +20 -0
  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_trees/array.rb +4 -7
  85. data/lib/super_diff/operation_trees/base.rb +39 -16
  86. data/lib/super_diff/operation_trees/custom_object.rb +4 -8
  87. data/lib/super_diff/operation_trees/default_object.rb +28 -13
  88. data/lib/super_diff/operation_trees/hash.rb +4 -7
  89. data/lib/super_diff/operation_trees/main.rb +1 -1
  90. data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
  91. data/lib/super_diff/operations/binary_operation.rb +1 -6
  92. data/lib/super_diff/operations/unary_operation.rb +2 -30
  93. data/lib/super_diff/recursion_guard.rb +3 -3
  94. data/lib/super_diff/rspec.rb +12 -13
  95. data/lib/super_diff/rspec/monkey_patches.rb +2 -2
  96. data/lib/super_diff/rspec/object_inspection.rb +4 -1
  97. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
  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/{inspectors → inspection_tree_builders}/collection_including.rb +9 -8
  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/{inspectors → inspection_tree_builders}/instance_of.rb +3 -5
  103. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/kind_of.rb +3 -5
  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/operation_tree_builders/collection_containing_exactly.rb +0 -3
  108. data/lib/super_diff/tiered_lines.rb +4 -0
  109. data/lib/super_diff/tiered_lines_elider.rb +490 -0
  110. data/lib/super_diff/tiered_lines_formatter.rb +79 -0
  111. data/lib/super_diff/version.rb +1 -1
  112. data/spec/examples.txt +407 -410
  113. data/spec/integration/rails/active_support_spec.rb +19 -0
  114. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
  115. data/spec/integration/rspec/eq_matcher_spec.rb +22 -88
  116. data/spec/integration/rspec/have_attributes_matcher_spec.rb +6 -7
  117. data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
  118. data/spec/integration/rspec/match_matcher_spec.rb +10 -5
  119. data/spec/spec_helper.rb +1 -0
  120. data/spec/support/command_runner.rb +15 -25
  121. data/spec/support/helpers.rb +21 -0
  122. data/spec/support/integration/helpers.rb +2 -0
  123. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
  124. data/spec/support/integration/test_programs/base.rb +36 -10
  125. data/spec/support/shared_examples/active_record.rb +3 -2
  126. data/spec/support/shared_examples/active_support.rb +65 -0
  127. data/spec/support/shared_examples/elided_diffs.rb +914 -0
  128. data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
  129. data/spec/support/unit/helpers.rb +15 -0
  130. data/spec/support/unit/matchers/match_output.rb +41 -0
  131. data/spec/unit/active_record/object_inspection_spec.rb +273 -0
  132. data/spec/unit/equality_matchers/main_spec.rb +51 -71
  133. data/spec/unit/helpers_spec.rb +61 -0
  134. data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
  135. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
  136. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
  137. data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
  138. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
  139. data/spec/unit/rspec/object_inspection_spec.rb +446 -0
  140. data/spec/unit/super_diff_spec.rb +1488 -846
  141. data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
  142. data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
  143. metadata +88 -50
  144. data/lib/super_diff/active_record/diff_formatters.rb +0 -10
  145. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
  146. data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
  147. data/lib/super_diff/active_support/diff_formatters.rb +0 -10
  148. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
  149. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
  150. data/lib/super_diff/diff_formatters.rb +0 -14
  151. data/lib/super_diff/diff_formatters/array.rb +0 -21
  152. data/lib/super_diff/diff_formatters/base.rb +0 -33
  153. data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
  154. data/lib/super_diff/diff_formatters/default_object.rb +0 -46
  155. data/lib/super_diff/diff_formatters/defaults.rb +0 -10
  156. data/lib/super_diff/diff_formatters/hash.rb +0 -34
  157. data/lib/super_diff/diff_formatters/main.rb +0 -41
  158. data/lib/super_diff/object_inspection/inspectors.rb +0 -23
  159. data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
  160. data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
  161. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
  162. data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
  163. data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
  164. data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
  165. data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
  166. data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
  167. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
  168. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
  169. data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
  170. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -36
  171. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
  172. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
  173. data/spec/support/object_id.rb +0 -27
  174. data/spec/support/ruby_versions.rb +0 -11
@@ -269,13 +269,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
269
269
  diff: proc {
270
270
  plain_line %| #<HashWithIndifferentAccess {|
271
271
  plain_line %| "shipments" => [|
272
- plain_line %| {|
273
- plain_line %| "estimated_delivery" => {|
272
+ plain_line %| #<HashWithIndifferentAccess {|
273
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
274
274
  plain_line %| "from" => "2019-05-06",|
275
275
  expected_line %|- "to" => "2019-05-06"|
276
276
  actual_line %|+ "to" => "2019-05-09"|
277
- plain_line %| }|
278
- plain_line %| }|
277
+ plain_line %| }>|
278
+ plain_line %| }>|
279
279
  plain_line %| ]|
280
280
  plain_line %| }>|
281
281
  },
@@ -333,13 +333,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
333
333
  diff: proc {
334
334
  plain_line %| #<HashWithIndifferentAccess {|
335
335
  plain_line %| "shipments" => [|
336
- plain_line %| {|
337
- plain_line %| "estimated_delivery" => {|
336
+ plain_line %| #<HashWithIndifferentAccess {|
337
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
338
338
  plain_line %| "from" => "2019-05-06",|
339
339
  expected_line %|- "to" => "2019-05-06"|
340
340
  actual_line %|+ "to" => "2019-05-09"|
341
- plain_line %| }|
342
- plain_line %| }|
341
+ plain_line %| }>|
342
+ plain_line %| }>|
343
343
  plain_line %| ]|
344
344
  plain_line %| }>|
345
345
  },
@@ -625,13 +625,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
625
625
  diff: proc {
626
626
  plain_line %| #<HashWithIndifferentAccess {|
627
627
  plain_line %| "shipments" => [|
628
- plain_line %| {|
629
- plain_line %| "estimated_delivery" => {|
628
+ plain_line %| #<HashWithIndifferentAccess {|
629
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
630
630
  plain_line %| "from" => "2019-05-06",|
631
631
  expected_line %|- "to" => "2019-05-06"|
632
632
  actual_line %|+ "to" => "2019-05-09"|
633
- plain_line %| }|
634
- plain_line %| }|
633
+ plain_line %| }>|
634
+ plain_line %| }>|
635
635
  plain_line %| ]|
636
636
  plain_line %| }>|
637
637
  },
@@ -689,13 +689,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
689
689
  diff: proc {
690
690
  plain_line %| #<HashWithIndifferentAccess {|
691
691
  plain_line %| "shipments" => [|
692
- plain_line %| {|
693
- plain_line %| "estimated_delivery" => {|
692
+ plain_line %| #<HashWithIndifferentAccess {|
693
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
694
694
  plain_line %| "from" => "2019-05-06",|
695
695
  expected_line %|- "to" => "2019-05-06"|
696
696
  actual_line %|+ "to" => "2019-05-09"|
697
- plain_line %| }|
698
- plain_line %| }|
697
+ plain_line %| }>|
698
+ plain_line %| }>|
699
699
  plain_line %| ]|
700
700
  plain_line %| }>|
701
701
  },
@@ -0,0 +1,15 @@
1
+ module SuperDiff
2
+ module UnitTests
3
+ def with_configuration(configuration)
4
+ old_configuration = SuperDiff.configuration.dup
5
+ SuperDiff.configuration.merge!(configuration)
6
+ yield.tap do
7
+ SuperDiff.configuration.merge!(old_configuration)
8
+ end
9
+ end
10
+
11
+ def colored(*args, **opts, &block)
12
+ SuperDiff::Helpers.style(*args, **opts, &block).to_s.chomp
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ module SuperDiff
2
+ module UnitTests
3
+ def match_output(expected_output)
4
+ MatchOutputMatcher.new(expected_output)
5
+ end
6
+
7
+ class MatchOutputMatcher
8
+ extend AttrExtras.mixin
9
+
10
+ pattr_initialize :expected_output
11
+ attr_private :actual_output
12
+
13
+ def matches?(actual_output)
14
+ @actual_output = actual_output
15
+ actual_output == expected_output
16
+ end
17
+
18
+ def failure_message
19
+ message =
20
+ "Expected colored output to be printed, but got a mismatch.\n\n" +
21
+ "Expected output:\n\n" +
22
+ SuperDiff::Test::OutputHelpers.bookended(expected_output) +
23
+ "\n" +
24
+ "Actual output:\n\n" +
25
+ SuperDiff::Test::OutputHelpers.bookended(actual_output)
26
+
27
+ if ["1", "true"].include?(ENV["SHOW_DIFF"])
28
+ ::RSpec::Matchers::ExpectedsForMultipleDiffs.
29
+ from(expected_output).
30
+ message_with_diff(
31
+ message,
32
+ ::RSpec::Expectations.differ,
33
+ actual_output,
34
+ )
35
+ else
36
+ message
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,273 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe SuperDiff, type: :unit do
4
+ describe ".inspect_object", "for ActiveRecord objects", active_record: true do
5
+ context "given an ActiveRecord object" do
6
+ context "given as_lines: false" do
7
+ it "returns an inspected version of the object" do
8
+ string = described_class.inspect_object(
9
+ SuperDiff::Test::Models::ActiveRecord::Person.new(
10
+ name: "Elliot",
11
+ age: 31,
12
+ ),
13
+ as_lines: false,
14
+ )
15
+ expect(string).to eq(
16
+ %(#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">)
17
+ )
18
+ end
19
+ end
20
+
21
+ context "given as_lines: true" do
22
+ it "returns an inspected version of the object as multiple Lines" do
23
+ tiered_lines = described_class.inspect_object(
24
+ SuperDiff::Test::Models::ActiveRecord::Person.new(
25
+ name: "Elliot",
26
+ age: 31,
27
+ ),
28
+ as_lines: true,
29
+ type: :delete,
30
+ indentation_level: 1,
31
+ )
32
+ expect(tiered_lines).to match([
33
+ an_object_having_attributes(
34
+ type: :delete,
35
+ indentation_level: 1,
36
+ value: %(#<SuperDiff::Test::Models::ActiveRecord::Person {),
37
+ collection_bookend: :open,
38
+ ),
39
+ an_object_having_attributes(
40
+ type: :delete,
41
+ indentation_level: 2,
42
+ prefix: %(id: ),
43
+ value: %(nil),
44
+ add_comma: true,
45
+ ),
46
+ an_object_having_attributes(
47
+ type: :delete,
48
+ indentation_level: 2,
49
+ prefix: %(age: ),
50
+ value: %(31),
51
+ add_comma: true,
52
+ ),
53
+ an_object_having_attributes(
54
+ type: :delete,
55
+ indentation_level: 2,
56
+ prefix: %(name: ),
57
+ value: %("Elliot"),
58
+ add_comma: false,
59
+ ),
60
+ an_object_having_attributes(
61
+ type: :delete,
62
+ indentation_level: 1,
63
+ value: %(}>),
64
+ collection_bookend: :close,
65
+ ),
66
+ ])
67
+ end
68
+ end
69
+ end
70
+
71
+ context "given an ActiveRecord::Relation object" do
72
+ context "given as_lines: false" do
73
+ it "returns an inspected version of the Relation" do
74
+ SuperDiff::Test::Models::ActiveRecord::Person.create!(
75
+ name: "Marty",
76
+ age: 19,
77
+ )
78
+ SuperDiff::Test::Models::ActiveRecord::Person.create!(
79
+ name: "Jennifer",
80
+ age: 17,
81
+ )
82
+
83
+ string = described_class.inspect_object(
84
+ SuperDiff::Test::Models::ActiveRecord::Person.all,
85
+ as_lines: false,
86
+ )
87
+
88
+ expect(string).to eq(
89
+ %(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person id: 2, age: 17, name: "Jennifer">]>)
90
+ )
91
+ end
92
+ end
93
+
94
+ context "given as_lines: true" do
95
+ it "returns an inspected version of the Relation as multiple Lines" do
96
+ SuperDiff::Test::Models::ActiveRecord::Person.create!(
97
+ name: "Marty",
98
+ age: 19,
99
+ )
100
+ SuperDiff::Test::Models::ActiveRecord::Person.create!(
101
+ name: "Jennifer",
102
+ age: 17,
103
+ )
104
+
105
+ tiered_lines = described_class.inspect_object(
106
+ SuperDiff::Test::Models::ActiveRecord::Person.all,
107
+ as_lines: true,
108
+ type: :delete,
109
+ indentation_level: 1,
110
+ )
111
+
112
+ expect(tiered_lines).to match([
113
+ an_object_having_attributes(
114
+ type: :delete,
115
+ indentation_level: 1,
116
+ value: %(#<ActiveRecord::Relation [),
117
+ collection_bookend: :open,
118
+ ),
119
+ an_object_having_attributes(
120
+ type: :delete,
121
+ indentation_level: 2,
122
+ value: %(#<SuperDiff::Test::Models::ActiveRecord::Person {),
123
+ collection_bookend: :open,
124
+ ),
125
+ an_object_having_attributes(
126
+ type: :delete,
127
+ indentation_level: 3,
128
+ prefix: %(id: ),
129
+ value: %(1),
130
+ add_comma: true,
131
+ ),
132
+ an_object_having_attributes(
133
+ type: :delete,
134
+ indentation_level: 3,
135
+ prefix: %(age: ),
136
+ value: %(19),
137
+ add_comma: true,
138
+ ),
139
+ an_object_having_attributes(
140
+ type: :delete,
141
+ indentation_level: 3,
142
+ prefix: %(name: ),
143
+ value: %("Marty"),
144
+ add_comma: false,
145
+ ),
146
+ an_object_having_attributes(
147
+ type: :delete,
148
+ indentation_level: 2,
149
+ value: %(}>),
150
+ collection_bookend: :close,
151
+ ),
152
+ an_object_having_attributes(
153
+ type: :delete,
154
+ indentation_level: 2,
155
+ value: %(#<SuperDiff::Test::Models::ActiveRecord::Person {),
156
+ collection_bookend: :open,
157
+ ),
158
+ an_object_having_attributes(
159
+ type: :delete,
160
+ indentation_level: 3,
161
+ prefix: %(id: ),
162
+ value: %(2),
163
+ add_comma: true,
164
+ ),
165
+ an_object_having_attributes(
166
+ type: :delete,
167
+ indentation_level: 3,
168
+ prefix: %(age: ),
169
+ value: %(17),
170
+ add_comma: true,
171
+ ),
172
+ an_object_having_attributes(
173
+ type: :delete,
174
+ indentation_level: 3,
175
+ prefix: %(name: ),
176
+ value: %("Jennifer"),
177
+ add_comma: false,
178
+ ),
179
+ an_object_having_attributes(
180
+ type: :delete,
181
+ indentation_level: 2,
182
+ value: %(}>),
183
+ collection_bookend: :close,
184
+ ),
185
+ an_object_having_attributes(
186
+ type: :delete,
187
+ indentation_level: 1,
188
+ value: %(]>),
189
+ collection_bookend: :close,
190
+ ),
191
+ ])
192
+ end
193
+ end
194
+ end
195
+
196
+ context "given a HashWithIndifferentAccess" do
197
+ context "given as_lines: false" do
198
+ it "returns an inspected version of the object" do
199
+ string = described_class.inspect_object(
200
+ HashWithIndifferentAccess.new({
201
+ line_1: "123 Main St.",
202
+ city: "Hill Valley",
203
+ state: "CA",
204
+ zip: "90382",
205
+ }),
206
+ as_lines: false,
207
+ )
208
+ expect(string).to eq(
209
+ %(#<HashWithIndifferentAccess { "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }>),
210
+ )
211
+ end
212
+ end
213
+
214
+ context "given as_lines: true" do
215
+ it "returns an inspected version of the object as multiple Lines" do
216
+ tiered_lines = described_class.inspect_object(
217
+ HashWithIndifferentAccess.new({
218
+ line_1: "123 Main St.",
219
+ city: "Hill Valley",
220
+ state: "CA",
221
+ zip: "90382",
222
+ }),
223
+ as_lines: true,
224
+ type: :delete,
225
+ indentation_level: 1,
226
+ )
227
+ expect(tiered_lines).to match([
228
+ an_object_having_attributes(
229
+ type: :delete,
230
+ indentation_level: 1,
231
+ value: %(#<HashWithIndifferentAccess {),
232
+ collection_bookend: :open,
233
+ ),
234
+ an_object_having_attributes(
235
+ type: :delete,
236
+ indentation_level: 2,
237
+ prefix: %("line_1" => ),
238
+ value: %("123 Main St."),
239
+ add_comma: true,
240
+ ),
241
+ an_object_having_attributes(
242
+ type: :delete,
243
+ indentation_level: 2,
244
+ prefix: %("city" => ),
245
+ value: %("Hill Valley"),
246
+ add_comma: true,
247
+ ),
248
+ an_object_having_attributes(
249
+ type: :delete,
250
+ indentation_level: 2,
251
+ prefix: %("state" => ),
252
+ value: %("CA"),
253
+ add_comma: true,
254
+ ),
255
+ an_object_having_attributes(
256
+ type: :delete,
257
+ indentation_level: 2,
258
+ prefix: %("zip" => ),
259
+ value: %("90382"),
260
+ add_comma: false,
261
+ ),
262
+ an_object_having_attributes(
263
+ type: :delete,
264
+ indentation_level: 1,
265
+ value: %(}>),
266
+ collection_bookend: :close,
267
+ ),
268
+ ])
269
+ end
270
+ end
271
+ end
272
+ end
273
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe SuperDiff::EqualityMatchers::Main do
3
+ RSpec.describe SuperDiff::EqualityMatchers::Main, type: :unit do
4
4
  describe "#call" do
5
5
  context "given the same integers" do
6
6
  it "returns an empty string" do
@@ -33,7 +33,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
33
33
  }
34
34
  STR
35
35
 
36
- expect(actual_output).to eq(expected_output)
36
+ expect(actual_output).to match_output(expected_output)
37
37
  end
38
38
  end
39
39
 
@@ -60,7 +60,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
60
60
  }
61
61
  STR
62
62
 
63
- expect(actual_output).to eq(expected_output)
63
+ expect(actual_output).to match_output(expected_output)
64
64
  end
65
65
  end
66
66
 
@@ -90,7 +90,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
90
90
  }
91
91
  STR
92
92
 
93
- expect(actual_output).to eq(expected_output)
93
+ expect(actual_output).to match_output(expected_output)
94
94
  end
95
95
  end
96
96
 
@@ -112,7 +112,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
112
112
  }
113
113
  STR
114
114
 
115
- expect(actual_output).to eq(expected_output)
115
+ expect(actual_output).to match_output(expected_output)
116
116
  end
117
117
  end
118
118
 
@@ -134,7 +134,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
134
134
  }
135
135
  STR
136
136
 
137
- expect(actual_output).to eq(expected_output)
137
+ expect(actual_output).to match_output(expected_output)
138
138
  end
139
139
  end
140
140
 
@@ -156,7 +156,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
156
156
  }
157
157
  STR
158
158
 
159
- expect(actual_output).to eq(expected_output)
159
+ expect(actual_output).to match_output(expected_output)
160
160
  end
161
161
  end
162
162
 
@@ -189,7 +189,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
189
189
  }
190
190
  STR
191
191
 
192
- expect(actual_output).to eq(expected_output)
192
+ expect(actual_output).to match_output(expected_output)
193
193
  end
194
194
  end
195
195
 
@@ -222,7 +222,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
222
222
  }
223
223
  STR
224
224
 
225
- expect(actual_output).to eq(expected_output)
225
+ expect(actual_output).to match_output(expected_output)
226
226
  end
227
227
  end
228
228
 
@@ -288,7 +288,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
288
288
  }
289
289
  STR
290
290
 
291
- expect(actual_output).to eq(expected_output)
291
+ expect(actual_output).to match_output(expected_output)
292
292
  end
293
293
  end
294
294
 
@@ -335,7 +335,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
335
335
  }
336
336
  STR
337
337
 
338
- expect(actual_output).to eq(expected_output)
338
+ expect(actual_output).to match_output(expected_output)
339
339
  end
340
340
  end
341
341
 
@@ -371,7 +371,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
371
371
  }
372
372
  STR
373
373
 
374
- expect(actual_output).to eq(expected_output)
374
+ expect(actual_output).to match_output(expected_output)
375
375
  end
376
376
  end
377
377
 
@@ -406,7 +406,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
406
406
  }
407
407
  STR
408
408
 
409
- expect(actual_output).to eq(expected_output)
409
+ expect(actual_output).to match_output(expected_output)
410
410
  end
411
411
  end
412
412
 
@@ -453,7 +453,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
453
453
  }
454
454
  STR
455
455
 
456
- expect(actual_output).to eq(expected_output)
456
+ expect(actual_output).to match_output(expected_output)
457
457
  end
458
458
  end
459
459
 
@@ -487,7 +487,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
487
487
  }
488
488
  STR
489
489
 
490
- expect(actual_output).to eq(expected_output)
490
+ expect(actual_output).to match_output(expected_output)
491
491
  end
492
492
  end
493
493
 
@@ -521,7 +521,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
521
521
  }
522
522
  STR
523
523
 
524
- expect(actual_output).to eq(expected_output)
524
+ expect(actual_output).to match_output(expected_output)
525
525
  end
526
526
  end
527
527
 
@@ -555,7 +555,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
555
555
  }
556
556
  STR
557
557
 
558
- expect(actual_output).to eq(expected_output)
558
+ expect(actual_output).to match_output(expected_output)
559
559
  end
560
560
  end
561
561
 
@@ -589,7 +589,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
589
589
  }
590
590
  STR
591
591
 
592
- expect(actual_output).to eq(expected_output)
592
+ expect(actual_output).to match_output(expected_output)
593
593
  end
594
594
  end
595
595
 
@@ -629,7 +629,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
629
629
  }
630
630
  STR
631
631
 
632
- expect(actual_output).to eq(expected_output)
632
+ expect(actual_output).to match_output(expected_output)
633
633
  end
634
634
  end
635
635
 
@@ -668,7 +668,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
668
668
  }
669
669
  STR
670
670
 
671
- expect(actual_output).to eq(expected_output)
671
+ expect(actual_output).to match_output(expected_output)
672
672
  end
673
673
  end
674
674
 
@@ -713,7 +713,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
713
713
  }
714
714
  STR
715
715
 
716
- expect(actual_output).to eq(expected_output)
716
+ expect(actual_output).to match_output(expected_output)
717
717
  end
718
718
  end
719
719
 
@@ -776,7 +776,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
776
776
  plain_line %( data: {)
777
777
  expected_line %(- "sticky" => true)
778
778
  actual_line %(+ "sticky" => false,)
779
- actual_line %(+ role: "deprecated")
779
+ actual_line %(+ :role => "deprecated")
780
780
  plain_line %( })
781
781
  plain_line %( })
782
782
  plain_line %( ],)
@@ -786,7 +786,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
786
786
  }
787
787
  STR
788
788
 
789
- expect(actual_output).to eq(expected_output)
789
+ expect(actual_output).to match_output(expected_output)
790
790
  end
791
791
  end
792
792
 
@@ -832,7 +832,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
832
832
  }
833
833
  STR
834
834
 
835
- expect(actual_output).to eq(expected_output)
835
+ expect(actual_output).to match_output(expected_output)
836
836
  end
837
837
  end
838
838
 
@@ -867,7 +867,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
867
867
  }
868
868
  STR
869
869
 
870
- expect(actual_output).to eq(expected_output)
870
+ expect(actual_output).to match_output(expected_output)
871
871
  end
872
872
  end
873
873
 
@@ -902,7 +902,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
902
902
  }
903
903
  STR
904
904
 
905
- expect(actual_output).to eq(expected_output)
905
+ expect(actual_output).to match_output(expected_output)
906
906
  end
907
907
  end
908
908
 
@@ -937,7 +937,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
937
937
  }
938
938
  STR
939
939
 
940
- expect(actual_output).to eq(expected_output)
940
+ expect(actual_output).to match_output(expected_output)
941
941
  end
942
942
  end
943
943
 
@@ -984,7 +984,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
984
984
  }
985
985
  STR
986
986
 
987
- expect(actual_output).to eq(expected_output)
987
+ expect(actual_output).to match_output(expected_output)
988
988
  end
989
989
  end
990
990
 
@@ -1018,7 +1018,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1018
1018
  }
1019
1019
  STR
1020
1020
 
1021
- expect(actual_output).to eq(expected_output)
1021
+ expect(actual_output).to match_output(expected_output)
1022
1022
  end
1023
1023
  end
1024
1024
 
@@ -1052,7 +1052,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1052
1052
  }
1053
1053
  STR
1054
1054
 
1055
- expect(actual_output).to eq(expected_output)
1055
+ expect(actual_output).to match_output(expected_output)
1056
1056
  end
1057
1057
  end
1058
1058
 
@@ -1132,7 +1132,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1132
1132
  }
1133
1133
  STR
1134
1134
 
1135
- expect(actual_output).to eq(expected_output)
1135
+ expect(actual_output).to match_output(expected_output)
1136
1136
  end
1137
1137
  end
1138
1138
 
@@ -1207,7 +1207,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1207
1207
  }
1208
1208
  STR
1209
1209
 
1210
- expect(actual_output).to eq(expected_output)
1210
+ expect(actual_output).to match_output(expected_output)
1211
1211
  end
1212
1212
  end
1213
1213
  end
@@ -1255,7 +1255,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1255
1255
  }
1256
1256
  STR
1257
1257
 
1258
- expect(actual_output).to eq(expected_output)
1258
+ expect(actual_output).to match_output(expected_output)
1259
1259
  end
1260
1260
  end
1261
1261
 
@@ -1310,7 +1310,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1310
1310
  }
1311
1311
  STR
1312
1312
 
1313
- expect(actual_output).to eq(expected_output)
1313
+ expect(actual_output).to match_output(expected_output)
1314
1314
  end
1315
1315
  end
1316
1316
 
@@ -1357,7 +1357,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1357
1357
  }
1358
1358
  STR
1359
1359
 
1360
- expect(actual_output).to eq(expected_output)
1360
+ expect(actual_output).to match_output(expected_output)
1361
1361
  end
1362
1362
  end
1363
1363
 
@@ -1450,7 +1450,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1450
1450
  }
1451
1451
  STR
1452
1452
 
1453
- expect(actual_output).to eq(expected_output)
1453
+ expect(actual_output).to match_output(expected_output)
1454
1454
  end
1455
1455
  end
1456
1456
 
@@ -1499,7 +1499,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1499
1499
  }
1500
1500
  STR
1501
1501
 
1502
- expect(actual_output).to eq(expected_output)
1502
+ expect(actual_output).to match_output(expected_output)
1503
1503
  end
1504
1504
  end
1505
1505
 
@@ -1528,17 +1528,9 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1528
1528
  Differing objects.
1529
1529
 
1530
1530
  #{
1531
- if SuperDiff::Test.jruby?
1532
- # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
1533
- colored do
1534
- expected_line %(Expected: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(expected)} @inventory=["flatline", "purple body shield"], @character="mirage", @handle="martymcfly", @ultimate=0.8, @shields=0.6, @health=0.3>)
1535
- actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @inventory=["wingman", "mastiff"], @character="lifeline", @handle="docbrown", @ultimate=0.8, @shields=0.6, @health=0.3>)
1536
- end
1537
- else
1538
- colored do
1539
- expected_line %(Expected: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(expected)} @handle="martymcfly", @character="mirage", @inventory=["flatline", "purple body shield"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1540
- actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @handle="docbrown", @character="lifeline", @inventory=["wingman", "mastiff"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1541
- end
1531
+ colored do
1532
+ expected_line %(Expected: #<SuperDiff::Test::Player:#{SuperDiff::Helpers.object_address_for(expected)} @character="mirage", @handle="martymcfly", @health=0.3, @inventory=["flatline", "purple body shield"], @shields=0.6, @ultimate=0.8>)
1533
+ actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Helpers.object_address_for(actual)} @character="lifeline", @handle="docbrown", @health=0.3, @inventory=["wingman", "mastiff"], @shields=0.6, @ultimate=0.8>)
1542
1534
  end
1543
1535
  }
1544
1536
 
@@ -1546,7 +1538,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1546
1538
 
1547
1539
  #{
1548
1540
  colored do
1549
- plain_line %( #<SuperDiff::Test::Player {)
1541
+ plain_line %( #<SuperDiff::Test::Player:#{SuperDiff::Helpers.object_address_for(actual)} {)
1550
1542
  expected_line %(- @character="mirage",)
1551
1543
  actual_line %(+ @character="lifeline",)
1552
1544
  expected_line %(- @handle="martymcfly",)
@@ -1565,7 +1557,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1565
1557
  }
1566
1558
  STR
1567
1559
 
1568
- expect(actual_output).to eq(expected_output)
1560
+ expect(actual_output).to match_output(expected_output)
1569
1561
  end
1570
1562
  end
1571
1563
 
@@ -1594,7 +1586,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1594
1586
  }
1595
1587
  STR
1596
1588
 
1597
- expect(actual_output).to eq(expected_output)
1589
+ expect(actual_output).to match_output(expected_output)
1598
1590
  end
1599
1591
  end
1600
1592
 
@@ -1619,22 +1611,14 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1619
1611
  Differing objects.
1620
1612
 
1621
1613
  #{
1622
- if SuperDiff::Test.jruby?
1623
- # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
1624
- colored do
1625
- expected_line %(Expected: #<SuperDiff::Test::Item:#{SuperDiff::Test.object_id_hex(expected)} @name="camera", @quantity=3>)
1626
- actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @inventory=["sword"], @character="Jon", @handle="mcmire", @ultimate=true, @shields=11.4, @health=4>)
1627
- end
1628
- else
1629
- colored do
1630
- expected_line %(Expected: #<SuperDiff::Test::Item:#{SuperDiff::Test.object_id_hex(expected)} @name="camera", @quantity=3>)
1631
- actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @handle="mcmire", @character="Jon", @inventory=["sword"], @shields=11.4, @health=4, @ultimate=true>)
1632
- end
1614
+ colored do
1615
+ expected_line %(Expected: #<SuperDiff::Test::Item:#{SuperDiff::Helpers.object_address_for(expected)} @name="camera", @quantity=3>)
1616
+ actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Helpers.object_address_for(actual)} @character="Jon", @handle="mcmire", @health=4, @inventory=["sword"], @shields=11.4, @ultimate=true>)
1633
1617
  end
1634
1618
  }
1635
1619
  STR
1636
1620
 
1637
- expect(actual_output).to eq(expected_output)
1621
+ expect(actual_output).to match_output(expected_output)
1638
1622
  end
1639
1623
  end
1640
1624
 
@@ -1671,7 +1655,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1671
1655
  }
1672
1656
  STR
1673
1657
 
1674
- expect(actual_output).to eq(expected_output)
1658
+ expect(actual_output).to match_output(expected_output)
1675
1659
  end
1676
1660
  end
1677
1661
 
@@ -1708,7 +1692,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1708
1692
  }
1709
1693
  STR
1710
1694
 
1711
- expect(actual_output).to eq(expected_output)
1695
+ expect(actual_output).to match_output(expected_output)
1712
1696
  end
1713
1697
  end
1714
1698
 
@@ -1747,7 +1731,7 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1747
1731
  }
1748
1732
  STR
1749
1733
 
1750
- expect(actual_output).to eq(expected_output)
1734
+ expect(actual_output).to match_output(expected_output)
1751
1735
  end
1752
1736
  end
1753
1737
 
@@ -1786,12 +1770,8 @@ RSpec.describe SuperDiff::EqualityMatchers::Main do
1786
1770
  }
1787
1771
  STR
1788
1772
 
1789
- expect(actual_output).to eq(expected_output)
1773
+ expect(actual_output).to match_output(expected_output)
1790
1774
  end
1791
1775
  end
1792
1776
  end
1793
-
1794
- def colored(*args, **opts, &block)
1795
- SuperDiff::Helpers.style(*args, **opts, &block).to_s.chomp
1796
- end
1797
1777
  end