super_diff 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/lib/super_diff.rb +27 -6
  4. data/lib/super_diff/active_record.rb +7 -7
  5. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
  6. data/lib/super_diff/active_record/object_inspection.rb +2 -6
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
  8. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
  9. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
  10. data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
  11. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
  12. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
  13. data/lib/super_diff/active_support.rb +8 -8
  14. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
  15. data/lib/super_diff/active_support/object_inspection.rb +2 -6
  16. data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
  18. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
  19. data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
  20. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
  21. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
  22. data/lib/super_diff/colorized_document_extensions.rb +9 -6
  23. data/lib/super_diff/configuration.rb +81 -8
  24. data/lib/super_diff/csi.rb +1 -2
  25. data/lib/super_diff/csi/four_bit_color.rb +0 -2
  26. data/lib/super_diff/differs/array.rb +1 -1
  27. data/lib/super_diff/differs/base.rb +3 -21
  28. data/lib/super_diff/differs/custom_object.rb +1 -1
  29. data/lib/super_diff/differs/default_object.rb +1 -1
  30. data/lib/super_diff/differs/hash.rb +1 -1
  31. data/lib/super_diff/differs/main.rb +1 -7
  32. data/lib/super_diff/differs/multiline_string.rb +1 -1
  33. data/lib/super_diff/differs/time_like.rb +1 -1
  34. data/lib/super_diff/equality_matchers/array.rb +2 -2
  35. data/lib/super_diff/equality_matchers/default.rb +2 -2
  36. data/lib/super_diff/equality_matchers/hash.rb +2 -2
  37. data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
  38. data/lib/super_diff/equality_matchers/primitive.rb +4 -7
  39. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  40. data/lib/super_diff/helpers.rb +52 -2
  41. data/lib/super_diff/line.rb +83 -0
  42. data/lib/super_diff/object_inspection.rb +12 -1
  43. data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
  44. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
  45. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
  46. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
  47. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
  48. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
  49. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
  50. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
  51. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
  52. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
  53. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/time_like.rb +19 -18
  54. data/lib/super_diff/object_inspection/nodes.rb +33 -32
  55. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
  56. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
  57. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
  58. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
  59. data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
  60. data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
  61. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
  62. data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
  63. data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
  64. data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
  65. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
  66. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
  67. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
  68. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
  69. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
  70. data/lib/super_diff/operation_tree_builders/array.rb +7 -10
  71. data/lib/super_diff/operation_tree_builders/base.rb +6 -6
  72. data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
  73. data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
  74. data/lib/super_diff/operation_tree_builders/hash.rb +0 -7
  75. data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
  76. data/lib/super_diff/operation_tree_flatteners.rb +20 -0
  77. data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
  78. data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
  79. data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
  80. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
  81. data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
  82. data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
  83. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
  84. data/lib/super_diff/operation_trees/array.rb +4 -7
  85. data/lib/super_diff/operation_trees/base.rb +39 -16
  86. data/lib/super_diff/operation_trees/custom_object.rb +4 -8
  87. data/lib/super_diff/operation_trees/default_object.rb +28 -13
  88. data/lib/super_diff/operation_trees/hash.rb +4 -7
  89. data/lib/super_diff/operation_trees/main.rb +1 -1
  90. data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
  91. data/lib/super_diff/operations/binary_operation.rb +1 -6
  92. data/lib/super_diff/operations/unary_operation.rb +2 -30
  93. data/lib/super_diff/recursion_guard.rb +3 -3
  94. data/lib/super_diff/rspec.rb +12 -13
  95. data/lib/super_diff/rspec/monkey_patches.rb +2 -2
  96. data/lib/super_diff/rspec/object_inspection.rb +4 -1
  97. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
  98. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
  99. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_including.rb +9 -8
  100. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
  101. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
  102. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/instance_of.rb +3 -5
  103. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/kind_of.rb +3 -5
  104. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
  105. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
  106. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
  107. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
  108. data/lib/super_diff/tiered_lines.rb +4 -0
  109. data/lib/super_diff/tiered_lines_elider.rb +490 -0
  110. data/lib/super_diff/tiered_lines_formatter.rb +79 -0
  111. data/lib/super_diff/version.rb +1 -1
  112. data/spec/examples.txt +407 -410
  113. data/spec/integration/rails/active_support_spec.rb +19 -0
  114. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
  115. data/spec/integration/rspec/eq_matcher_spec.rb +22 -88
  116. data/spec/integration/rspec/have_attributes_matcher_spec.rb +6 -7
  117. data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
  118. data/spec/integration/rspec/match_matcher_spec.rb +10 -5
  119. data/spec/spec_helper.rb +1 -0
  120. data/spec/support/command_runner.rb +15 -25
  121. data/spec/support/helpers.rb +21 -0
  122. data/spec/support/integration/helpers.rb +2 -0
  123. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
  124. data/spec/support/integration/test_programs/base.rb +36 -10
  125. data/spec/support/shared_examples/active_record.rb +3 -2
  126. data/spec/support/shared_examples/active_support.rb +65 -0
  127. data/spec/support/shared_examples/elided_diffs.rb +914 -0
  128. data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
  129. data/spec/support/unit/helpers.rb +15 -0
  130. data/spec/support/unit/matchers/match_output.rb +41 -0
  131. data/spec/unit/active_record/object_inspection_spec.rb +273 -0
  132. data/spec/unit/equality_matchers/main_spec.rb +51 -71
  133. data/spec/unit/helpers_spec.rb +61 -0
  134. data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
  135. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
  136. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
  137. data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
  138. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
  139. data/spec/unit/rspec/object_inspection_spec.rb +446 -0
  140. data/spec/unit/super_diff_spec.rb +1488 -846
  141. data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
  142. data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
  143. metadata +88 -50
  144. data/lib/super_diff/active_record/diff_formatters.rb +0 -10
  145. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
  146. data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
  147. data/lib/super_diff/active_support/diff_formatters.rb +0 -10
  148. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
  149. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
  150. data/lib/super_diff/diff_formatters.rb +0 -14
  151. data/lib/super_diff/diff_formatters/array.rb +0 -21
  152. data/lib/super_diff/diff_formatters/base.rb +0 -33
  153. data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
  154. data/lib/super_diff/diff_formatters/default_object.rb +0 -46
  155. data/lib/super_diff/diff_formatters/defaults.rb +0 -10
  156. data/lib/super_diff/diff_formatters/hash.rb +0 -34
  157. data/lib/super_diff/diff_formatters/main.rb +0 -41
  158. data/lib/super_diff/object_inspection/inspectors.rb +0 -23
  159. data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
  160. data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
  161. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
  162. data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
  163. data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
  164. data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
  165. data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
  166. data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
  167. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
  168. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
  169. data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
  170. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -36
  171. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
  172. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
  173. data/spec/support/object_id.rb +0 -27
  174. data/spec/support/ruby_versions.rb +0 -11
@@ -0,0 +1,121 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe SuperDiff::OperationTreeFlatteners::MultilineString do
4
+ context "given an empty tree" do
5
+ it "returns an empty set of lines" do
6
+ operation_tree = SuperDiff::OperationTrees::MultilineString.new([])
7
+ flattened_operation_tree = described_class.call(operation_tree)
8
+ expect(flattened_operation_tree).to eq([])
9
+ end
10
+ end
11
+
12
+ context "given a tree of only noops" do
13
+ it "returns a series of lines from printing each value" do
14
+ collection = Array.new(3) { :some_value }
15
+ operation_tree = SuperDiff::OperationTrees::MultilineString.new([
16
+ double(
17
+ :operation,
18
+ name: :noop,
19
+ collection: collection,
20
+ value: "This is a line\n",
21
+ index: 0,
22
+ ),
23
+ double(
24
+ :operation,
25
+ name: :noop,
26
+ collection: collection,
27
+ value: "This is another line\n",
28
+ index: 1,
29
+ ),
30
+ double(
31
+ :operation,
32
+ name: :noop,
33
+ collection: collection,
34
+ value: "This is yet another line",
35
+ index: 2,
36
+ ),
37
+ ])
38
+
39
+ flattened_operation_tree = described_class.call(operation_tree)
40
+
41
+ expect(flattened_operation_tree).to match([
42
+ an_object_having_attributes(
43
+ type: :noop,
44
+ indentation_level: 0,
45
+ prefix: "",
46
+ value: %(This is a line\\n),
47
+ add_comma: false,
48
+ ),
49
+ an_object_having_attributes(
50
+ type: :noop,
51
+ indentation_level: 0,
52
+ prefix: "",
53
+ value: %(This is another line\\n),
54
+ add_comma: false,
55
+ ),
56
+ an_object_having_attributes(
57
+ type: :noop,
58
+ indentation_level: 0,
59
+ prefix: "",
60
+ value: %(This is yet another line),
61
+ add_comma: false,
62
+ ),
63
+ ])
64
+ end
65
+ end
66
+
67
+ context "given a tree of noops, inserts, and deletes" do
68
+ it "returns a series of lines from printing each value" do
69
+ collection = Array.new(3) { :some_value }
70
+ operation_tree = SuperDiff::OperationTrees::MultilineString.new([
71
+ double(
72
+ :operation,
73
+ name: :noop,
74
+ collection: collection,
75
+ value: "This is a line\n",
76
+ index: 0,
77
+ ),
78
+ double(
79
+ :operation,
80
+ name: :delete,
81
+ collection: collection,
82
+ value: "This is another line\n",
83
+ index: 1,
84
+ ),
85
+ double(
86
+ :operation,
87
+ name: :insert,
88
+ collection: collection,
89
+ value: "This is yet another line",
90
+ index: 1,
91
+ ),
92
+ ])
93
+
94
+ flattened_operation_tree = described_class.call(operation_tree)
95
+
96
+ expect(flattened_operation_tree).to match([
97
+ an_object_having_attributes(
98
+ type: :noop,
99
+ indentation_level: 0,
100
+ prefix: "",
101
+ value: %(This is a line\\n),
102
+ add_comma: false,
103
+ ),
104
+ an_object_having_attributes(
105
+ type: :delete,
106
+ indentation_level: 0,
107
+ prefix: "",
108
+ value: %(This is another line\\n),
109
+ add_comma: false,
110
+ ),
111
+ an_object_having_attributes(
112
+ type: :insert,
113
+ indentation_level: 0,
114
+ prefix: "",
115
+ value: %(This is yet another line),
116
+ add_comma: false,
117
+ ),
118
+ ])
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,446 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe SuperDiff, type: :unit do
4
+ describe ".inspect_object", "for RSpec objects" do
5
+ context "given a hash-including-<something>" do
6
+ context "given as_lines: false" do
7
+ it "returns an inspected version of the object" do
8
+ string = described_class.inspect_object(
9
+ a_hash_including(foo: "bar", baz: "qux"),
10
+ as_lines: false,
11
+ )
12
+ expect(string).to eq(
13
+ %(#<a hash including (foo: "bar", baz: "qux")>),
14
+ )
15
+ end
16
+ end
17
+
18
+ context "given as_lines: true" do
19
+ it "returns an inspected version of the object as multiple Lines" do
20
+ tiered_lines = described_class.inspect_object(
21
+ a_hash_including(foo: "bar", baz: "qux"),
22
+ as_lines: true,
23
+ type: :delete,
24
+ indentation_level: 1,
25
+ )
26
+ expect(tiered_lines).to match([
27
+ an_object_having_attributes(
28
+ type: :delete,
29
+ indentation_level: 1,
30
+ value: %[#<a hash including (],
31
+ collection_bookend: :open,
32
+ ),
33
+ an_object_having_attributes(
34
+ type: :delete,
35
+ indentation_level: 2,
36
+ prefix: %[foo: ],
37
+ value: %["bar"],
38
+ add_comma: true,
39
+ ),
40
+ an_object_having_attributes(
41
+ type: :delete,
42
+ indentation_level: 2,
43
+ prefix: %[baz: ],
44
+ value: %["qux"],
45
+ add_comma: false,
46
+ ),
47
+ an_object_having_attributes(
48
+ type: :delete,
49
+ indentation_level: 1,
50
+ value: %[)>],
51
+ collection_bookend: :close,
52
+ ),
53
+ ])
54
+ end
55
+ end
56
+ end
57
+
58
+ context "given a collection-including-<something>" do
59
+ context "given as_lines: false" do
60
+ it "returns an inspected version of the object" do
61
+ string = described_class.inspect_object(
62
+ a_collection_including(1, 2, 3),
63
+ as_lines: false,
64
+ )
65
+ expect(string).to eq(
66
+ %(#<a collection including (1, 2, 3)>),
67
+ )
68
+ end
69
+ end
70
+
71
+ context "given as_lines: true" do
72
+ it "returns an inspected version of the object as multiple Lines" do
73
+ tiered_lines = described_class.inspect_object(
74
+ a_collection_including(1, 2, 3),
75
+ as_lines: true,
76
+ type: :delete,
77
+ indentation_level: 1,
78
+ )
79
+ expect(tiered_lines).to match([
80
+ an_object_having_attributes(
81
+ type: :delete,
82
+ indentation_level: 1,
83
+ value: %[#<a collection including (],
84
+ collection_bookend: :open,
85
+ ),
86
+ an_object_having_attributes(
87
+ type: :delete,
88
+ indentation_level: 2,
89
+ value: %[1],
90
+ add_comma: true,
91
+ ),
92
+ an_object_having_attributes(
93
+ type: :delete,
94
+ indentation_level: 2,
95
+ value: %[2],
96
+ add_comma: true,
97
+ ),
98
+ an_object_having_attributes(
99
+ type: :delete,
100
+ indentation_level: 2,
101
+ value: %[3],
102
+ add_comma: false,
103
+ ),
104
+ an_object_having_attributes(
105
+ type: :delete,
106
+ indentation_level: 1,
107
+ value: %[)>],
108
+ collection_bookend: :close,
109
+ ),
110
+ ])
111
+ end
112
+ end
113
+ end
114
+
115
+ context "given a fuzzy object" do
116
+ context "given as_lines: false" do
117
+ it "returns an inspected version of the object" do
118
+ string = described_class.inspect_object(
119
+ an_object_having_attributes(foo: "bar", baz: "qux"),
120
+ as_lines: false,
121
+ )
122
+ expect(string).to eq(
123
+ %(#<an object having attributes (foo: "bar", baz: "qux")>),
124
+ )
125
+ end
126
+ end
127
+
128
+ context "given as_lines: true" do
129
+ it "returns an inspected version of the object as multiple Lines" do
130
+ tiered_lines = described_class.inspect_object(
131
+ an_object_having_attributes(foo: "bar", baz: "qux"),
132
+ as_lines: true,
133
+ type: :delete,
134
+ indentation_level: 1,
135
+ )
136
+ expect(tiered_lines).to match([
137
+ an_object_having_attributes(
138
+ type: :delete,
139
+ indentation_level: 1,
140
+ value: %[#<an object having attributes (],
141
+ collection_bookend: :open,
142
+ ),
143
+ an_object_having_attributes(
144
+ type: :delete,
145
+ indentation_level: 2,
146
+ prefix: %[foo: ],
147
+ value: %["bar"],
148
+ add_comma: true,
149
+ ),
150
+ an_object_having_attributes(
151
+ type: :delete,
152
+ indentation_level: 2,
153
+ prefix: %[baz: ],
154
+ value: %["qux"],
155
+ add_comma: false,
156
+ ),
157
+ an_object_having_attributes(
158
+ type: :delete,
159
+ indentation_level: 1,
160
+ value: %[)>],
161
+ collection_bookend: :close,
162
+ ),
163
+ ])
164
+ end
165
+ end
166
+ end
167
+
168
+ context "given a collection-containing-exactly-<something>" do
169
+ context "given as_lines: false" do
170
+ it "returns an inspected version of the object" do
171
+ string = described_class.inspect_object(
172
+ a_collection_containing_exactly("foo", "bar", "baz"),
173
+ as_lines: false,
174
+ )
175
+ expect(string).to eq(
176
+ %(#<a collection containing exactly ("foo", "bar", "baz")>),
177
+ )
178
+ end
179
+ end
180
+
181
+ context "given as_lines: true" do
182
+ it "returns an inspected version of the object as multiple Lines" do
183
+ tiered_lines = described_class.inspect_object(
184
+ a_collection_containing_exactly("foo", "bar", "baz"),
185
+ as_lines: true,
186
+ type: :delete,
187
+ indentation_level: 1,
188
+ )
189
+ expect(tiered_lines).to match([
190
+ an_object_having_attributes(
191
+ type: :delete,
192
+ indentation_level: 1,
193
+ value: %[#<a collection containing exactly (],
194
+ collection_bookend: :open,
195
+ ),
196
+ an_object_having_attributes(
197
+ type: :delete,
198
+ indentation_level: 2,
199
+ value: %["foo"],
200
+ add_comma: true,
201
+ ),
202
+ an_object_having_attributes(
203
+ type: :delete,
204
+ indentation_level: 2,
205
+ value: %["bar"],
206
+ add_comma: true,
207
+ ),
208
+ an_object_having_attributes(
209
+ type: :delete,
210
+ indentation_level: 2,
211
+ value: %["baz"],
212
+ add_comma: false,
213
+ ),
214
+ an_object_having_attributes(
215
+ type: :delete,
216
+ indentation_level: 1,
217
+ value: %[)>],
218
+ collection_bookend: :close,
219
+ ),
220
+ ])
221
+ end
222
+ end
223
+ end
224
+
225
+ context "given a kind-of-<something>" do
226
+ context "given as_lines: false" do
227
+ it "returns an inspected version of the object" do
228
+ string = described_class.inspect_object(
229
+ a_kind_of(Symbol),
230
+ as_lines: false,
231
+ )
232
+ expect(string).to eq(%(#<a kind of Symbol>))
233
+ end
234
+ end
235
+
236
+ context "given as_lines: true" do
237
+ it "returns an inspected version of the object as a single Line" do
238
+ tiered_lines = described_class.inspect_object(
239
+ a_kind_of(Symbol),
240
+ as_lines: true,
241
+ type: :delete,
242
+ indentation_level: 1,
243
+ )
244
+ expect(tiered_lines).to match([
245
+ an_object_having_attributes(
246
+ type: :delete,
247
+ indentation_level: 1,
248
+ value: %[#<a kind of Symbol>],
249
+ ),
250
+ ])
251
+ end
252
+ end
253
+ end
254
+
255
+ context "given an-instance-of-<something>" do
256
+ context "given as_lines: false" do
257
+ it "returns an inspected version of the object" do
258
+ string = described_class.inspect_object(
259
+ an_instance_of(Symbol),
260
+ as_lines: false,
261
+ )
262
+ expect(string).to eq(%(#<an instance of Symbol>))
263
+ end
264
+ end
265
+
266
+ context "given as_lines: true" do
267
+ it "returns an inspected version of the object" do
268
+ tiered_lines = described_class.inspect_object(
269
+ an_instance_of(Symbol),
270
+ as_lines: true,
271
+ type: :delete,
272
+ indentation_level: 1,
273
+ )
274
+ expect(tiered_lines).to match([
275
+ an_object_having_attributes(
276
+ type: :delete,
277
+ indentation_level: 1,
278
+ value: %[#<an instance of Symbol>],
279
+ ),
280
+ ])
281
+ end
282
+ end
283
+ end
284
+
285
+ context "given a-value-within-<something>" do
286
+ context "given as_lines: false" do
287
+ it "returns an inspected version of the object" do
288
+ string = described_class.inspect_object(
289
+ a_value_within(1).of(Time.utc(2020, 4, 9)),
290
+ as_lines: false,
291
+ )
292
+ expect(string).to eq(
293
+ %(#<a value within 1 of #<Time 2020-04-09 00:00:00 +00:00 (UTC)>>),
294
+ )
295
+ end
296
+ end
297
+
298
+ context "given as_lines: true" do
299
+ it "returns an inspected version of the object" do
300
+ tiered_lines = described_class.inspect_object(
301
+ a_value_within(1).of(Time.utc(2020, 4, 9)),
302
+ as_lines: true,
303
+ type: :delete,
304
+ indentation_level: 1,
305
+ )
306
+ expect(tiered_lines).to match([
307
+ an_object_having_attributes(
308
+ type: :delete,
309
+ indentation_level: 1,
310
+ value: %(#<a value within 1 of #<Time {),
311
+ add_comma: false,
312
+ collection_bookend: :open,
313
+ ),
314
+ an_object_having_attributes(
315
+ type: :delete,
316
+ indentation_level: 2,
317
+ value: %(year: 2020),
318
+ add_comma: true,
319
+ collection_bookend: nil,
320
+ ),
321
+ an_object_having_attributes(
322
+ type: :delete,
323
+ indentation_level: 2,
324
+ value: %(month: 4),
325
+ add_comma: true,
326
+ collection_bookend: nil,
327
+ ),
328
+ an_object_having_attributes(
329
+ type: :delete,
330
+ indentation_level: 2,
331
+ value: %(day: 9),
332
+ add_comma: true,
333
+ collection_bookend: nil,
334
+ ),
335
+ an_object_having_attributes(
336
+ type: :delete,
337
+ indentation_level: 2,
338
+ value: %(hour: 0),
339
+ add_comma: true,
340
+ collection_bookend: nil,
341
+ ),
342
+ an_object_having_attributes(
343
+ type: :delete,
344
+ indentation_level: 2,
345
+ value: %(min: 0),
346
+ add_comma: true,
347
+ collection_bookend: nil,
348
+ ),
349
+ an_object_having_attributes(
350
+ type: :delete,
351
+ indentation_level: 2,
352
+ value: %(sec: 0),
353
+ add_comma: true,
354
+ collection_bookend: nil,
355
+ ),
356
+ an_object_having_attributes(
357
+ type: :delete,
358
+ indentation_level: 2,
359
+ value: %(subsec: 0),
360
+ add_comma: true,
361
+ collection_bookend: nil,
362
+ ),
363
+ an_object_having_attributes(
364
+ type: :delete,
365
+ indentation_level: 2,
366
+ value: %(zone: "UTC"),
367
+ add_comma: true,
368
+ collection_bookend: nil,
369
+ ),
370
+ an_object_having_attributes(
371
+ type: :delete,
372
+ indentation_level: 2,
373
+ value: %(utc_offset: 0),
374
+ add_comma: false,
375
+ collection_bookend: nil,
376
+ ),
377
+ an_object_having_attributes(
378
+ type: :delete,
379
+ indentation_level: 1,
380
+ value: %(}>>),
381
+ add_comma: false,
382
+ collection_bookend: :close,
383
+ ),
384
+ ])
385
+ end
386
+ end
387
+ end
388
+
389
+ # TODO: Test InstanceDouble, ClassDouble, ObjectDouble
390
+ context "given a Double" do
391
+ # TODO: Test named double
392
+ context "that is anonymous" do
393
+ context "given as_lines: false" do
394
+ it "returns an inspected version of the object" do
395
+ string = described_class.inspect_object(
396
+ double(foo: "bar", baz: "qux"),
397
+ as_lines: false,
398
+ )
399
+ expect(string).to eq(
400
+ %(#<Double (anonymous) foo: "bar", baz: "qux">),
401
+ )
402
+ end
403
+ end
404
+
405
+ context "given as_lines: true" do
406
+ it "returns an inspected version of the object as multiple Lines" do
407
+ tiered_lines = described_class.inspect_object(
408
+ double(foo: "bar", baz: "qux"),
409
+ as_lines: true,
410
+ type: :delete,
411
+ indentation_level: 1,
412
+ )
413
+ expect(tiered_lines).to match([
414
+ an_object_having_attributes(
415
+ type: :delete,
416
+ indentation_level: 1,
417
+ value: %(#<Double (anonymous) {),
418
+ collection_bookend: :open,
419
+ ),
420
+ an_object_having_attributes(
421
+ type: :delete,
422
+ indentation_level: 2,
423
+ prefix: %(foo: ),
424
+ value: %("bar"),
425
+ add_comma: true,
426
+ ),
427
+ an_object_having_attributes(
428
+ type: :delete,
429
+ indentation_level: 2,
430
+ prefix: %(baz: ),
431
+ value: %("qux"),
432
+ add_comma: false,
433
+ ),
434
+ an_object_having_attributes(
435
+ type: :delete,
436
+ indentation_level: 1,
437
+ value: %(}>),
438
+ collection_bookend: :close,
439
+ ),
440
+ ])
441
+ end
442
+ end
443
+ end
444
+ end
445
+ end
446
+ end