super_diff 0.5.3 → 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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -20
  3. data/lib/super_diff.rb +46 -7
  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 +102 -19
  24. data/lib/super_diff/csi.rb +1 -1
  25. data/lib/super_diff/csi/four_bit_color.rb +0 -2
  26. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  27. data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
  28. data/lib/super_diff/differs/array.rb +1 -1
  29. data/lib/super_diff/differs/base.rb +3 -21
  30. data/lib/super_diff/differs/custom_object.rb +1 -1
  31. data/lib/super_diff/differs/default_object.rb +1 -1
  32. data/lib/super_diff/differs/hash.rb +1 -1
  33. data/lib/super_diff/differs/main.rb +1 -7
  34. data/lib/super_diff/differs/multiline_string.rb +1 -1
  35. data/lib/super_diff/differs/time_like.rb +1 -1
  36. data/lib/super_diff/equality_matchers/array.rb +4 -4
  37. data/lib/super_diff/equality_matchers/default.rb +4 -4
  38. data/lib/super_diff/equality_matchers/hash.rb +4 -4
  39. data/lib/super_diff/equality_matchers/multiline_string.rb +4 -4
  40. data/lib/super_diff/equality_matchers/primitive.rb +6 -9
  41. data/lib/super_diff/equality_matchers/singleline_string.rb +4 -4
  42. data/lib/super_diff/gem_version.rb +45 -0
  43. data/lib/super_diff/helpers.rb +52 -2
  44. data/lib/super_diff/line.rb +83 -0
  45. data/lib/super_diff/object_inspection.rb +12 -9
  46. data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
  47. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
  48. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
  49. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
  50. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
  51. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
  52. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
  53. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
  54. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
  57. data/lib/super_diff/object_inspection/nodes.rb +33 -32
  58. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
  59. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
  60. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
  61. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
  62. data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
  63. data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
  64. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
  65. data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
  66. data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
  67. data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
  68. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
  69. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
  70. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
  71. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
  72. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
  73. data/lib/super_diff/operation_tree_builders/array.rb +7 -10
  74. data/lib/super_diff/operation_tree_builders/base.rb +6 -6
  75. data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
  76. data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  78. data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
  79. data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
  80. data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
  81. data/lib/super_diff/operation_tree_flatteners.rb +20 -0
  82. data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
  83. data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
  84. data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
  85. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
  86. data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
  87. data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
  88. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
  89. data/lib/super_diff/operation_trees/array.rb +4 -7
  90. data/lib/super_diff/operation_trees/base.rb +39 -16
  91. data/lib/super_diff/operation_trees/custom_object.rb +4 -8
  92. data/lib/super_diff/operation_trees/default_object.rb +28 -13
  93. data/lib/super_diff/operation_trees/hash.rb +4 -7
  94. data/lib/super_diff/operation_trees/main.rb +1 -1
  95. data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
  96. data/lib/super_diff/operations/binary_operation.rb +1 -6
  97. data/lib/super_diff/operations/unary_operation.rb +2 -30
  98. data/lib/super_diff/recursion_guard.rb +3 -3
  99. data/lib/super_diff/rspec.rb +41 -13
  100. data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
  101. data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
  102. data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
  103. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
  104. data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
  108. data/lib/super_diff/rspec/monkey_patches.rb +353 -306
  109. data/lib/super_diff/rspec/object_inspection.rb +4 -1
  110. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
  111. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
  117. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
  120. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +12 -4
  121. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
  122. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
  123. data/lib/super_diff/tiered_lines.rb +4 -0
  124. data/lib/super_diff/tiered_lines_elider.rb +490 -0
  125. data/lib/super_diff/tiered_lines_formatter.rb +79 -0
  126. data/lib/super_diff/version.rb +1 -1
  127. data/spec/examples.txt +407 -5
  128. data/spec/integration/rails/active_support_spec.rb +19 -0
  129. data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
  130. data/spec/integration/rspec/be_matcher_spec.rb +100 -100
  131. data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
  132. data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
  133. data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
  134. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +113 -107
  135. data/spec/integration/rspec/eq_matcher_spec.rb +223 -277
  136. data/spec/integration/rspec/have_attributes_matcher_spec.rb +138 -129
  137. data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
  138. data/spec/integration/rspec/include_matcher_spec.rb +73 -73
  139. data/spec/integration/rspec/match_array_matcher_spec.rb +126 -119
  140. data/spec/integration/rspec/match_matcher_spec.rb +362 -274
  141. data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
  142. data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
  143. data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
  144. data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
  145. data/spec/spec_helper.rb +33 -13
  146. data/spec/support/command_runner.rb +15 -25
  147. data/spec/support/helpers.rb +21 -0
  148. data/spec/support/integration/helpers.rb +8 -2
  149. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +4 -4
  150. data/spec/support/integration/test_programs/base.rb +38 -10
  151. data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
  152. data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
  153. data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
  154. data/spec/support/shared_examples/active_record.rb +109 -108
  155. data/spec/support/shared_examples/active_support.rb +65 -0
  156. data/spec/support/shared_examples/elided_diffs.rb +914 -0
  157. data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
  158. data/spec/support/unit/helpers.rb +15 -0
  159. data/spec/support/unit/matchers/match_output.rb +41 -0
  160. data/spec/unit/active_record/object_inspection_spec.rb +273 -0
  161. data/spec/unit/equality_matchers/main_spec.rb +445 -465
  162. data/spec/unit/helpers_spec.rb +61 -0
  163. data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
  164. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
  165. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
  166. data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
  167. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
  168. data/spec/unit/rspec/object_inspection_spec.rb +446 -0
  169. data/spec/unit/super_diff_spec.rb +1958 -0
  170. data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
  171. data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
  172. data/super_diff.gemspec +1 -1
  173. metadata +95 -50
  174. data/lib/super_diff/active_record/diff_formatters.rb +0 -10
  175. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
  176. data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
  177. data/lib/super_diff/active_support/diff_formatters.rb +0 -10
  178. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
  179. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
  180. data/lib/super_diff/diff_formatters.rb +0 -14
  181. data/lib/super_diff/diff_formatters/array.rb +0 -21
  182. data/lib/super_diff/diff_formatters/base.rb +0 -33
  183. data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
  184. data/lib/super_diff/diff_formatters/default_object.rb +0 -46
  185. data/lib/super_diff/diff_formatters/defaults.rb +0 -10
  186. data/lib/super_diff/diff_formatters/hash.rb +0 -34
  187. data/lib/super_diff/diff_formatters/main.rb +0 -41
  188. data/lib/super_diff/object_inspection/inspectors.rb +0 -23
  189. data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
  190. data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
  191. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
  192. data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
  193. data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
  194. data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
  195. data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
  196. data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
  197. data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
  198. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
  199. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
  200. data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
  201. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
  202. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
  203. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
  204. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
  205. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
  206. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
  207. data/spec/support/object_id.rb +0 -27
  208. data/spec/support/ruby_versions.rb +0 -11
  209. data/spec/unit/object_inspection_spec.rb +0 -1168
@@ -0,0 +1,1958 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe SuperDiff, type: :unit do
4
+ describe ".inspect_object", "for Ruby objects" do
5
+ context "given nil" do
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")
10
+ end
11
+ end
12
+
13
+ context "given as_lines: true" do
14
+ it "returns nil wrapped in a single Line" do
15
+ tiered_lines = described_class.inspect_object(
16
+ nil,
17
+ as_lines: true,
18
+ type: :delete,
19
+ indentation_level: 1,
20
+ )
21
+ expect(tiered_lines).to match([
22
+ an_object_having_attributes(
23
+ type: :delete,
24
+ indentation_level: 1,
25
+ value: %(nil),
26
+ ),
27
+ ])
28
+ end
29
+ end
30
+ end
31
+
32
+ context "given true" do
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")
37
+ end
38
+ end
39
+
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,
47
+ )
48
+ expect(tiered_lines).to match([
49
+ an_object_having_attributes(
50
+ type: :delete,
51
+ indentation_level: 1,
52
+ value: %(true),
53
+ ),
54
+ ])
55
+ end
56
+ end
57
+ end
58
+
59
+ context "given false" do
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")
64
+ end
65
+ end
66
+
67
+ context "given as_lines: true" do
68
+ it "returns false wrapped in a single Line" do
69
+ tiered_lines = described_class.inspect_object(
70
+ false,
71
+ as_lines: true,
72
+ type: :delete,
73
+ indentation_level: 1,
74
+ )
75
+ expect(tiered_lines).to match([
76
+ an_object_having_attributes(
77
+ type: :delete,
78
+ indentation_level: 1,
79
+ value: %(false),
80
+ ),
81
+ ])
82
+ end
83
+ end
84
+ end
85
+
86
+ context "given a number" do
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")
91
+ end
92
+ end
93
+
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(
97
+ 3,
98
+ as_lines: true,
99
+ type: :delete,
100
+ indentation_level: 1,
101
+ )
102
+ expect(tiered_lines).to match([
103
+ an_object_having_attributes(
104
+ type: :delete,
105
+ indentation_level: 1,
106
+ value: %(3),
107
+ ),
108
+ ])
109
+ end
110
+ end
111
+ end
112
+
113
+ context "given a symbol" do
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")
118
+ end
119
+ end
120
+
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(
124
+ :foo,
125
+ as_lines: true,
126
+ type: :delete,
127
+ indentation_level: 1,
128
+ )
129
+ expect(tiered_lines).to match([
130
+ an_object_having_attributes(
131
+ type: :delete,
132
+ indentation_level: 1,
133
+ value: %(:foo),
134
+ ),
135
+ ])
136
+ end
137
+ end
138
+ end
139
+
140
+ context "given a regex" do
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/")
145
+ end
146
+ end
147
+
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(
151
+ /foo/,
152
+ as_lines: true,
153
+ type: :delete,
154
+ indentation_level: 1,
155
+ )
156
+ expect(tiered_lines).to match([
157
+ an_object_having_attributes(
158
+ type: :delete,
159
+ indentation_level: 1,
160
+ value: %(/foo/),
161
+ ),
162
+ ])
163
+ end
164
+ end
165
+ end
166
+
167
+ context "given a single-line string" do
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
191
+ end
192
+ end
193
+
194
+ context "given a multi-line string" do
195
+ context "that does not contain color codes" do
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
224
+ end
225
+ end
226
+
227
+ context "that contains color codes" do
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")
250
+
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
302
+ end
303
+ end
304
+ end
305
+
306
+ context "given an array" do
307
+ context "containing only primitive values" do
308
+ context "given as_lines: false" do
309
+ it "returns an inspected version of the array" do
310
+ string = described_class.inspect_object(
311
+ ["foo", 2, :baz],
312
+ as_lines: false,
313
+ )
314
+ expect(string).to eq(%(["foo", 2, :baz]))
315
+ end
316
+ end
317
+
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(
321
+ ["foo", 2, :baz],
322
+ as_lines: true,
323
+ type: :delete,
324
+ indentation_level: 1,
325
+ )
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
+ ])
358
+ end
359
+ end
360
+ end
361
+
362
+ context "containing other arrays" do
363
+ context "given as_lines: false" do
364
+ it "returns an inspected version of the array" do
365
+ string = described_class.inspect_object(
366
+ [
367
+ "foo",
368
+ ["bar", "baz"],
369
+ "qux",
370
+ ],
371
+ as_lines: false,
372
+ )
373
+ expect(string).to eq(%(["foo", ["bar", "baz"], "qux"]))
374
+ end
375
+ end
376
+
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(
380
+ [
381
+ "foo",
382
+ ["bar", "baz"],
383
+ "qux",
384
+ ],
385
+ as_lines: true,
386
+ type: :delete,
387
+ indentation_level: 1,
388
+ )
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
+ ])
440
+ end
441
+ end
442
+ end
443
+
444
+ context "which is empty" do
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(%([]))
449
+ end
450
+ end
451
+
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(
455
+ [],
456
+ as_lines: true,
457
+ type: :delete,
458
+ indentation_level: 1,
459
+ )
460
+ expect(tiered_lines).to match([
461
+ an_object_having_attributes(
462
+ type: :delete,
463
+ indentation_level: 1,
464
+ value: %([]),
465
+ ),
466
+ ])
467
+ end
468
+ end
469
+ end
470
+ end
471
+
472
+ context "given a hash" do
473
+ context "containing only primitive values" do
474
+ context "where all of the keys are symbols" do
475
+ context "given as_lines: false" do
476
+ it "returns an inspected version of the hash" do
477
+ string = described_class.inspect_object(
478
+ # rubocop:disable Style/HashSyntax
479
+ { :foo => "bar", :baz => "qux" },
480
+ # rubocop:enable Style/HashSyntax
481
+ as_lines: false,
482
+ )
483
+ expect(string).to eq(%({ foo: "bar", baz: "qux" }))
484
+ end
485
+ end
486
+
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(
490
+ # rubocop:disable Style/HashSyntax
491
+ { :foo => "bar", :baz => "qux" },
492
+ # rubocop:enable Style/HashSyntax
493
+ as_lines: true,
494
+ type: :delete,
495
+ indentation_level: 1,
496
+ )
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
+ ])
525
+ end
526
+ end
527
+ end
528
+
529
+ context "where only some of the keys are symbols" do
530
+ context "given as_lines: false" do
531
+ it "returns an inspected version of the hash" do
532
+ string = described_class.inspect_object(
533
+ { :foo => "bar", 2 => "baz" },
534
+ as_lines: false,
535
+ )
536
+ expect(string).to eq(%({ :foo => "bar", 2 => "baz" }))
537
+ end
538
+ end
539
+
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(
543
+ { :foo => "bar", 2 => "baz" },
544
+ as_lines: true,
545
+ type: :delete,
546
+ indentation_level: 1,
547
+ )
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
+ ])
576
+ end
577
+ end
578
+ end
579
+ end
580
+
581
+ context "containing other hashes" do
582
+ context "given as_lines: false" do
583
+ it "returns an inspected version of the hash" do
584
+ value_to_inspect = {
585
+ # rubocop:disable Style/HashSyntax
586
+ :category_name => "Appliances",
587
+ :products_by_sku => {
588
+ "EMDL-2934" => { :id => 4, :name => "Jordan Air" },
589
+ "KDS-3912" => { :id => 8, :name => "Chevy Impala" },
590
+ },
591
+ :number_of_products => 2,
592
+ # rubocop:enable Style/HashSyntax
593
+ }
594
+ string = described_class.inspect_object(
595
+ value_to_inspect,
596
+ as_lines: false,
597
+ )
598
+ # rubocop:disable Metrics/LineLength
599
+ expect(string).to eq(
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 }),
601
+ )
602
+ # rubocop:enable Metrics/LineLength
603
+ end
604
+ end
605
+
606
+ context "given as_lines: true" do
607
+ it "returns an inspected version of the array as multiple Lines" do
608
+ value_to_inspect = {
609
+ # rubocop:disable Style/HashSyntax
610
+ :category_name => "Appliances",
611
+ :products_by_sku => {
612
+ "EMDL-2934" => { :id => 4, :name => "George Foreman Grill" },
613
+ "KDS-3912" => { :id => 8, :name => "Magic Bullet" },
614
+ },
615
+ :number_of_products => 2,
616
+ # rubocop:enable Style/HashSyntax
617
+ }
618
+ tiered_lines = described_class.inspect_object(
619
+ value_to_inspect,
620
+ as_lines: true,
621
+ type: :delete,
622
+ indentation_level: 1,
623
+ )
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
+ ])
723
+ end
724
+ end
725
+ end
726
+
727
+ context "which is empty" do
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(%({}))
732
+ end
733
+ end
734
+
735
+ context "given as_lines: true" do
736
+ it "returns an inspected version of the array" do
737
+ tiered_lines = described_class.inspect_object(
738
+ {},
739
+ as_lines: true,
740
+ type: :delete,
741
+ indentation_level: 1,
742
+ )
743
+ expect(tiered_lines).to match([
744
+ an_object_having_attributes(
745
+ type: :delete,
746
+ indentation_level: 1,
747
+ value: %({}),
748
+ ),
749
+ ])
750
+ end
751
+ end
752
+ end
753
+ end
754
+
755
+ context "given a Time object" do
756
+ context "that does not have an associated time zone" do
757
+ context "given as_lines: false" do
758
+ it "returns a representation of the time on a single line" do
759
+ inspection = described_class.inspect_object(
760
+ Time.new(2021, 5, 5, 10, 23, 28.1234567891, "-05:00"),
761
+ as_lines: false
762
+ )
763
+ expect(inspection).to eq(
764
+ "#<Time 2021-05-05 10:23:28+(34749996836695/281474976710656) -05:00>"
765
+ )
766
+ end
767
+ end
768
+
769
+ context "given as_lines: true" do
770
+ it "returns a representation of the time across multiple lines" do
771
+ inspection = described_class.inspect_object(
772
+ Time.new(2021, 5, 5, 10, 23, 28.1234567891, "-05:00"),
773
+ as_lines: true,
774
+ type: :delete,
775
+ indentation_level: 1
776
+ )
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
+ ])
856
+ end
857
+ end
858
+ end
859
+
860
+ context "that has an associated time zone" do
861
+ around do |example|
862
+ ClimateControl.modify(TZ: 'America/Chicago', &example)
863
+ end
864
+
865
+ context "given as_lines: false" do
866
+ it "returns a representation of the time on a single line" do
867
+ inspection = described_class.inspect_object(
868
+ Time.new(2021, 5, 5, 10, 23, 28.1234567891),
869
+ as_lines: false
870
+ )
871
+ expect(inspection).to eq(
872
+ "#<Time 2021-05-05 10:23:28+(34749996836695/281474976710656) -05:00 (CDT)>"
873
+ )
874
+ end
875
+ end
876
+
877
+ context "given as_lines: true" do
878
+ it "returns a representation of the time across multiple lines" do
879
+ inspection = described_class.inspect_object(
880
+ Time.new(2021, 5, 5, 10, 23, 28.1234567891),
881
+ as_lines: true,
882
+ type: :delete,
883
+ indentation_level: 1
884
+ )
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
+ ])
964
+ end
965
+ end
966
+ end
967
+ end
968
+
969
+ context "given a class" do
970
+ context "given as_lines: false" do
971
+ it "returns an inspected version of the object" do
972
+ string = described_class.inspect_object(
973
+ SuperDiff::Test::Person,
974
+ as_lines: false,
975
+ )
976
+ expect(string).to eq("SuperDiff::Test::Person")
977
+ end
978
+ end
979
+
980
+ context "given as_lines: true" do
981
+ it "returns an inspected version of the object" do
982
+ tiered_lines = described_class.inspect_object(
983
+ SuperDiff::Test::Person,
984
+ as_lines: true,
985
+ type: :delete,
986
+ indentation_level: 1,
987
+ )
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
+ ])
995
+ end
996
+ end
997
+ end
998
+
999
+ # TODO: Add when empty
1000
+ context "given a custom object" do
1001
+ context "containing only primitive values" do
1002
+ context "given as_lines: false" do
1003
+ it "returns an inspected version of the object" do
1004
+ string = described_class.inspect_object(
1005
+ SuperDiff::Test::Person.new(name: "Doc", age: 58),
1006
+ as_lines: false,
1007
+ )
1008
+ expect(string).to eq(
1009
+ %(#<SuperDiff::Test::Person name: "Doc", age: 58>),
1010
+ )
1011
+ end
1012
+ end
1013
+
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(
1017
+ SuperDiff::Test::Person.new(name: "Doc", age: 58),
1018
+ as_lines: true,
1019
+ type: :delete,
1020
+ indentation_level: 1,
1021
+ )
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
+ ])
1048
+ end
1049
+ end
1050
+ end
1051
+
1052
+ context "containing other custom objects" do
1053
+ context "given as_lines: false" do
1054
+ it "returns an inspected version of the object" do
1055
+ string = described_class.inspect_object(
1056
+ SuperDiff::Test::Customer.new(
1057
+ name: "Marty McFly",
1058
+ shipping_address: SuperDiff::Test::ShippingAddress.new(
1059
+ line_1: "123 Main St.",
1060
+ line_2: "",
1061
+ city: "Hill Valley",
1062
+ state: "CA",
1063
+ zip: "90382",
1064
+ ),
1065
+ phone: "111-222-3333",
1066
+ ),
1067
+ as_lines: false,
1068
+ )
1069
+ expect(string).to eq(
1070
+ # rubocop:disable Metrics/LineLength
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">),
1072
+ # rubocop:enable Metrics/LineLength
1073
+ )
1074
+ end
1075
+ end
1076
+
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(
1080
+ SuperDiff::Test::Customer.new(
1081
+ name: "Marty McFly",
1082
+ shipping_address: SuperDiff::Test::ShippingAddress.new(
1083
+ line_1: "123 Main St.",
1084
+ line_2: "",
1085
+ city: "Hill Valley",
1086
+ state: "CA",
1087
+ zip: "90382",
1088
+ ),
1089
+ phone: "111-222-3333",
1090
+ ),
1091
+ as_lines: true,
1092
+ type: :delete,
1093
+ indentation_level: 1,
1094
+ )
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
+ ])
1173
+ end
1174
+ end
1175
+ end
1176
+ end
1177
+
1178
+ context "given a non-custom object" do
1179
+ context "containing only primitive values" do
1180
+ context "given as_lines: false" do
1181
+ it "returns an inspected version of the object" do
1182
+ string = described_class.inspect_object(
1183
+ SuperDiff::Test::Item.new(
1184
+ name: "mac and cheese",
1185
+ quantity: 2,
1186
+ ),
1187
+ as_lines: false,
1188
+ )
1189
+ expect(string).to match(
1190
+ /\A#<SuperDiff::Test::Item:0x[a-z0-9]+ @name="mac and cheese", @quantity=2>\Z/,
1191
+ )
1192
+ end
1193
+ end
1194
+
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(
1198
+ SuperDiff::Test::Item.new(
1199
+ name: "mac and cheese",
1200
+ quantity: 2,
1201
+ ),
1202
+ as_lines: true,
1203
+ type: :delete,
1204
+ indentation_level: 1,
1205
+ )
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
+ ])
1236
+ end
1237
+ end
1238
+ end
1239
+
1240
+ context "containing other custom objects" do
1241
+ context "given as_lines: false" do
1242
+ it "returns an inspected version of the object" do
1243
+ string = described_class.inspect_object(
1244
+ SuperDiff::Test::Order.new([
1245
+ SuperDiff::Test::Item.new(name: "ham", quantity: 1),
1246
+ SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
1247
+ SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
1248
+ ]),
1249
+ as_lines: false,
1250
+ )
1251
+ expect(string).to match(
1252
+ # rubocop:disable Metrics/LineLength
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/,
1254
+ # rubocop:enable Metrics/LineLength
1255
+ )
1256
+ end
1257
+ end
1258
+
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(
1262
+ SuperDiff::Test::Order.new([
1263
+ SuperDiff::Test::Item.new(name: "ham", quantity: 1),
1264
+ SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
1265
+ SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
1266
+ ]),
1267
+ as_lines: true,
1268
+ type: :delete,
1269
+ indentation_level: 1,
1270
+ )
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
+ ])
1393
+ end
1394
+ end
1395
+ end
1396
+
1397
+ context "which is empty" do
1398
+ context "given as_lines: false" do
1399
+ it "returns an inspected version of the array" do
1400
+ string = described_class.inspect_object(
1401
+ SuperDiff::Test::EmptyClass.new,
1402
+ as_lines: false,
1403
+ )
1404
+ expect(string).to match(
1405
+ /#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/,
1406
+ )
1407
+ end
1408
+ end
1409
+
1410
+ context "given as_lines: true" do
1411
+ it "returns an inspected version of the array" do
1412
+ inspection = described_class.inspect_object(
1413
+ SuperDiff::Test::EmptyClass.new,
1414
+ as_lines: true,
1415
+ type: :delete,
1416
+ indentation_level: 1
1417
+ )
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
+ ])
1427
+ end
1428
+ end
1429
+ end
1430
+ end
1431
+
1432
+ context "given a combination of all kinds of values" do
1433
+ context "given as_lines: false" do
1434
+ it "returns an inspected version of the object" do
1435
+ string = described_class.inspect_object(
1436
+ {
1437
+ state: :down,
1438
+ errors: [
1439
+ "Container A-234 is partially damaged",
1440
+ "Vessel B042 was attacked by raccoons",
1441
+ "Product FDK-3429 is out of stock",
1442
+ ],
1443
+ mission_critical: true,
1444
+ serviceable: false,
1445
+ outstanding_orders: [
1446
+ SuperDiff::Test::Order.new([
1447
+ SuperDiff::Test::Item.new(name: "ham", quantity: 1),
1448
+ SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
1449
+ SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
1450
+ ]),
1451
+ ],
1452
+ customers: [
1453
+ SuperDiff::Test::Customer.new(
1454
+ name: "Marty McFly",
1455
+ shipping_address: SuperDiff::Test::ShippingAddress.new(
1456
+ line_1: "123 Baltic Ave.",
1457
+ line_2: "",
1458
+ city: "Hill Valley",
1459
+ state: "CA",
1460
+ zip: "90382",
1461
+ ),
1462
+ phone: "111-111-1111",
1463
+ ),
1464
+ SuperDiff::Test::Customer.new(
1465
+ name: "Doc Brown",
1466
+ shipping_address: SuperDiff::Test::ShippingAddress.new(
1467
+ line_1: "456 Park Place",
1468
+ line_2: "",
1469
+ city: "Beverly Hills",
1470
+ state: "CA",
1471
+ zip: "90210",
1472
+ ),
1473
+ phone: "222-222-2222",
1474
+ ),
1475
+ ],
1476
+ },
1477
+ as_lines: false,
1478
+ )
1479
+ expect(string).to match(
1480
+ # rubocop:disable Metrics/LineLength
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/,
1482
+ # rubocop:enable Metrics/LineLength
1483
+ )
1484
+ end
1485
+ end
1486
+
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(
1490
+ {
1491
+ state: :down,
1492
+ errors: [
1493
+ "Container A-234 is partially damaged",
1494
+ "Vessel B042 was attacked by raccoons",
1495
+ "Product FDK-3429 is out of stock",
1496
+ ],
1497
+ mission_critical: true,
1498
+ serviceable: false,
1499
+ outstanding_orders: [
1500
+ SuperDiff::Test::Order.new([
1501
+ SuperDiff::Test::Item.new(name: "ham", quantity: 1),
1502
+ SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
1503
+ SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
1504
+ ]),
1505
+ ],
1506
+ customers: [
1507
+ SuperDiff::Test::Customer.new(
1508
+ name: "Marty McFly",
1509
+ shipping_address: SuperDiff::Test::ShippingAddress.new(
1510
+ line_1: "123 Baltic Ave.",
1511
+ line_2: "",
1512
+ city: "Hill Valley",
1513
+ state: "CA",
1514
+ zip: "90382",
1515
+ ),
1516
+ phone: "111-111-1111",
1517
+ ),
1518
+ SuperDiff::Test::Customer.new(
1519
+ name: "Doc Brown",
1520
+ shipping_address: SuperDiff::Test::ShippingAddress.new(
1521
+ line_1: "456 Park Place",
1522
+ line_2: "",
1523
+ city: "Beverly Hills",
1524
+ state: "CA",
1525
+ zip: "90210",
1526
+ ),
1527
+ phone: "222-222-2222",
1528
+ ),
1529
+ ],
1530
+ },
1531
+ as_lines: true,
1532
+ type: :delete,
1533
+ indentation_level: 1,
1534
+ )
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
+ ])
1890
+ end
1891
+ end
1892
+ end
1893
+
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
1902
+ end
1903
+
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
1953
+ end
1954
+ end
1955
+
1956
+ context "given a data structure that refers to itself in a nested data structure"
1957
+ end
1958
+ end