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
@@ -1,284 +1,469 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe SuperDiff do
4
- describe ".inspect_object" do
3
+ RSpec.describe SuperDiff, type: :unit do
4
+ describe ".inspect_object", "for Ruby objects" do
5
5
  context "given nil" do
6
- context "given as_single_line: true" do
7
- it "returns nil, inspected" do
8
- inspection = described_class.inspect_object(
9
- nil,
10
- as_single_line: true,
11
- )
12
- expect(inspection).to eq("nil")
6
+ context "given as_lines: false" do
7
+ it "returns 'nil'" do
8
+ string = described_class.inspect_object(nil, as_lines: false)
9
+ expect(string).to eq("nil")
13
10
  end
14
11
  end
15
12
 
16
- context "given as_single_line: false" do
17
- it "returns nil, inspected" do
18
- inspection = described_class.inspect_object(
13
+ context "given as_lines: true" do
14
+ it "returns nil wrapped in a single Line" do
15
+ tiered_lines = described_class.inspect_object(
19
16
  nil,
20
- as_single_line: false,
17
+ as_lines: true,
18
+ type: :delete,
19
+ indentation_level: 1,
21
20
  )
22
- expect(inspection).to eq("nil")
21
+ expect(tiered_lines).to match([
22
+ an_object_having_attributes(
23
+ type: :delete,
24
+ indentation_level: 1,
25
+ value: %(nil),
26
+ ),
27
+ ])
23
28
  end
24
29
  end
25
30
  end
26
31
 
27
32
  context "given true" do
28
- context "given as_single_line: true" do
29
- it "returns nil, inspected" do
30
- inspection = described_class.inspect_object(
31
- nil,
32
- as_single_line: true,
33
- )
34
- expect(inspection).to eq("nil")
33
+ context "given as_lines: false" do
34
+ it "returns an inspected version of true" do
35
+ string = described_class.inspect_object(true, as_lines: false)
36
+ expect(string).to eq("true")
35
37
  end
36
38
  end
37
39
 
38
- context "given as_single_line: false" do
39
- it "returns nil, inspected" do
40
- inspection = described_class.inspect_object(
41
- nil,
42
- as_single_line: false,
40
+ context "given as_lines: true" do
41
+ it "returns true wrapped in a single Line" do
42
+ tiered_lines = described_class.inspect_object(
43
+ true,
44
+ as_lines: true,
45
+ type: :delete,
46
+ indentation_level: 1,
43
47
  )
44
- expect(inspection).to eq("nil")
48
+ expect(tiered_lines).to match([
49
+ an_object_having_attributes(
50
+ type: :delete,
51
+ indentation_level: 1,
52
+ value: %(true),
53
+ ),
54
+ ])
45
55
  end
46
56
  end
47
57
  end
48
58
 
49
59
  context "given false" do
50
- context "given as_single_line: false" do
51
- it "returns false, inspected" do
52
- inspection = described_class.inspect_object(
53
- false,
54
- as_single_line: false,
55
- )
56
- expect(inspection).to eq("false")
60
+ context "given as_lines: false" do
61
+ it "returns an inspected version of false" do
62
+ string = described_class.inspect_object(false, as_lines: false)
63
+ expect(string).to eq("false")
57
64
  end
58
65
  end
59
66
 
60
- context "given as_single_line: false" do
61
- it "returns false, inspected" do
62
- inspection = described_class.inspect_object(
67
+ context "given as_lines: true" do
68
+ it "returns false wrapped in a single Line" do
69
+ tiered_lines = described_class.inspect_object(
63
70
  false,
64
- as_single_line: false,
71
+ as_lines: true,
72
+ type: :delete,
73
+ indentation_level: 1,
65
74
  )
66
- expect(inspection).to eq("false")
75
+ expect(tiered_lines).to match([
76
+ an_object_having_attributes(
77
+ type: :delete,
78
+ indentation_level: 1,
79
+ value: %(false),
80
+ ),
81
+ ])
67
82
  end
68
83
  end
69
84
  end
70
85
 
71
86
  context "given a number" do
72
- context "given as_single_line: true" do
73
- it "returns the number as a string" do
74
- inspection = described_class.inspect_object(
75
- 3,
76
- as_single_line: true,
77
- )
78
- expect(inspection).to eq("3")
87
+ context "given as_lines: false" do
88
+ it "returns an inspected version of the number" do
89
+ string = described_class.inspect_object(3, as_lines: false)
90
+ expect(string).to eq("3")
79
91
  end
80
92
  end
81
93
 
82
- context "given as_single_line: false" do
83
- it "returns the number as a string" do
84
- inspection = described_class.inspect_object(
94
+ context "given as_lines: true" do
95
+ it "returns the number wrapped in a single Line" do
96
+ tiered_lines = described_class.inspect_object(
85
97
  3,
86
- as_single_line: false,
98
+ as_lines: true,
99
+ type: :delete,
100
+ indentation_level: 1,
87
101
  )
88
- expect(inspection).to eq("3")
102
+ expect(tiered_lines).to match([
103
+ an_object_having_attributes(
104
+ type: :delete,
105
+ indentation_level: 1,
106
+ value: %(3),
107
+ ),
108
+ ])
89
109
  end
90
110
  end
91
111
  end
92
112
 
93
113
  context "given a symbol" do
94
- context "given as_single_line: true" do
95
- it "returns the symbol, inspected" do
96
- inspection = described_class.inspect_object(
97
- :foo,
98
- as_single_line: true,
99
- )
100
- expect(inspection).to eq(":foo")
114
+ context "given as_lines: false" do
115
+ it "returns an inspected version of the symbol" do
116
+ string = described_class.inspect_object(:foo, as_lines: false)
117
+ expect(string).to eq(":foo")
101
118
  end
102
119
  end
103
120
 
104
- context "given as_single_line: false" do
105
- it "returns the symbol, inspected" do
106
- inspection = described_class.inspect_object(
121
+ context "given as_lines: true" do
122
+ it "returns an inspected version of the symbol wrapped in a single Line" do
123
+ tiered_lines = described_class.inspect_object(
107
124
  :foo,
108
- as_single_line: false,
125
+ as_lines: true,
126
+ type: :delete,
127
+ indentation_level: 1,
109
128
  )
110
- expect(inspection).to eq(":foo")
129
+ expect(tiered_lines).to match([
130
+ an_object_having_attributes(
131
+ type: :delete,
132
+ indentation_level: 1,
133
+ value: %(:foo),
134
+ ),
135
+ ])
111
136
  end
112
137
  end
113
138
  end
114
139
 
115
140
  context "given a regex" do
116
- context "given as_single_line: true" do
117
- it "returns the regex, inspected" do
118
- inspection = described_class.inspect_object(
119
- /foo/,
120
- as_single_line: true,
121
- )
122
- expect(inspection).to eq("/foo/")
141
+ context "given as_lines: false" do
142
+ it "returns an inspected version of the regex" do
143
+ string = described_class.inspect_object(/foo/, as_lines: false)
144
+ expect(string).to eq("/foo/")
123
145
  end
124
146
  end
125
147
 
126
- context "given as_single_line: false" do
127
- it "returns the regex, inspected" do
128
- inspection = described_class.inspect_object(
148
+ context "given as_lines: true" do
149
+ it "returns an inspected version of the regex wrapped in a single Line" do
150
+ tiered_lines = described_class.inspect_object(
129
151
  /foo/,
130
- as_single_line: false,
152
+ as_lines: true,
153
+ type: :delete,
154
+ indentation_level: 1,
131
155
  )
132
- expect(inspection).to eq("/foo/")
156
+ expect(tiered_lines).to match([
157
+ an_object_having_attributes(
158
+ type: :delete,
159
+ indentation_level: 1,
160
+ value: %(/foo/),
161
+ ),
162
+ ])
133
163
  end
134
164
  end
135
165
  end
136
166
 
137
167
  context "given a single-line string" do
138
- it "returns the string surrounded by quotes" do
139
- inspection = described_class.inspect_object(
140
- "Marty",
141
- as_single_line: true,
142
- )
143
- expect(inspection).to eq('"Marty"')
168
+ context "given as_lines: false" do
169
+ it "returns an inspected version of the string" do
170
+ inspection = described_class.inspect_object("Marty", as_lines: false)
171
+ expect(inspection).to eq('"Marty"')
172
+ end
173
+ end
174
+
175
+ context "given as_lines: true" do
176
+ it "returns an inspected version of the string wrapped in a single Line" do
177
+ tiered_lines = described_class.inspect_object(
178
+ "Marty",
179
+ as_lines: true,
180
+ type: :delete,
181
+ indentation_level: 1,
182
+ )
183
+ expect(tiered_lines).to match([
184
+ an_object_having_attributes(
185
+ type: :delete,
186
+ indentation_level: 1,
187
+ value: %("Marty"),
188
+ ),
189
+ ])
190
+ end
144
191
  end
145
192
  end
146
193
 
147
194
  context "given a multi-line string" do
148
195
  context "that does not contain color codes" do
149
- it "returns the string surrounded by quotes, with newline characters escaped" do
150
- inspection = described_class.inspect_object(
151
- "This is a line\nAnd that's a line\nAnd there's a line too",
152
- as_single_line: true,
153
- )
154
- expect(inspection).to eq(
155
- %("This is a line\\nAnd that's a line\\nAnd there's a line too"),
156
- )
196
+ context "given as_lines: false" do
197
+ it "returns an inspected version of the string, with newline characters escaped" do
198
+ string = described_class.inspect_object(
199
+ "This is a line\nAnd that's a line\nAnd there's a line too",
200
+ as_lines: false,
201
+ )
202
+ expect(string).to eq(
203
+ %("This is a line\\nAnd that's a line\\nAnd there's a line too"),
204
+ )
205
+ end
206
+ end
207
+
208
+ context "given as_lines: true" do
209
+ it "returns an inspected version of the string, with newline characters escaped, wrapped in a Line" do
210
+ tiered_lines = described_class.inspect_object(
211
+ "This is a line\nAnd that's a line\nAnd there's a line too",
212
+ as_lines: true,
213
+ type: :delete,
214
+ indentation_level: 1,
215
+ )
216
+ expect(tiered_lines).to match([
217
+ an_object_having_attributes(
218
+ type: :delete,
219
+ indentation_level: 1,
220
+ value: %("This is a line\\nAnd that's a line\\nAnd there's a line too"),
221
+ ),
222
+ ])
223
+ end
157
224
  end
158
225
  end
159
226
 
160
227
  context "that contains color codes" do
161
- it "escapes the color codes" do
162
- colors = [
163
- SuperDiff::Csi::FourBitColor.new(:blue, layer: :foreground),
164
- SuperDiff::Csi::EightBitColor.new(
165
- red: 3,
166
- green: 8,
167
- blue: 4,
168
- layer: :foreground,
169
- ),
170
- SuperDiff::Csi::TwentyFourBitColor.new(
171
- red: 47,
172
- green: 164,
173
- blue: 59,
174
- layer: :foreground,
175
- ),
176
- ]
177
- string_to_inspect = [
178
- colorize("This is a line", colors[0]),
179
- colorize("And that's a line", colors[1]),
180
- colorize("And there's a line too", colors[2]),
181
- ].join("\n")
228
+ context "given as_lines: false" do
229
+ it "returns an inspected version of string with the color codes escaped" do
230
+ colors = [
231
+ SuperDiff::Csi::FourBitColor.new(:blue, layer: :foreground),
232
+ SuperDiff::Csi::EightBitColor.new(
233
+ red: 3,
234
+ green: 8,
235
+ blue: 4,
236
+ layer: :foreground,
237
+ ),
238
+ SuperDiff::Csi::TwentyFourBitColor.new(
239
+ red: 47,
240
+ green: 164,
241
+ blue: 59,
242
+ layer: :foreground,
243
+ ),
244
+ ]
245
+ string_to_inspect = [
246
+ colored("This is a line", colors[0]),
247
+ colored("And that's a line", colors[1]),
248
+ colored("And there's a line too", colors[2]),
249
+ ].join("\n")
182
250
 
183
- inspection = described_class.inspect_object(
184
- string_to_inspect,
185
- as_single_line: true,
186
- )
187
- # TODO: Figure out how to represent a colorized string inside of an
188
- # already colorized string
189
- expect(inspection).to eq(<<~INSPECTION.rstrip)
190
- "\\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"
191
- INSPECTION
251
+ inspection = described_class.inspect_object(
252
+ string_to_inspect,
253
+ as_lines: false,
254
+ )
255
+ # TODO: Figure out how to represent a colorized string inside of an
256
+ # already colorized string
257
+ expect(inspection).to eq(
258
+ %("\\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"),
259
+ )
260
+ end
261
+ end
262
+
263
+ context "given as_lines: true" do
264
+ it "returns an inspected version of the string, with the color codes escaped, wrapped in a Line" do
265
+ colors = [
266
+ SuperDiff::Csi::FourBitColor.new(:blue, layer: :foreground),
267
+ SuperDiff::Csi::EightBitColor.new(
268
+ red: 3,
269
+ green: 8,
270
+ blue: 4,
271
+ layer: :foreground,
272
+ ),
273
+ SuperDiff::Csi::TwentyFourBitColor.new(
274
+ red: 47,
275
+ green: 164,
276
+ blue: 59,
277
+ layer: :foreground,
278
+ ),
279
+ ]
280
+ string_to_inspect = [
281
+ colored("This is a line", colors[0]),
282
+ colored("And that's a line", colors[1]),
283
+ colored("And there's a line too", colors[2]),
284
+ ].join("\n")
285
+
286
+ tiered_lines = described_class.inspect_object(
287
+ string_to_inspect,
288
+ as_lines: true,
289
+ type: :delete,
290
+ indentation_level: 1,
291
+ )
292
+ # TODO: Figure out how to represent a colorized string inside of an
293
+ # already colorized string
294
+ expect(tiered_lines).to match([
295
+ an_object_having_attributes(
296
+ type: :delete,
297
+ indentation_level: 1,
298
+ value: %("\\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")
299
+ ),
300
+ ])
301
+ end
192
302
  end
193
303
  end
194
304
  end
195
305
 
196
306
  context "given an array" do
197
307
  context "containing only primitive values" do
198
- context "given as_single_line: true" do
199
- it "returns a representation of the array on a single line" do
200
- inspection = described_class.inspect_object(
308
+ context "given as_lines: false" do
309
+ it "returns an inspected version of the array" do
310
+ string = described_class.inspect_object(
201
311
  ["foo", 2, :baz],
202
- as_single_line: true,
312
+ as_lines: false,
203
313
  )
204
- expect(inspection).to eq(%(["foo", 2, :baz]))
314
+ expect(string).to eq(%(["foo", 2, :baz]))
205
315
  end
206
316
  end
207
317
 
208
- context "given as_single_line: false" do
209
- it "returns a representation of the array across multiple lines" do
210
- inspection = described_class.inspect_object(
318
+ context "given as_lines: true" do
319
+ it "returns an inspected version of the array as multiple Lines" do
320
+ tiered_lines = described_class.inspect_object(
211
321
  ["foo", 2, :baz],
212
- as_single_line: false,
322
+ as_lines: true,
323
+ type: :delete,
324
+ indentation_level: 1,
213
325
  )
214
- expect(inspection).to eq(<<~INSPECTION.rstrip)
215
- [
216
- "foo",
217
- 2,
218
- :baz
219
- ]
220
- INSPECTION
326
+ expect(tiered_lines).to match([
327
+ an_object_having_attributes(
328
+ type: :delete,
329
+ indentation_level: 1,
330
+ value: %([),
331
+ collection_bookend: :open,
332
+ ),
333
+ an_object_having_attributes(
334
+ type: :delete,
335
+ indentation_level: 2,
336
+ value: %("foo"),
337
+ add_comma: true,
338
+ ),
339
+ an_object_having_attributes(
340
+ type: :delete,
341
+ indentation_level: 2,
342
+ value: %(2),
343
+ add_comma: true,
344
+ ),
345
+ an_object_having_attributes(
346
+ type: :delete,
347
+ indentation_level: 2,
348
+ value: %(:baz),
349
+ add_comma: false,
350
+ ),
351
+ an_object_having_attributes(
352
+ type: :delete,
353
+ indentation_level: 1,
354
+ value: %(]),
355
+ collection_bookend: :close,
356
+ ),
357
+ ])
221
358
  end
222
359
  end
223
360
  end
224
361
 
225
362
  context "containing other arrays" do
226
- context "given as_single_line: true" do
227
- it "returns a representation of the array on a single line" do
228
- inspection = described_class.inspect_object(
363
+ context "given as_lines: false" do
364
+ it "returns an inspected version of the array" do
365
+ string = described_class.inspect_object(
229
366
  [
230
367
  "foo",
231
368
  ["bar", "baz"],
232
369
  "qux",
233
370
  ],
234
- as_single_line: true,
371
+ as_lines: false,
235
372
  )
236
- expect(inspection).to eq(%(["foo", ["bar", "baz"], "qux"]))
373
+ expect(string).to eq(%(["foo", ["bar", "baz"], "qux"]))
237
374
  end
238
375
  end
239
376
 
240
- context "given as_single_line: false" do
241
- it "returns a representation of the array across multiple lines" do
242
- inspection = described_class.inspect_object(
377
+ context "given as_lines: true" do
378
+ it "returns an inspected version of the array as multiple Lines" do
379
+ tiered_lines = described_class.inspect_object(
243
380
  [
244
381
  "foo",
245
382
  ["bar", "baz"],
246
383
  "qux",
247
384
  ],
248
- as_single_line: false,
385
+ as_lines: true,
386
+ type: :delete,
387
+ indentation_level: 1,
249
388
  )
250
- expect(inspection).to eq(<<~INSPECTION.rstrip)
251
- [
252
- "foo",
253
- [
254
- "bar",
255
- "baz"
256
- ],
257
- "qux"
258
- ]
259
- INSPECTION
389
+ expect(tiered_lines).to match([
390
+ an_object_having_attributes(
391
+ type: :delete,
392
+ indentation_level: 1,
393
+ value: %([),
394
+ collection_bookend: :open,
395
+ ),
396
+ an_object_having_attributes(
397
+ type: :delete,
398
+ indentation_level: 2,
399
+ value: %("foo"),
400
+ add_comma: true,
401
+ ),
402
+ an_object_having_attributes(
403
+ type: :delete,
404
+ indentation_level: 2,
405
+ value: %([),
406
+ collection_bookend: :open,
407
+ ),
408
+ an_object_having_attributes(
409
+ type: :delete,
410
+ indentation_level: 3,
411
+ value: %("bar"),
412
+ add_comma: true,
413
+ ),
414
+ an_object_having_attributes(
415
+ type: :delete,
416
+ indentation_level: 3,
417
+ value: %("baz"),
418
+ add_comma: false,
419
+ ),
420
+ an_object_having_attributes(
421
+ type: :delete,
422
+ indentation_level: 2,
423
+ value: %(]),
424
+ add_comma: true,
425
+ collection_bookend: :close,
426
+ ),
427
+ an_object_having_attributes(
428
+ type: :delete,
429
+ indentation_level: 2,
430
+ value: %("qux"),
431
+ add_comma: false,
432
+ ),
433
+ an_object_having_attributes(
434
+ type: :delete,
435
+ indentation_level: 1,
436
+ value: %(]),
437
+ collection_bookend: :close,
438
+ ),
439
+ ])
260
440
  end
261
441
  end
262
442
  end
263
443
 
264
444
  context "which is empty" do
265
- context "given as_single_line: true" do
266
- it "returns a representation of the array on a single line" do
267
- inspection = described_class.inspect_object(
268
- [],
269
- as_single_line: true,
270
- )
271
- expect(inspection).to eq(%([]))
445
+ context "given as_lines: false" do
446
+ it "returns an inspected version of the array" do
447
+ string = described_class.inspect_object([], as_lines: false)
448
+ expect(string).to eq(%([]))
272
449
  end
273
450
  end
274
451
 
275
- context "given as_single_line: false" do
276
- it "returns a representation of the array on a single line" do
277
- inspection = described_class.inspect_object(
452
+ context "given as_lines: true" do
453
+ it "returns an inspected version of the array as multiple Lines" do
454
+ tiered_lines = described_class.inspect_object(
278
455
  [],
279
- as_single_line: false,
456
+ as_lines: true,
457
+ type: :delete,
458
+ indentation_level: 1,
280
459
  )
281
- expect(inspection).to eq(%([]))
460
+ expect(tiered_lines).to match([
461
+ an_object_having_attributes(
462
+ type: :delete,
463
+ indentation_level: 1,
464
+ value: %([]),
465
+ ),
466
+ ])
282
467
  end
283
468
  end
284
469
  end
@@ -287,68 +472,115 @@ RSpec.describe SuperDiff do
287
472
  context "given a hash" do
288
473
  context "containing only primitive values" do
289
474
  context "where all of the keys are symbols" do
290
- context "given as_single_line: true" do
291
- it "returns a representation of the hash on a single line" do
292
- inspection = described_class.inspect_object(
475
+ context "given as_lines: false" do
476
+ it "returns an inspected version of the hash" do
477
+ string = described_class.inspect_object(
293
478
  # rubocop:disable Style/HashSyntax
294
479
  { :foo => "bar", :baz => "qux" },
295
480
  # rubocop:enable Style/HashSyntax
296
- as_single_line: true,
481
+ as_lines: false,
297
482
  )
298
- expect(inspection).to eq(%({ foo: "bar", baz: "qux" }))
483
+ expect(string).to eq(%({ foo: "bar", baz: "qux" }))
299
484
  end
300
485
  end
301
486
 
302
- context "given as_single_line: false" do
303
- it "returns a representation of the hash across multiple lines" do
304
- inspection = described_class.inspect_object(
487
+ context "given as_lines: true" do
488
+ it "returns an inspected version of the hash as multiple Lines" do
489
+ tiered_lines = described_class.inspect_object(
305
490
  # rubocop:disable Style/HashSyntax
306
491
  { :foo => "bar", :baz => "qux" },
307
492
  # rubocop:enable Style/HashSyntax
308
- as_single_line: false,
493
+ as_lines: true,
494
+ type: :delete,
495
+ indentation_level: 1,
309
496
  )
310
- expect(inspection).to eq(<<~INSPECTION.rstrip)
311
- {
312
- foo: "bar",
313
- baz: "qux"
314
- }
315
- INSPECTION
497
+ expect(tiered_lines).to match([
498
+ an_object_having_attributes(
499
+ type: :delete,
500
+ indentation_level: 1,
501
+ value: %({),
502
+ collection_bookend: :open,
503
+ ),
504
+ an_object_having_attributes(
505
+ type: :delete,
506
+ indentation_level: 2,
507
+ prefix: %(foo: ),
508
+ value: %("bar"),
509
+ add_comma: true,
510
+ ),
511
+ an_object_having_attributes(
512
+ type: :delete,
513
+ indentation_level: 2,
514
+ prefix: %(baz: ),
515
+ value: %("qux"),
516
+ add_comma: false,
517
+ ),
518
+ an_object_having_attributes(
519
+ type: :delete,
520
+ indentation_level: 1,
521
+ value: %(}),
522
+ collection_bookend: :close,
523
+ ),
524
+ ])
316
525
  end
317
526
  end
318
527
  end
319
528
 
320
529
  context "where only some of the keys are symbols" do
321
- context "given as_single_line: true" do
322
- it "returns a representation of the hash on a single line" do
323
- inspection = described_class.inspect_object(
530
+ context "given as_lines: false" do
531
+ it "returns an inspected version of the hash" do
532
+ string = described_class.inspect_object(
324
533
  { :foo => "bar", 2 => "baz" },
325
- as_single_line: true,
534
+ as_lines: false,
326
535
  )
327
- expect(inspection).to eq(%({ :foo => "bar", 2 => "baz" }))
536
+ expect(string).to eq(%({ :foo => "bar", 2 => "baz" }))
328
537
  end
329
538
  end
330
539
 
331
- context "given as_single_line: false" do
332
- it "returns a representation of the hash across multiple lines" do
333
- inspection = described_class.inspect_object(
540
+ context "given as_lines: true" do
541
+ it "returns an inspected version of the hash as multiple Lines" do
542
+ tiered_lines = described_class.inspect_object(
334
543
  { :foo => "bar", 2 => "baz" },
335
- as_single_line: false,
544
+ as_lines: true,
545
+ type: :delete,
546
+ indentation_level: 1,
336
547
  )
337
- expect(inspection).to eq(<<~INSPECTION.rstrip)
338
- {
339
- :foo => "bar",
340
- 2 => "baz"
341
- }
342
- INSPECTION
548
+ expect(tiered_lines).to match([
549
+ an_object_having_attributes(
550
+ type: :delete,
551
+ indentation_level: 1,
552
+ value: %({),
553
+ collection_bookend: :open,
554
+ ),
555
+ an_object_having_attributes(
556
+ type: :delete,
557
+ indentation_level: 2,
558
+ prefix: %(:foo => ),
559
+ value: %("bar"),
560
+ add_comma: true,
561
+ ),
562
+ an_object_having_attributes(
563
+ type: :delete,
564
+ indentation_level: 2,
565
+ prefix: %(2 => ),
566
+ value: %("baz"),
567
+ add_comma: false,
568
+ ),
569
+ an_object_having_attributes(
570
+ type: :delete,
571
+ indentation_level: 1,
572
+ value: %(}),
573
+ collection_bookend: :close,
574
+ ),
575
+ ])
343
576
  end
344
577
  end
345
578
  end
346
579
  end
347
580
 
348
581
  context "containing other hashes" do
349
- context "given as_single_line: true" do
350
- it "returns a representation of the hash on a single line" do
351
- # TODO: Update this with a key/value pair before AND after
582
+ context "given as_lines: false" do
583
+ it "returns an inspected version of the hash" do
352
584
  value_to_inspect = {
353
585
  # rubocop:disable Style/HashSyntax
354
586
  :category_name => "Appliances",
@@ -359,20 +591,20 @@ RSpec.describe SuperDiff do
359
591
  :number_of_products => 2,
360
592
  # rubocop:enable Style/HashSyntax
361
593
  }
362
- inspection = described_class.inspect_object(
594
+ string = described_class.inspect_object(
363
595
  value_to_inspect,
364
- as_single_line: true,
596
+ as_lines: false,
365
597
  )
366
598
  # rubocop:disable Metrics/LineLength
367
- expect(inspection).to eq(
599
+ expect(string).to eq(
368
600
  %({ category_name: "Appliances", products_by_sku: { "EMDL-2934" => { id: 4, name: "Jordan Air" }, "KDS-3912" => { id: 8, name: "Chevy Impala" } }, number_of_products: 2 }),
369
601
  )
370
602
  # rubocop:enable Metrics/LineLength
371
603
  end
372
604
  end
373
605
 
374
- context "given as_single_line: false" do
375
- it "returns a representation of the array across multiple lines" do
606
+ context "given as_lines: true" do
607
+ it "returns an inspected version of the array as multiple Lines" do
376
608
  value_to_inspect = {
377
609
  # rubocop:disable Style/HashSyntax
378
610
  :category_name => "Appliances",
@@ -383,48 +615,138 @@ RSpec.describe SuperDiff do
383
615
  :number_of_products => 2,
384
616
  # rubocop:enable Style/HashSyntax
385
617
  }
386
- inspection = described_class.inspect_object(
618
+ tiered_lines = described_class.inspect_object(
387
619
  value_to_inspect,
388
- as_single_line: false,
620
+ as_lines: true,
621
+ type: :delete,
622
+ indentation_level: 1,
389
623
  )
390
- expect(inspection).to eq(<<~INSPECTION.rstrip)
391
- {
392
- category_name: "Appliances",
393
- products_by_sku: {
394
- "EMDL-2934" => {
395
- id: 4,
396
- name: "George Foreman Grill"
397
- },
398
- "KDS-3912" => {
399
- id: 8,
400
- name: "Magic Bullet"
401
- }
402
- },
403
- number_of_products: 2
404
- }
405
- INSPECTION
624
+ expect(tiered_lines).to match([
625
+ an_object_having_attributes(
626
+ type: :delete,
627
+ indentation_level: 1,
628
+ value: %({),
629
+ collection_bookend: :open,
630
+ ),
631
+ an_object_having_attributes(
632
+ type: :delete,
633
+ indentation_level: 2,
634
+ prefix: %(category_name: ),
635
+ value: %("Appliances"),
636
+ add_comma: true,
637
+ ),
638
+ an_object_having_attributes(
639
+ type: :delete,
640
+ indentation_level: 2,
641
+ prefix: %(products_by_sku: ),
642
+ value: %({),
643
+ collection_bookend: :open,
644
+ ),
645
+ an_object_having_attributes(
646
+ type: :delete,
647
+ indentation_level: 3,
648
+ prefix: %("EMDL-2934" => ),
649
+ value: %({),
650
+ collection_bookend: :open,
651
+ ),
652
+ an_object_having_attributes(
653
+ type: :delete,
654
+ indentation_level: 4,
655
+ prefix: %(id: ),
656
+ value: %(4),
657
+ add_comma: true,
658
+ ),
659
+ an_object_having_attributes(
660
+ type: :delete,
661
+ indentation_level: 4,
662
+ prefix: %(name: ),
663
+ value: %("George Foreman Grill"),
664
+ add_comma: false,
665
+ ),
666
+ an_object_having_attributes(
667
+ type: :delete,
668
+ indentation_level: 3,
669
+ prefix: "",
670
+ value: %(}),
671
+ add_comma: true,
672
+ collection_bookend: :close,
673
+ ),
674
+ an_object_having_attributes(
675
+ type: :delete,
676
+ indentation_level: 3,
677
+ prefix: %("KDS-3912" => ),
678
+ value: %({),
679
+ collection_bookend: :open,
680
+ ),
681
+ an_object_having_attributes(
682
+ type: :delete,
683
+ indentation_level: 4,
684
+ prefix: %(id: ),
685
+ value: %(8),
686
+ add_comma: true,
687
+ ),
688
+ an_object_having_attributes(
689
+ type: :delete,
690
+ indentation_level: 4,
691
+ prefix: %(name: ),
692
+ value: %("Magic Bullet"),
693
+ add_comma: false,
694
+ ),
695
+ an_object_having_attributes(
696
+ type: :delete,
697
+ indentation_level: 3,
698
+ prefix: "",
699
+ value: %(}),
700
+ collection_bookend: :close,
701
+ ),
702
+ an_object_having_attributes(
703
+ type: :delete,
704
+ indentation_level: 2,
705
+ prefix: "",
706
+ value: %(}),
707
+ add_comma: true,
708
+ collection_bookend: :close,
709
+ ),
710
+ an_object_having_attributes(
711
+ type: :delete,
712
+ indentation_level: 2,
713
+ prefix: %(number_of_products: ),
714
+ value: %(2),
715
+ ),
716
+ an_object_having_attributes(
717
+ type: :delete,
718
+ indentation_level: 1,
719
+ prefix: "",
720
+ value: %(}),
721
+ ),
722
+ ])
406
723
  end
407
724
  end
408
725
  end
409
726
 
410
727
  context "which is empty" do
411
- context "given as_single_line: true" do
412
- it "returns a representation of the array on a single line" do
413
- inspection = described_class.inspect_object(
414
- {},
415
- as_single_line: true,
416
- )
417
- expect(inspection).to eq(%({}))
728
+ context "given as_lines: false" do
729
+ it "returns an inspected version of the array" do
730
+ string = described_class.inspect_object({}, as_lines: false)
731
+ expect(string).to eq(%({}))
418
732
  end
419
733
  end
420
734
 
421
- context "given as_single_line: false" do
422
- it "returns a representation of the array on a single line" do
423
- inspection = described_class.inspect_object(
735
+ context "given as_lines: true" do
736
+ it "returns an inspected version of the array" do
737
+ tiered_lines = described_class.inspect_object(
424
738
  {},
425
- as_single_line: false,
739
+ as_lines: true,
740
+ type: :delete,
741
+ indentation_level: 1,
426
742
  )
427
- expect(inspection).to eq(%({}))
743
+ expect(tiered_lines).to match([
744
+ an_object_having_attributes(
745
+ type: :delete,
746
+ indentation_level: 1,
747
+ value: %({}),
748
+ ),
749
+ ])
428
750
  end
429
751
  end
430
752
  end
@@ -432,11 +754,11 @@ RSpec.describe SuperDiff do
432
754
 
433
755
  context "given a Time object" do
434
756
  context "that does not have an associated time zone" do
435
- context "given as_single_line: true" do
757
+ context "given as_lines: false" do
436
758
  it "returns a representation of the time on a single line" do
437
759
  inspection = described_class.inspect_object(
438
760
  Time.new(2021, 5, 5, 10, 23, 28.1234567891, "-05:00"),
439
- as_single_line: true,
761
+ as_lines: false
440
762
  )
441
763
  expect(inspection).to eq(
442
764
  "#<Time 2021-05-05 10:23:28+(34749996836695/281474976710656) -05:00>"
@@ -444,25 +766,93 @@ RSpec.describe SuperDiff do
444
766
  end
445
767
  end
446
768
 
447
- context "given as_single_line: false" do
769
+ context "given as_lines: true" do
448
770
  it "returns a representation of the time across multiple lines" do
449
771
  inspection = described_class.inspect_object(
450
772
  Time.new(2021, 5, 5, 10, 23, 28.1234567891, "-05:00"),
451
- as_single_line: false,
773
+ as_lines: true,
774
+ type: :delete,
775
+ indentation_level: 1
452
776
  )
453
- expect(inspection).to eq(<<~INSPECTION.rstrip)
454
- #<Time {
455
- year: 2021,
456
- month: 5,
457
- day: 5,
458
- hour: 10,
459
- min: 23,
460
- sec: 28,
461
- subsec: (34749996836695/281474976710656),
462
- zone: nil,
463
- utc_offset: -18000
464
- }>
465
- INSPECTION
777
+ expect(inspection).to match([
778
+ an_object_having_attributes(
779
+ type: :delete,
780
+ indentation_level: 1,
781
+ value: %(#<Time {),
782
+ add_comma: false,
783
+ collection_bookend: :open,
784
+ ),
785
+ an_object_having_attributes(
786
+ type: :delete,
787
+ indentation_level: 2,
788
+ value: %(year: 2021),
789
+ add_comma: true,
790
+ collection_bookend: nil,
791
+ ),
792
+ an_object_having_attributes(
793
+ type: :delete,
794
+ indentation_level: 2,
795
+ value: %(month: 5),
796
+ add_comma: true,
797
+ collection_bookend: nil,
798
+ ),
799
+ an_object_having_attributes(
800
+ type: :delete,
801
+ indentation_level: 2,
802
+ value: %(day: 5),
803
+ add_comma: true,
804
+ collection_bookend: nil,
805
+ ),
806
+ an_object_having_attributes(
807
+ type: :delete,
808
+ indentation_level: 2,
809
+ value: %(hour: 10),
810
+ add_comma: true,
811
+ collection_bookend: nil,
812
+ ),
813
+ an_object_having_attributes(
814
+ type: :delete,
815
+ indentation_level: 2,
816
+ value: %(min: 23),
817
+ add_comma: true,
818
+ collection_bookend: nil,
819
+ ),
820
+ an_object_having_attributes(
821
+ type: :delete,
822
+ indentation_level: 2,
823
+ value: %(sec: 28),
824
+ add_comma: true,
825
+ collection_bookend: nil,
826
+ ),
827
+ an_object_having_attributes(
828
+ type: :delete,
829
+ indentation_level: 2,
830
+ value: %(subsec: (34749996836695/281474976710656)),
831
+ add_comma: true,
832
+ collection_bookend: nil,
833
+ ),
834
+ an_object_having_attributes(
835
+ type: :delete,
836
+ indentation_level: 2,
837
+ value: %(zone: nil),
838
+ add_comma: true,
839
+ collection_bookend: nil,
840
+ ),
841
+ an_object_having_attributes(
842
+ type: :delete,
843
+ indentation_level: 2,
844
+ value: %(utc_offset: -18000),
845
+ add_comma: false,
846
+ collection_bookend: nil,
847
+ ),
848
+ an_object_having_attributes(
849
+ type: :delete,
850
+ indentation_level: 1,
851
+ value: %(}>),
852
+ add_comma: false,
853
+ collection_bookend: :close,
854
+ ),
855
+ ])
466
856
  end
467
857
  end
468
858
  end
@@ -472,11 +862,11 @@ RSpec.describe SuperDiff do
472
862
  ClimateControl.modify(TZ: 'America/Chicago', &example)
473
863
  end
474
864
 
475
- context "given as_single_line: true" do
865
+ context "given as_lines: false" do
476
866
  it "returns a representation of the time on a single line" do
477
867
  inspection = described_class.inspect_object(
478
868
  Time.new(2021, 5, 5, 10, 23, 28.1234567891),
479
- as_single_line: true,
869
+ as_lines: false
480
870
  )
481
871
  expect(inspection).to eq(
482
872
  "#<Time 2021-05-05 10:23:28+(34749996836695/281474976710656) -05:00 (CDT)>"
@@ -484,86 +874,185 @@ RSpec.describe SuperDiff do
484
874
  end
485
875
  end
486
876
 
487
- context "given as_single_line: false" do
877
+ context "given as_lines: true" do
488
878
  it "returns a representation of the time across multiple lines" do
489
879
  inspection = described_class.inspect_object(
490
880
  Time.new(2021, 5, 5, 10, 23, 28.1234567891),
491
- as_single_line: false,
881
+ as_lines: true,
882
+ type: :delete,
883
+ indentation_level: 1
492
884
  )
493
- expect(inspection).to eq(<<~INSPECTION.rstrip)
494
- #<Time {
495
- year: 2021,
496
- month: 5,
497
- day: 5,
498
- hour: 10,
499
- min: 23,
500
- sec: 28,
501
- subsec: (34749996836695/281474976710656),
502
- zone: "CDT",
503
- utc_offset: -18000
504
- }>
505
- INSPECTION
885
+ expect(inspection).to match([
886
+ an_object_having_attributes(
887
+ type: :delete,
888
+ indentation_level: 1,
889
+ value: %(#<Time {),
890
+ add_comma: false,
891
+ collection_bookend: :open,
892
+ ),
893
+ an_object_having_attributes(
894
+ type: :delete,
895
+ indentation_level: 2,
896
+ value: %(year: 2021),
897
+ add_comma: true,
898
+ collection_bookend: nil,
899
+ ),
900
+ an_object_having_attributes(
901
+ type: :delete,
902
+ indentation_level: 2,
903
+ value: %(month: 5),
904
+ add_comma: true,
905
+ collection_bookend: nil,
906
+ ),
907
+ an_object_having_attributes(
908
+ type: :delete,
909
+ indentation_level: 2,
910
+ value: %(day: 5),
911
+ add_comma: true,
912
+ collection_bookend: nil,
913
+ ),
914
+ an_object_having_attributes(
915
+ type: :delete,
916
+ indentation_level: 2,
917
+ value: %(hour: 10),
918
+ add_comma: true,
919
+ collection_bookend: nil,
920
+ ),
921
+ an_object_having_attributes(
922
+ type: :delete,
923
+ indentation_level: 2,
924
+ value: %(min: 23),
925
+ add_comma: true,
926
+ collection_bookend: nil,
927
+ ),
928
+ an_object_having_attributes(
929
+ type: :delete,
930
+ indentation_level: 2,
931
+ value: %(sec: 28),
932
+ add_comma: true,
933
+ collection_bookend: nil,
934
+ ),
935
+ an_object_having_attributes(
936
+ type: :delete,
937
+ indentation_level: 2,
938
+ value: %(subsec: (34749996836695/281474976710656)),
939
+ add_comma: true,
940
+ collection_bookend: nil,
941
+ ),
942
+ an_object_having_attributes(
943
+ type: :delete,
944
+ indentation_level: 2,
945
+ value: %(zone: "CDT"),
946
+ add_comma: true,
947
+ collection_bookend: nil,
948
+ ),
949
+ an_object_having_attributes(
950
+ type: :delete,
951
+ indentation_level: 2,
952
+ value: %(utc_offset: -18000),
953
+ add_comma: false,
954
+ collection_bookend: nil,
955
+ ),
956
+ an_object_having_attributes(
957
+ type: :delete,
958
+ indentation_level: 1,
959
+ value: %(}>),
960
+ add_comma: false,
961
+ collection_bookend: :close,
962
+ ),
963
+ ])
506
964
  end
507
965
  end
508
966
  end
509
967
  end
510
968
 
511
969
  context "given a class" do
512
- context "given as_single_line: true" do
513
- it "returns a representation of the object on a single line" do
514
- inspection = described_class.inspect_object(
970
+ context "given as_lines: false" do
971
+ it "returns an inspected version of the object" do
972
+ string = described_class.inspect_object(
515
973
  SuperDiff::Test::Person,
516
- as_single_line: true,
974
+ as_lines: false,
517
975
  )
518
- expect(inspection).to eq("SuperDiff::Test::Person")
976
+ expect(string).to eq("SuperDiff::Test::Person")
519
977
  end
520
978
  end
521
979
 
522
- context "given as_single_line: false" do
523
- it "returns a representation of the object on a single line" do
524
- inspection = described_class.inspect_object(
980
+ context "given as_lines: true" do
981
+ it "returns an inspected version of the object" do
982
+ tiered_lines = described_class.inspect_object(
525
983
  SuperDiff::Test::Person,
526
- as_single_line: false,
984
+ as_lines: true,
985
+ type: :delete,
986
+ indentation_level: 1,
527
987
  )
528
- expect(inspection).to eq("SuperDiff::Test::Person")
988
+ expect(tiered_lines).to match([
989
+ an_object_having_attributes(
990
+ type: :delete,
991
+ indentation_level: 1,
992
+ value: %(SuperDiff::Test::Person),
993
+ ),
994
+ ])
529
995
  end
530
996
  end
531
997
  end
532
998
 
999
+ # TODO: Add when empty
533
1000
  context "given a custom object" do
534
1001
  context "containing only primitive values" do
535
- context "given as_single_line: true" do
536
- it "returns a representation of the object on a single line" do
537
- inspection = described_class.inspect_object(
1002
+ context "given as_lines: false" do
1003
+ it "returns an inspected version of the object" do
1004
+ string = described_class.inspect_object(
538
1005
  SuperDiff::Test::Person.new(name: "Doc", age: 58),
539
- as_single_line: true,
1006
+ as_lines: false,
540
1007
  )
541
- expect(inspection).to eq(
1008
+ expect(string).to eq(
542
1009
  %(#<SuperDiff::Test::Person name: "Doc", age: 58>),
543
1010
  )
544
1011
  end
545
1012
  end
546
1013
 
547
- context "given as_single_line: false" do
548
- it "returns a representation of the object across multiple lines" do
549
- inspection = described_class.inspect_object(
1014
+ context "given as_lines: true" do
1015
+ it "returns an inspected version of the object as multiple Lines" do
1016
+ tiered_lines = described_class.inspect_object(
550
1017
  SuperDiff::Test::Person.new(name: "Doc", age: 58),
551
- as_single_line: false,
1018
+ as_lines: true,
1019
+ type: :delete,
1020
+ indentation_level: 1,
552
1021
  )
553
- expect(inspection).to eq(<<~INSPECTION.rstrip)
554
- #<SuperDiff::Test::Person {
555
- name: "Doc",
556
- age: 58
557
- }>
558
- INSPECTION
1022
+ expect(tiered_lines).to match([
1023
+ an_object_having_attributes(
1024
+ type: :delete,
1025
+ indentation_level: 1,
1026
+ value: %(#<SuperDiff::Test::Person {),
1027
+ ),
1028
+ an_object_having_attributes(
1029
+ type: :delete,
1030
+ indentation_level: 2,
1031
+ prefix: %(name: ),
1032
+ value: %("Doc"),
1033
+ add_comma: true,
1034
+ ),
1035
+ an_object_having_attributes(
1036
+ type: :delete,
1037
+ indentation_level: 2,
1038
+ prefix: %(age: ),
1039
+ value: %(58),
1040
+ add_comma: false,
1041
+ ),
1042
+ an_object_having_attributes(
1043
+ type: :delete,
1044
+ indentation_level: 1,
1045
+ value: %(}>),
1046
+ ),
1047
+ ])
559
1048
  end
560
1049
  end
561
1050
  end
562
1051
 
563
1052
  context "containing other custom objects" do
564
- context "given as_single_line: true" do
565
- it "returns a representation of the object on a single line" do
566
- inspection = described_class.inspect_object(
1053
+ context "given as_lines: false" do
1054
+ it "returns an inspected version of the object" do
1055
+ string = described_class.inspect_object(
567
1056
  SuperDiff::Test::Customer.new(
568
1057
  name: "Marty McFly",
569
1058
  shipping_address: SuperDiff::Test::ShippingAddress.new(
@@ -575,9 +1064,9 @@ RSpec.describe SuperDiff do
575
1064
  ),
576
1065
  phone: "111-222-3333",
577
1066
  ),
578
- as_single_line: true,
1067
+ as_lines: false,
579
1068
  )
580
- expect(inspection).to eq(
1069
+ expect(string).to eq(
581
1070
  # rubocop:disable Metrics/LineLength
582
1071
  %(#<SuperDiff::Test::Customer name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: "", city: "Hill Valley", state: "CA", zip: "90382">, phone: "111-222-3333">),
583
1072
  # rubocop:enable Metrics/LineLength
@@ -585,9 +1074,9 @@ RSpec.describe SuperDiff do
585
1074
  end
586
1075
  end
587
1076
 
588
- context "given as_single_line: false" do
589
- it "returns a representation of the object across multiple lines" do
590
- inspection = described_class.inspect_object(
1077
+ context "given as_lines: true" do
1078
+ it "returns an inspected version of the object as multiple Lines" do
1079
+ tiered_lines = described_class.inspect_object(
591
1080
  SuperDiff::Test::Customer.new(
592
1081
  name: "Marty McFly",
593
1082
  shipping_address: SuperDiff::Test::ShippingAddress.new(
@@ -599,21 +1088,88 @@ RSpec.describe SuperDiff do
599
1088
  ),
600
1089
  phone: "111-222-3333",
601
1090
  ),
602
- as_single_line: false,
1091
+ as_lines: true,
1092
+ type: :delete,
1093
+ indentation_level: 1,
603
1094
  )
604
- expect(inspection).to eq(<<~INSPECTION.rstrip)
605
- #<SuperDiff::Test::Customer {
606
- name: "Marty McFly",
607
- shipping_address: #<SuperDiff::Test::ShippingAddress {
608
- line_1: "123 Main St.",
609
- line_2: "",
610
- city: "Hill Valley",
611
- state: "CA",
612
- zip: "90382"
613
- }>,
614
- phone: "111-222-3333"
615
- }>
616
- INSPECTION
1095
+ expect(tiered_lines).to match([
1096
+ an_object_having_attributes(
1097
+ type: :delete,
1098
+ indentation_level: 1,
1099
+ value: %(#<SuperDiff::Test::Customer {),
1100
+ collection_bookend: :open,
1101
+ ),
1102
+ an_object_having_attributes(
1103
+ type: :delete,
1104
+ indentation_level: 2,
1105
+ prefix: %(name: ),
1106
+ value: %("Marty McFly"),
1107
+ add_comma: true,
1108
+ ),
1109
+ an_object_having_attributes(
1110
+ type: :delete,
1111
+ indentation_level: 2,
1112
+ prefix: %(shipping_address: ),
1113
+ value: %(#<SuperDiff::Test::ShippingAddress {),
1114
+ add_comma: false,
1115
+ collection_bookend: :open,
1116
+ ),
1117
+ an_object_having_attributes(
1118
+ type: :delete,
1119
+ indentation_level: 3,
1120
+ prefix: %(line_1: ),
1121
+ value: %("123 Main St."),
1122
+ ),
1123
+ an_object_having_attributes(
1124
+ type: :delete,
1125
+ indentation_level: 3,
1126
+ prefix: %(line_2: ),
1127
+ value: %(""),
1128
+ add_comma: true,
1129
+ ),
1130
+ an_object_having_attributes(
1131
+ type: :delete,
1132
+ indentation_level: 3,
1133
+ prefix: %(city: ),
1134
+ value: %("Hill Valley"),
1135
+ add_comma: true,
1136
+ ),
1137
+ an_object_having_attributes(
1138
+ type: :delete,
1139
+ indentation_level: 3,
1140
+ prefix: %(state: ),
1141
+ value: %("CA"),
1142
+ add_comma: true,
1143
+ ),
1144
+ an_object_having_attributes(
1145
+ type: :delete,
1146
+ indentation_level: 3,
1147
+ prefix: %(zip: ),
1148
+ value: %("90382"),
1149
+ add_comma: false,
1150
+ ),
1151
+ an_object_having_attributes(
1152
+ type: :delete,
1153
+ indentation_level: 2,
1154
+ value: %(}>),
1155
+ add_comma: true,
1156
+ collection_bookend: :close,
1157
+ ),
1158
+ an_object_having_attributes(
1159
+ type: :delete,
1160
+ indentation_level: 2,
1161
+ prefix: %(phone: ),
1162
+ value: %("111-222-3333"),
1163
+ add_comma: false,
1164
+ ),
1165
+ an_object_having_attributes(
1166
+ type: :delete,
1167
+ indentation_level: 1,
1168
+ value: %(}>),
1169
+ add_comma: false,
1170
+ collection_bookend: :close,
1171
+ ),
1172
+ ])
617
1173
  end
618
1174
  end
619
1175
  end
@@ -621,55 +1177,78 @@ RSpec.describe SuperDiff do
621
1177
 
622
1178
  context "given a non-custom object" do
623
1179
  context "containing only primitive values" do
624
- context "given as_single_line: true" do
625
- it "returns a representation of the object on a single line" do
626
- inspection = described_class.inspect_object(
1180
+ context "given as_lines: false" do
1181
+ it "returns an inspected version of the object" do
1182
+ string = described_class.inspect_object(
627
1183
  SuperDiff::Test::Item.new(
628
1184
  name: "mac and cheese",
629
1185
  quantity: 2,
630
1186
  ),
631
- as_single_line: true,
1187
+ as_lines: false,
632
1188
  )
633
- expect(inspection).to match(
634
- # rubocop:disable Metrics/LineLength
1189
+ expect(string).to match(
635
1190
  /\A#<SuperDiff::Test::Item:0x[a-z0-9]+ @name="mac and cheese", @quantity=2>\Z/,
636
- # rubocop:enable Metrics/LineLength
637
1191
  )
638
1192
  end
639
1193
  end
640
1194
 
641
- context "given as_single_line: false" do
642
- it "returns a representation of the object across multiple lines" do
643
- inspection = described_class.inspect_object(
1195
+ context "given as_lines: true" do
1196
+ it "returns an inspected version of the object as multiple Lines" do
1197
+ tiered_lines = described_class.inspect_object(
644
1198
  SuperDiff::Test::Item.new(
645
1199
  name: "mac and cheese",
646
1200
  quantity: 2,
647
1201
  ),
648
- as_single_line: false,
1202
+ as_lines: true,
1203
+ type: :delete,
1204
+ indentation_level: 1,
649
1205
  )
650
- regexp = <<~INSPECTION.rstrip
651
- #<SuperDiff::Test::Item:0x[a-z0-9]+ \{
652
- @name="mac and cheese",
653
- @quantity=2
654
- \}>
655
- INSPECTION
656
- expect(inspection).to match(/\A#{regexp}\Z/)
1206
+ expect(tiered_lines).to match([
1207
+ an_object_having_attributes(
1208
+ type: :delete,
1209
+ indentation_level: 1,
1210
+ value: a_string_matching(
1211
+ %r(#<SuperDiff::Test::Item:0x[a-f0-9]+ \{),
1212
+ ),
1213
+ collection_bookend: :open,
1214
+ ),
1215
+ an_object_having_attributes(
1216
+ type: :delete,
1217
+ indentation_level: 2,
1218
+ prefix: %(@name=),
1219
+ value: %("mac and cheese"),
1220
+ add_comma: true,
1221
+ ),
1222
+ an_object_having_attributes(
1223
+ type: :delete,
1224
+ indentation_level: 2,
1225
+ prefix: %(@quantity=),
1226
+ value: %(2),
1227
+ add_comma: false,
1228
+ ),
1229
+ an_object_having_attributes(
1230
+ type: :delete,
1231
+ indentation_level: 1,
1232
+ value: %(}>),
1233
+ collection_bookend: :close,
1234
+ ),
1235
+ ])
657
1236
  end
658
1237
  end
659
1238
  end
660
1239
 
661
1240
  context "containing other custom objects" do
662
- context "given as_single_line: true" do
663
- it "returns a representation of the object on a single line" do
664
- inspection = described_class.inspect_object(
1241
+ context "given as_lines: false" do
1242
+ it "returns an inspected version of the object" do
1243
+ string = described_class.inspect_object(
665
1244
  SuperDiff::Test::Order.new([
666
1245
  SuperDiff::Test::Item.new(name: "ham", quantity: 1),
667
1246
  SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
668
1247
  SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
669
1248
  ]),
670
- as_single_line: true,
1249
+ as_lines: false,
671
1250
  )
672
- expect(inspection).to match(
1251
+ expect(string).to match(
673
1252
  # rubocop:disable Metrics/LineLength
674
1253
  /\A#<SuperDiff::Test::Order:0x[a-z0-9]+ @items=\[#<SuperDiff::Test::Item:0x[a-z0-9]+ @name="ham", @quantity=1>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="eggs", @quantity=2>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="cheese", @quantity=1>\]>\Z/,
675
1254
  # rubocop:enable Metrics/LineLength
@@ -677,452 +1256,183 @@ RSpec.describe SuperDiff do
677
1256
  end
678
1257
  end
679
1258
 
680
- context "given as_single_line: false" do
681
- it "returns a representation of the object across multiple lines" do
682
- inspection = described_class.inspect_object(
1259
+ context "given as_lines: true" do
1260
+ it "returns an inspected version of the object as multiple Lines" do
1261
+ tiered_lines = described_class.inspect_object(
683
1262
  SuperDiff::Test::Order.new([
684
1263
  SuperDiff::Test::Item.new(name: "ham", quantity: 1),
685
1264
  SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
686
1265
  SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
687
1266
  ]),
688
- as_single_line: false,
1267
+ as_lines: true,
1268
+ type: :delete,
1269
+ indentation_level: 1,
689
1270
  )
690
- regexp = <<~INSPECTION.rstrip
691
- #<SuperDiff::Test::Order:0x[a-z0-9]+ \\{
692
- @items=\\[
693
- #<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
694
- @name="ham",
695
- @quantity=1
696
- \\}>,
697
- #<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
698
- @name="eggs",
699
- @quantity=2
700
- \\}>,
701
- #<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
702
- @name="cheese",
703
- @quantity=1
704
- \\}>
705
- \\]
706
- \\}>
707
- INSPECTION
708
- expect(inspection).to match(/\A#{regexp}\Z/)
1271
+ expect(tiered_lines).to match([
1272
+ an_object_having_attributes(
1273
+ type: :delete,
1274
+ indentation_level: 1,
1275
+ value: a_string_matching(
1276
+ %r(#<SuperDiff::Test::Order:0x[a-f0-9]+ \{),
1277
+ ),
1278
+ collection_bookend: :open,
1279
+ ),
1280
+ an_object_having_attributes(
1281
+ type: :delete,
1282
+ indentation_level: 2,
1283
+ prefix: %(@items=),
1284
+ value: %([),
1285
+ add_comma: false,
1286
+ collection_bookend: :open,
1287
+ ),
1288
+ an_object_having_attributes(
1289
+ type: :delete,
1290
+ indentation_level: 3,
1291
+ value: a_string_matching(
1292
+ %r(#<SuperDiff::Test::Item:0x[a-f0-9]+ \{),
1293
+ ),
1294
+ add_comma: false,
1295
+ collection_bookend: :open,
1296
+ ),
1297
+ an_object_having_attributes(
1298
+ type: :delete,
1299
+ indentation_level: 4,
1300
+ prefix: %(@name=),
1301
+ value: %("ham"),
1302
+ add_comma: true,
1303
+ ),
1304
+ an_object_having_attributes(
1305
+ type: :delete,
1306
+ indentation_level: 4,
1307
+ prefix: %(@quantity=),
1308
+ value: %(1),
1309
+ add_comma: false,
1310
+ ),
1311
+ an_object_having_attributes(
1312
+ type: :delete,
1313
+ indentation_level: 3,
1314
+ value: %(}>),
1315
+ add_comma: true,
1316
+ collection_bookend: :close,
1317
+ ),
1318
+ an_object_having_attributes(
1319
+ type: :delete,
1320
+ indentation_level: 3,
1321
+ value: a_string_matching(
1322
+ %r(#<SuperDiff::Test::Item:0x[a-f0-9]+ \{),
1323
+ ),
1324
+ add_comma: false,
1325
+ collection_bookend: :open,
1326
+ ),
1327
+ an_object_having_attributes(
1328
+ type: :delete,
1329
+ indentation_level: 4,
1330
+ prefix: %(@name=),
1331
+ value: %("eggs"),
1332
+ add_comma: true,
1333
+ ),
1334
+ an_object_having_attributes(
1335
+ type: :delete,
1336
+ indentation_level: 4,
1337
+ prefix: %(@quantity=),
1338
+ value: %(2),
1339
+ add_comma: false,
1340
+ ),
1341
+ an_object_having_attributes(
1342
+ type: :delete,
1343
+ indentation_level: 3,
1344
+ value: %(}>),
1345
+ add_comma: true,
1346
+ collection_bookend: :close,
1347
+ ),
1348
+ an_object_having_attributes(
1349
+ type: :delete,
1350
+ indentation_level: 3,
1351
+ value: a_string_matching(
1352
+ %r(#<SuperDiff::Test::Item:0x[a-f0-9]+ \{),
1353
+ ),
1354
+ add_comma: false,
1355
+ collection_bookend: :open,
1356
+ ),
1357
+ an_object_having_attributes(
1358
+ type: :delete,
1359
+ indentation_level: 4,
1360
+ prefix: %(@name=),
1361
+ value: %("cheese"),
1362
+ add_comma: true,
1363
+ ),
1364
+ an_object_having_attributes(
1365
+ type: :delete,
1366
+ indentation_level: 4,
1367
+ prefix: %(@quantity=),
1368
+ value: %(1),
1369
+ add_comma: false,
1370
+ ),
1371
+ an_object_having_attributes(
1372
+ type: :delete,
1373
+ indentation_level: 3,
1374
+ value: %(}>),
1375
+ add_comma: false,
1376
+ collection_bookend: :close,
1377
+ ),
1378
+ an_object_having_attributes(
1379
+ type: :delete,
1380
+ indentation_level: 2,
1381
+ value: %(]),
1382
+ add_comma: false,
1383
+ collection_bookend: :close,
1384
+ ),
1385
+ an_object_having_attributes(
1386
+ type: :delete,
1387
+ indentation_level: 1,
1388
+ value: %(}>),
1389
+ add_comma: false,
1390
+ collection_bookend: :close,
1391
+ ),
1392
+ ])
709
1393
  end
710
1394
  end
711
1395
  end
712
1396
 
713
1397
  context "which is empty" do
714
- context "given as_single_line: true" do
715
- it "returns a representation of the array on a single line" do
716
- inspection = described_class.inspect_object(
1398
+ context "given as_lines: false" do
1399
+ it "returns an inspected version of the array" do
1400
+ string = described_class.inspect_object(
717
1401
  SuperDiff::Test::EmptyClass.new,
718
- as_single_line: true,
1402
+ as_lines: false,
719
1403
  )
720
- expect(inspection).to match(
1404
+ expect(string).to match(
721
1405
  /#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/,
722
1406
  )
723
1407
  end
724
1408
  end
725
1409
 
726
- context "given as_single_line: false" do
727
- it "returns a representation of the array on a single line" do
1410
+ context "given as_lines: true" do
1411
+ it "returns an inspected version of the array" do
728
1412
  inspection = described_class.inspect_object(
729
1413
  SuperDiff::Test::EmptyClass.new,
730
- as_single_line: false,
731
- )
732
- expect(inspection).to match(
733
- /#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/,
734
- )
735
- end
736
- end
737
- end
738
- end
739
-
740
- context "given a hash-including-<something>" do
741
- context "given as_single_line: true" do
742
- it "returns a representation of the object on a single line" do
743
- inspection = described_class.inspect_object(
744
- a_hash_including(foo: "bar", baz: "qux"),
745
- as_single_line: true,
746
- )
747
-
748
- expect(inspection).to eq(
749
- %(#<a hash including (foo: "bar", baz: "qux")>),
750
- )
751
- end
752
- end
753
-
754
- context "given as_single_line: false" do
755
- it "returns a representation of the object across multiple lines" do
756
- inspection = described_class.inspect_object(
757
- a_hash_including(foo: "bar", baz: "qux"),
758
- as_single_line: false,
759
- )
760
-
761
- expect(inspection).to eq(<<~INSPECTION.rstrip)
762
- #<a hash including (
763
- foo: "bar",
764
- baz: "qux"
765
- )>
766
- INSPECTION
767
- end
768
- end
769
- end
770
-
771
- context "given a collection-including-<something>" do
772
- context "given as_single_line: true" do
773
- it "returns a representation of the object on a single line" do
774
- inspection = described_class.inspect_object(
775
- a_collection_including(1, 2, 3),
776
- as_single_line: true,
777
- )
778
-
779
- expect(inspection).to eq(
780
- %(#<a collection including (1, 2, 3)>),
781
- )
782
- end
783
- end
784
-
785
- context "given as_single_line: false" do
786
- it "returns a representation of the object across multiple lines" do
787
- inspection = described_class.inspect_object(
788
- a_collection_including(1, 2, 3),
789
- as_single_line: false,
790
- )
791
-
792
- expect(inspection).to eq(<<~INSPECTION.rstrip)
793
- #<a collection including (
794
- 1,
795
- 2,
796
- 3
797
- )>
798
- INSPECTION
799
- end
800
- end
801
- end
802
-
803
- context "given a fuzzy object" do
804
- context "given as_single_line: true" do
805
- it "returns a representation of the object on a single line" do
806
- inspection = described_class.inspect_object(
807
- an_object_having_attributes(foo: "bar", baz: "qux"),
808
- as_single_line: true,
809
- )
810
-
811
- expect(inspection).to eq(
812
- %(#<an object having attributes (foo: "bar", baz: "qux")>),
813
- )
814
- end
815
- end
816
-
817
- context "given as_single_line: false" do
818
- it "returns a representation of the object across multiple lines" do
819
- inspection = described_class.inspect_object(
820
- an_object_having_attributes(foo: "bar", baz: "qux"),
821
- as_single_line: false,
822
- )
823
-
824
- expect(inspection).to eq(<<~INSPECTION.rstrip)
825
- #<an object having attributes (
826
- foo: "bar",
827
- baz: "qux"
828
- )>
829
- INSPECTION
830
- end
831
- end
832
- end
833
-
834
- context "given a collection-containing-exactly-<something>" do
835
- context "given as_single_line: true" do
836
- it "returns a representation of the object on a single line" do
837
- inspection = described_class.inspect_object(
838
- a_collection_containing_exactly("foo", "bar", "baz"),
839
- as_single_line: true,
840
- )
841
-
842
- expect(inspection).to eq(
843
- %(#<a collection containing exactly ("foo", "bar", "baz")>),
844
- )
845
- end
846
- end
847
-
848
- context "given as_single_line: false" do
849
- it "returns a representation of the object across multiple lines" do
850
- inspection = described_class.inspect_object(
851
- a_collection_containing_exactly("foo", "bar", "baz"),
852
- as_single_line: false,
853
- )
854
-
855
- expect(inspection).to eq(<<~INSPECTION.rstrip)
856
- #<a collection containing exactly (
857
- "foo",
858
- "bar",
859
- "baz"
860
- )>
861
- INSPECTION
862
- end
863
- end
864
- end
865
-
866
- context "given a kind-of-<something>" do
867
- context "given as_single_line: true" do
868
- it "returns a representation of the object on a single line" do
869
- inspection = described_class.inspect_object(
870
- a_kind_of(Symbol),
871
- as_single_line: true,
872
- )
873
-
874
- expect(inspection).to eq(%(#<a kind of Symbol>))
875
- end
876
- end
877
-
878
- context "given as_single_line: false" do
879
- it "returns a representation of the object on a single line" do
880
- inspection = described_class.inspect_object(
881
- a_kind_of(Symbol),
882
- as_single_line: false,
883
- )
884
-
885
- expect(inspection).to eq(%(#<a kind of Symbol>))
886
- end
887
- end
888
- end
889
-
890
- context "given an-instance-of-<something>" do
891
- context "given as_single_line: true" do
892
- it "returns a representation of the object on a single line" do
893
- inspection = described_class.inspect_object(
894
- an_instance_of(Symbol),
895
- as_single_line: true,
896
- )
897
-
898
- expect(inspection).to eq(%(#<an instance of Symbol>))
899
- end
900
- end
901
-
902
- context "given as_single_line: false" do
903
- it "returns a representation of the object on a single line" do
904
- inspection = described_class.inspect_object(
905
- an_instance_of(Symbol),
906
- as_single_line: false,
907
- )
908
-
909
- expect(inspection).to eq(%(#<an instance of Symbol>))
910
- end
911
- end
912
- end
913
-
914
- context "given a-value-within-<something>" do
915
- context "given as_single_line: true" do
916
- it "returns a representation of the object on a single line" do
917
- inspection = described_class.inspect_object(
918
- a_value_within(1).of(Time.utc(2020, 4, 9)),
919
- as_single_line: true,
920
- )
921
-
922
- expect(inspection).to eq(
923
- %(#<a value within 1 of #<Time 2020-04-09 00:00:00 +00:00 (UTC)>>),
924
- )
925
- end
926
- end
927
-
928
- context "given as_single_line: false" do
929
- it "returns a representation of the object across multiple lines" do
930
- inspection = described_class.inspect_object(
931
- a_value_within(1).of(Time.utc(2020, 4, 9)),
932
- as_single_line: false,
933
- )
934
-
935
- expect(inspection).to eq(<<~INSPECTION.rstrip)
936
- #<a value within 1 of #<Time {
937
- year: 2020,
938
- month: 4,
939
- day: 9,
940
- hour: 0,
941
- min: 0,
942
- sec: 0,
943
- subsec: 0,
944
- zone: "UTC",
945
- utc_offset: 0
946
- }>>
947
- INSPECTION
948
- end
949
- end
950
- end
951
-
952
- context "given a Double" do
953
- context "that is anonymous" do
954
- context "given as_single_line: true" do
955
- it "returns a representation of the object on a single line" do
956
- inspection = described_class.inspect_object(
957
- double(foo: "bar", baz: "qux"),
958
- as_single_line: true,
959
- )
960
-
961
- expect(inspection).to eq("#<Double (anonymous)>")
962
- end
963
- end
964
-
965
- context "given as_single_line: false" do
966
- it "returns a representation of the object across multiple lines" do
967
- inspection = described_class.inspect_object(
968
- double(foo: "bar", baz: "qux"),
969
- as_single_line: false,
1414
+ as_lines: true,
1415
+ type: :delete,
1416
+ indentation_level: 1
970
1417
  )
971
-
972
- expect(inspection).to eq("#<Double (anonymous)>")
1418
+ expect(inspection).to match([
1419
+ an_object_having_attributes(
1420
+ type: :delete,
1421
+ indentation_level: 1,
1422
+ value: a_string_matching(
1423
+ /#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/
1424
+ ),
1425
+ )
1426
+ ])
973
1427
  end
974
1428
  end
975
1429
  end
976
1430
  end
977
1431
 
978
- context "given an ActiveRecord object", active_record: true do
979
- context "given as_single_line: true" do
980
- it "returns a representation of the object on a single line" do
981
- inspection = described_class.inspect_object(
982
- SuperDiff::Test::Models::ActiveRecord::Person.new(
983
- name: "Elliot",
984
- age: 31,
985
- ),
986
- as_single_line: true,
987
- )
988
-
989
- # rubocop:disable Metrics/LineLength
990
- expect(inspection).to eq(
991
- %(#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">),
992
- )
993
- # rubocop:enable Metrics/LineLength
994
- end
995
- end
996
-
997
- context "given as_single_line: false" do
998
- it "returns a representation of the object across multiple lines" do
999
- inspection = described_class.inspect_object(
1000
- SuperDiff::Test::Models::ActiveRecord::Person.new(
1001
- name: "Elliot",
1002
- age: 31,
1003
- ),
1004
- as_single_line: false,
1005
- )
1006
-
1007
- expect(inspection).to eq(<<~INSPECTION.rstrip)
1008
- #<SuperDiff::Test::Models::ActiveRecord::Person {
1009
- id: nil,
1010
- age: 31,
1011
- name: "Elliot"
1012
- }>
1013
- INSPECTION
1014
- end
1015
- end
1016
- end
1017
-
1018
- context "given an ActiveRecord::Relation object", active_record: true do
1019
- context "given as_single_line: true" do
1020
- it "returns a representation of the Relation on a single line" do
1021
- SuperDiff::Test::Models::ActiveRecord::Person.create!(
1022
- name: "Marty",
1023
- age: 19,
1024
- )
1025
- SuperDiff::Test::Models::ActiveRecord::Person.create!(
1026
- name: "Jennifer",
1027
- age: 17,
1028
- )
1029
-
1030
- inspection = described_class.inspect_object(
1031
- SuperDiff::Test::Models::ActiveRecord::Person.all,
1032
- as_single_line: true,
1033
- )
1034
-
1035
- # rubocop:disable Metrics/LineLength
1036
- expect(inspection).to eq(
1037
- %(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person id: 2, age: 17, name: "Jennifer">]>),
1038
- )
1039
- # rubocop:enable Metrics/LineLength
1040
- end
1041
- end
1042
-
1043
- context "given as_single_line: false" do
1044
- it "returns a representation of the Relation across multiple lines" do
1045
- SuperDiff::Test::Models::ActiveRecord::Person.create!(
1046
- name: "Marty",
1047
- age: 19,
1048
- )
1049
- SuperDiff::Test::Models::ActiveRecord::Person.create!(
1050
- name: "Jennifer",
1051
- age: 17,
1052
- )
1053
-
1054
- inspection = described_class.inspect_object(
1055
- SuperDiff::Test::Models::ActiveRecord::Person.all,
1056
- as_single_line: false,
1057
- )
1058
-
1059
- expect(inspection).to eq(<<~INSPECTION.rstrip)
1060
- #<ActiveRecord::Relation [
1061
- #<SuperDiff::Test::Models::ActiveRecord::Person {
1062
- id: 1,
1063
- age: 19,
1064
- name: "Marty"
1065
- }>,
1066
- #<SuperDiff::Test::Models::ActiveRecord::Person {
1067
- id: 2,
1068
- age: 17,
1069
- name: "Jennifer"
1070
- }>
1071
- ]>
1072
- INSPECTION
1073
- end
1074
- end
1075
- end
1076
-
1077
- context "given a HashWithIndifferentAccess", active_record: true do
1078
- context "given as_single_line: true" do
1079
- it "returns a representation of the object on a single line" do
1080
- inspection = described_class.inspect_object(
1081
- HashWithIndifferentAccess.new({
1082
- line_1: "123 Main St.",
1083
- city: "Hill Valley",
1084
- state: "CA",
1085
- zip: "90382",
1086
- }),
1087
- as_single_line: true,
1088
- )
1089
-
1090
- # rubocop:disable Metrics/LineLength
1091
- expect(inspection).to eq(
1092
- %(#<HashWithIndifferentAccess { "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }>),
1093
- )
1094
- # rubocop:enable Metrics/LineLength
1095
- end
1096
- end
1097
-
1098
- context "given as_single_line: false" do
1099
- it "returns a representation of the object across multiple lines" do
1100
- inspection = described_class.inspect_object(
1101
- HashWithIndifferentAccess.new({
1102
- line_1: "123 Main St.",
1103
- city: "Hill Valley",
1104
- state: "CA",
1105
- zip: "90382",
1106
- }),
1107
- as_single_line: false,
1108
- )
1109
-
1110
- expect(inspection).to eq(<<~INSPECTION.rstrip)
1111
- #<HashWithIndifferentAccess {
1112
- "line_1" => "123 Main St.",
1113
- "city" => "Hill Valley",
1114
- "state" => "CA",
1115
- "zip" => "90382"
1116
- }>
1117
- INSPECTION
1118
- end
1119
- end
1120
- end
1121
-
1122
1432
  context "given a combination of all kinds of values" do
1123
- context "given as_single_line: true" do
1124
- it "returns a representation of the object on a single line" do
1125
- inspection = described_class.inspect_object(
1433
+ context "given as_lines: false" do
1434
+ it "returns an inspected version of the object" do
1435
+ string = described_class.inspect_object(
1126
1436
  {
1127
1437
  state: :down,
1128
1438
  errors: [
@@ -1164,9 +1474,9 @@ RSpec.describe SuperDiff do
1164
1474
  ),
1165
1475
  ],
1166
1476
  },
1167
- as_single_line: true,
1477
+ as_lines: false,
1168
1478
  )
1169
- expect(inspection).to match(
1479
+ expect(string).to match(
1170
1480
  # rubocop:disable Metrics/LineLength
1171
1481
  /\A\{ state: :down, errors: \["Container A-234 is partially damaged", "Vessel B042 was attacked by raccoons", "Product FDK-3429 is out of stock"\], mission_critical: true, serviceable: false, outstanding_orders: \[#<SuperDiff::Test::Order:0x[a-z0-9]+ @items=\[#<SuperDiff::Test::Item:0x[a-z0-9]+ @name="ham", @quantity=1>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="eggs", @quantity=2>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="cheese", @quantity=1>\]>\], customers: \[#<SuperDiff::Test::Customer name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "123 Baltic Ave.", line_2: "", city: "Hill Valley", state: "CA", zip: "90382">, phone: "111-111-1111">, #<SuperDiff::Test::Customer name: "Doc Brown", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "456 Park Place", line_2: "", city: "Beverly Hills", state: "CA", zip: "90210">, phone: "222-222-2222">\] \}\Z/,
1172
1482
  # rubocop:enable Metrics/LineLength
@@ -1174,9 +1484,9 @@ RSpec.describe SuperDiff do
1174
1484
  end
1175
1485
  end
1176
1486
 
1177
- context "given as_single_line: false" do
1178
- it "returns a representation of the object across multiple lines" do
1179
- inspection = described_class.inspect_object(
1487
+ context "given as_lines: true" do
1488
+ it "returns an inspected version of the object as multiple Lines" do
1489
+ tiered_lines = described_class.inspect_object(
1180
1490
  {
1181
1491
  state: :down,
1182
1492
  errors: [
@@ -1218,99 +1528,431 @@ RSpec.describe SuperDiff do
1218
1528
  ),
1219
1529
  ],
1220
1530
  },
1221
- as_single_line: false,
1531
+ as_lines: true,
1532
+ type: :delete,
1533
+ indentation_level: 1,
1222
1534
  )
1223
- regexp = <<~INSPECTION.rstrip
1224
- \\{
1225
- state: :down,
1226
- errors: \\[
1227
- "Container A-234 is partially damaged",
1228
- "Vessel B042 was attacked by raccoons",
1229
- "Product FDK-3429 is out of stock"
1230
- \\],
1231
- mission_critical: true,
1232
- serviceable: false,
1233
- outstanding_orders: \\[
1234
- #<SuperDiff::Test::Order:0x[a-z0-9]+ \\{
1235
- @items=\\[
1236
- #<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
1237
- @name="ham",
1238
- @quantity=1
1239
- \\}>,
1240
- #<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
1241
- @name="eggs",
1242
- @quantity=2
1243
- \\}>,
1244
- #<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
1245
- @name="cheese",
1246
- @quantity=1
1247
- \\}>
1248
- \\]
1249
- \\}>
1250
- \\],
1251
- customers: \\[
1252
- #<SuperDiff::Test::Customer \\{
1253
- name: "Marty McFly",
1254
- shipping_address: #<SuperDiff::Test::ShippingAddress \\{
1255
- line_1: "123 Baltic Ave.",
1256
- line_2: "",
1257
- city: "Hill Valley",
1258
- state: "CA",
1259
- zip: "90382"
1260
- \\}>,
1261
- phone: "111-111-1111"
1262
- \\}>,
1263
- #<SuperDiff::Test::Customer \\{
1264
- name: "Doc Brown",
1265
- shipping_address: #<SuperDiff::Test::ShippingAddress \\{
1266
- line_1: "456 Park Place",
1267
- line_2: "",
1268
- city: "Beverly Hills",
1269
- state: "CA",
1270
- zip: "90210"
1271
- \\}>,
1272
- phone: "222-222-2222"
1273
- \\}>
1274
- \\]
1275
- \\}
1276
- INSPECTION
1277
- expect(inspection).to match(/\A#{regexp}\Z/)
1535
+ expect(tiered_lines).to match([
1536
+ an_object_having_attributes(
1537
+ type: :delete,
1538
+ indentation_level: 1,
1539
+ value: %({),
1540
+ collection_bookend: :open,
1541
+ ),
1542
+ an_object_having_attributes(
1543
+ type: :delete,
1544
+ indentation_level: 2,
1545
+ prefix: %(state: ),
1546
+ value: %(:down),
1547
+ add_comma: true,
1548
+ ),
1549
+ an_object_having_attributes(
1550
+ type: :delete,
1551
+ indentation_level: 2,
1552
+ prefix: %(errors: ),
1553
+ value: %([),
1554
+ collection_bookend: :open,
1555
+ ),
1556
+ an_object_having_attributes(
1557
+ type: :delete,
1558
+ indentation_level: 3,
1559
+ value: %("Container A-234 is partially damaged"),
1560
+ add_comma: true,
1561
+ ),
1562
+ an_object_having_attributes(
1563
+ type: :delete,
1564
+ indentation_level: 3,
1565
+ value: %("Vessel B042 was attacked by raccoons"),
1566
+ add_comma: true,
1567
+ ),
1568
+ an_object_having_attributes(
1569
+ type: :delete,
1570
+ indentation_level: 3,
1571
+ value: %("Product FDK-3429 is out of stock"),
1572
+ add_comma: false,
1573
+ ),
1574
+ an_object_having_attributes(
1575
+ type: :delete,
1576
+ indentation_level: 2,
1577
+ value: %(]),
1578
+ collection_bookend: :close,
1579
+ ),
1580
+ an_object_having_attributes(
1581
+ type: :delete,
1582
+ indentation_level: 2,
1583
+ prefix: %(mission_critical: ),
1584
+ value: %(true),
1585
+ add_comma: true,
1586
+ ),
1587
+ an_object_having_attributes(
1588
+ type: :delete,
1589
+ indentation_level: 2,
1590
+ prefix: %(serviceable: ),
1591
+ value: %(false),
1592
+ add_comma: true,
1593
+ ),
1594
+ an_object_having_attributes(
1595
+ type: :delete,
1596
+ indentation_level: 2,
1597
+ prefix: %(outstanding_orders: ),
1598
+ value: %([),
1599
+ collection_bookend: :open,
1600
+ ),
1601
+ an_object_having_attributes(
1602
+ type: :delete,
1603
+ indentation_level: 3,
1604
+ value: a_string_matching(
1605
+ %r(#<SuperDiff::Test::Order:0x[a-f0-9]+ \{),
1606
+ ),
1607
+ collection_bookend: :open,
1608
+ ),
1609
+ an_object_having_attributes(
1610
+ type: :delete,
1611
+ indentation_level: 4,
1612
+ prefix: %(@items=),
1613
+ value: %([),
1614
+ collection_bookend: :open,
1615
+ ),
1616
+ an_object_having_attributes(
1617
+ type: :delete,
1618
+ indentation_level: 5,
1619
+ value: a_string_matching(
1620
+ %r(#<SuperDiff::Test::Item:0x[a-f0-9]+ \{),
1621
+ ),
1622
+ collection_bookend: :open,
1623
+ ),
1624
+ an_object_having_attributes(
1625
+ type: :delete,
1626
+ indentation_level: 6,
1627
+ prefix: %(@name=),
1628
+ value: %("ham"),
1629
+ add_comma: true,
1630
+ ),
1631
+ an_object_having_attributes(
1632
+ type: :delete,
1633
+ indentation_level: 6,
1634
+ prefix: %(@quantity=),
1635
+ value: %(1),
1636
+ add_comma: false,
1637
+ ),
1638
+ an_object_having_attributes(
1639
+ type: :delete,
1640
+ indentation_level: 5,
1641
+ value: %(}>),
1642
+ collection_bookend: :close,
1643
+ ),
1644
+ an_object_having_attributes(
1645
+ type: :delete,
1646
+ indentation_level: 5,
1647
+ value: a_string_matching(
1648
+ %r(#<SuperDiff::Test::Item:0x[a-f0-9]+ \{),
1649
+ ),
1650
+ collection_bookend: :open,
1651
+ ),
1652
+ an_object_having_attributes(
1653
+ type: :delete,
1654
+ indentation_level: 6,
1655
+ prefix: %(@name=),
1656
+ value: %("eggs"),
1657
+ add_comma: true,
1658
+ ),
1659
+ an_object_having_attributes(
1660
+ type: :delete,
1661
+ indentation_level: 6,
1662
+ prefix: %(@quantity=),
1663
+ value: %(2),
1664
+ add_comma: false,
1665
+ ),
1666
+ an_object_having_attributes(
1667
+ type: :delete,
1668
+ indentation_level: 5,
1669
+ value: %(}>),
1670
+ collection_bookend: :close,
1671
+ ),
1672
+ an_object_having_attributes(
1673
+ type: :delete,
1674
+ indentation_level: 5,
1675
+ value: a_string_matching(
1676
+ %r(#<SuperDiff::Test::Item:0x[a-f0-9]+ \{),
1677
+ ),
1678
+ collection_bookend: :open,
1679
+ ),
1680
+ an_object_having_attributes(
1681
+ type: :delete,
1682
+ indentation_level: 6,
1683
+ prefix: %(@name=),
1684
+ value: %("cheese"),
1685
+ add_comma: true,
1686
+ ),
1687
+ an_object_having_attributes(
1688
+ type: :delete,
1689
+ indentation_level: 6,
1690
+ prefix: %(@quantity=),
1691
+ value: %(1),
1692
+ add_comma: false,
1693
+ ),
1694
+ an_object_having_attributes(
1695
+ type: :delete,
1696
+ indentation_level: 5,
1697
+ value: %(}>),
1698
+ collection_bookend: :close,
1699
+ ),
1700
+ an_object_having_attributes(
1701
+ type: :delete,
1702
+ indentation_level: 4,
1703
+ value: %(]),
1704
+ collection_bookend: :close,
1705
+ ),
1706
+ an_object_having_attributes(
1707
+ type: :delete,
1708
+ indentation_level: 3,
1709
+ value: %(}>),
1710
+ collection_bookend: :close,
1711
+ ),
1712
+ an_object_having_attributes(
1713
+ type: :delete,
1714
+ indentation_level: 2,
1715
+ value: %(]),
1716
+ collection_bookend: :close,
1717
+ ),
1718
+ an_object_having_attributes(
1719
+ type: :delete,
1720
+ indentation_level: 2,
1721
+ prefix: %(customers: ),
1722
+ value: %([),
1723
+ collection_bookend: :open,
1724
+ ),
1725
+ an_object_having_attributes(
1726
+ type: :delete,
1727
+ indentation_level: 3,
1728
+ value: %(#<SuperDiff::Test::Customer {),
1729
+ collection_bookend: :open,
1730
+ ),
1731
+ an_object_having_attributes(
1732
+ type: :delete,
1733
+ indentation_level: 4,
1734
+ prefix: %(name: ),
1735
+ value: %("Marty McFly"),
1736
+ add_comma: true,
1737
+ ),
1738
+ an_object_having_attributes(
1739
+ type: :delete,
1740
+ indentation_level: 4,
1741
+ prefix: %(shipping_address: ),
1742
+ value: %(#<SuperDiff::Test::ShippingAddress {),
1743
+ collection_bookend: :open,
1744
+ ),
1745
+ an_object_having_attributes(
1746
+ type: :delete,
1747
+ indentation_level: 5,
1748
+ prefix: %(line_1: ),
1749
+ value: %("123 Baltic Ave."),
1750
+ add_comma: true,
1751
+ ),
1752
+ an_object_having_attributes(
1753
+ type: :delete,
1754
+ indentation_level: 5,
1755
+ prefix: %(line_2: ),
1756
+ value: %(""),
1757
+ add_comma: true,
1758
+ ),
1759
+ an_object_having_attributes(
1760
+ type: :delete,
1761
+ indentation_level: 5,
1762
+ prefix: %(city: ),
1763
+ value: %("Hill Valley"),
1764
+ add_comma: true,
1765
+ ),
1766
+ an_object_having_attributes(
1767
+ type: :delete,
1768
+ indentation_level: 5,
1769
+ prefix: %(state: ),
1770
+ value: %("CA"),
1771
+ add_comma: true,
1772
+ ),
1773
+ an_object_having_attributes(
1774
+ type: :delete,
1775
+ indentation_level: 5,
1776
+ prefix: %(zip: ),
1777
+ value: %("90382"),
1778
+ add_comma: false,
1779
+ ),
1780
+ an_object_having_attributes(
1781
+ type: :delete,
1782
+ indentation_level: 4,
1783
+ value: %(}>),
1784
+ add_comma: true,
1785
+ collection_bookend: :close,
1786
+ ),
1787
+ an_object_having_attributes(
1788
+ type: :delete,
1789
+ indentation_level: 4,
1790
+ prefix: %(phone: ),
1791
+ value: %("111-111-1111"),
1792
+ add_comma: false,
1793
+ ),
1794
+ an_object_having_attributes(
1795
+ type: :delete,
1796
+ indentation_level: 3,
1797
+ value: %(}>),
1798
+ add_comma: true,
1799
+ ),
1800
+ an_object_having_attributes(
1801
+ type: :delete,
1802
+ indentation_level: 3,
1803
+ value: %(#<SuperDiff::Test::Customer {),
1804
+ collection_bookend: :open,
1805
+ ),
1806
+ an_object_having_attributes(
1807
+ type: :delete,
1808
+ indentation_level: 4,
1809
+ prefix: %(name: ),
1810
+ value: %("Doc Brown"),
1811
+ add_comma: true,
1812
+ ),
1813
+ an_object_having_attributes(
1814
+ type: :delete,
1815
+ indentation_level: 4,
1816
+ prefix: %(shipping_address: ),
1817
+ value: %(#<SuperDiff::Test::ShippingAddress {),
1818
+ collection_bookend: :open,
1819
+ ),
1820
+ an_object_having_attributes(
1821
+ type: :delete,
1822
+ indentation_level: 5,
1823
+ prefix: %(line_1: ),
1824
+ value: %("456 Park Place"),
1825
+ add_comma: true,
1826
+ ),
1827
+ an_object_having_attributes(
1828
+ type: :delete,
1829
+ indentation_level: 5,
1830
+ prefix: %(line_2: ),
1831
+ value: %(""),
1832
+ add_comma: true,
1833
+ ),
1834
+ an_object_having_attributes(
1835
+ type: :delete,
1836
+ indentation_level: 5,
1837
+ prefix: %(city: ),
1838
+ value: %("Beverly Hills"),
1839
+ add_comma: true,
1840
+ ),
1841
+ an_object_having_attributes(
1842
+ type: :delete,
1843
+ indentation_level: 5,
1844
+ prefix: %(state: ),
1845
+ value: %("CA"),
1846
+ add_comma: true,
1847
+ ),
1848
+ an_object_having_attributes(
1849
+ type: :delete,
1850
+ indentation_level: 5,
1851
+ prefix: %(zip: ),
1852
+ value: %("90210"),
1853
+ add_comma: false,
1854
+ ),
1855
+ an_object_having_attributes(
1856
+ type: :delete,
1857
+ indentation_level: 4,
1858
+ value: %(}>),
1859
+ add_comma: true,
1860
+ collection_bookend: :close,
1861
+ ),
1862
+ an_object_having_attributes(
1863
+ type: :delete,
1864
+ indentation_level: 4,
1865
+ prefix: %(phone: ),
1866
+ value: %("222-222-2222"),
1867
+ add_comma: false,
1868
+ ),
1869
+ an_object_having_attributes(
1870
+ type: :delete,
1871
+ indentation_level: 3,
1872
+ value: %(}>),
1873
+ add_comma: false,
1874
+ collection_bookend: :close,
1875
+ ),
1876
+ an_object_having_attributes(
1877
+ type: :delete,
1878
+ indentation_level: 2,
1879
+ value: %(]),
1880
+ add_comma: false,
1881
+ collection_bookend: :close,
1882
+ ),
1883
+ an_object_having_attributes(
1884
+ type: :delete,
1885
+ indentation_level: 1,
1886
+ value: %(}),
1887
+ collection_bookend: :close,
1888
+ ),
1889
+ ])
1278
1890
  end
1279
1891
  end
1280
1892
  end
1281
- end
1282
1893
 
1283
- context "given a data structure that refers to itself somewhere inside of it" do
1284
- context "given as_single_line: true" do
1285
- it "replaces the reference with ∙∙∙" do
1286
- value = ["a", "b", "c"]
1287
- value.insert(1, value)
1288
- inspection = described_class.inspect_object(value, as_single_line: true)
1289
- expect(inspection).to eq(%(["a", ∙∙∙, "b", "c"]))
1894
+ context "given a data structure that refers to itself somewhere inside of it" do
1895
+ context "given as_lines: false" do
1896
+ it "replaces the reference with ∙∙∙" do
1897
+ value = ["a", "b", "c"]
1898
+ value.insert(1, value)
1899
+ string = described_class.inspect_object(value, as_lines: false)
1900
+ expect(string).to eq(%(["a", ∙∙∙, "b", "c"]))
1901
+ end
1290
1902
  end
1291
- end
1292
1903
 
1293
- context "given as_single_line: false" do
1294
- it "replaces the reference with ∙∙∙" do
1295
- value = ["a", "b", "c"]
1296
- value.insert(1, value)
1297
- inspection = described_class.inspect_object(
1298
- value,
1299
- as_single_line: false,
1300
- )
1301
- expect(inspection).to eq(<<~INSPECTION.rstrip)
1302
- [
1303
- "a",
1304
- ∙∙∙,
1305
- "b",
1306
- "c"
1307
- ]
1308
- INSPECTION
1904
+ context "given as_lines: true" do
1905
+ it "replaces the reference with ∙∙∙" do
1906
+ value = ["a", "b", "c"]
1907
+ value.insert(1, value)
1908
+ tiered_lines = described_class.inspect_object(
1909
+ value,
1910
+ as_lines: true,
1911
+ type: :delete,
1912
+ indentation_level: 1,
1913
+ )
1914
+ expect(tiered_lines).to match([
1915
+ an_object_having_attributes(
1916
+ type: :delete,
1917
+ indentation_level: 1,
1918
+ value: %([),
1919
+ collection_bookend: :open,
1920
+ ),
1921
+ an_object_having_attributes(
1922
+ type: :delete,
1923
+ indentation_level: 2,
1924
+ value: %("a"),
1925
+ add_comma: true,
1926
+ ),
1927
+ an_object_having_attributes(
1928
+ type: :delete,
1929
+ indentation_level: 2,
1930
+ value: %(∙∙∙),
1931
+ add_comma: true,
1932
+ ),
1933
+ an_object_having_attributes(
1934
+ type: :delete,
1935
+ indentation_level: 2,
1936
+ value: %("b"),
1937
+ add_comma: true,
1938
+ ),
1939
+ an_object_having_attributes(
1940
+ type: :delete,
1941
+ indentation_level: 2,
1942
+ value: %("c"),
1943
+ add_comma: false,
1944
+ ),
1945
+ an_object_having_attributes(
1946
+ type: :delete,
1947
+ indentation_level: 1,
1948
+ value: %(]),
1949
+ collection_bookend: :close,
1950
+ ),
1951
+ ])
1952
+ end
1309
1953
  end
1310
1954
  end
1311
- end
1312
1955
 
1313
- def colorize(*args, **opts, &block)
1314
- SuperDiff::Helpers.style(*args, **opts, &block).to_s.chomp
1956
+ context "given a data structure that refers to itself in a nested data structure"
1315
1957
  end
1316
1958
  end