super_diff 0.6.2 → 0.9.0

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