super_diff 0.9.0 → 0.10.0

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