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