super_diff 0.10.0 → 0.12.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.

Potentially problematic release.


This version of super_diff might be problematic. Click here for more details.

Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -166
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -1
  4. data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +57 -0
  5. data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +34 -0
  6. data/lib/super_diff/active_record/inspection_tree_builders.rb +14 -0
  7. data/lib/super_diff/active_record/monkey_patches.rb +6 -3
  8. data/lib/super_diff/active_record/object_inspection.rb +16 -4
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +6 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -1
  11. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +1 -1
  12. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +1 -1
  13. data/lib/super_diff/active_record.rb +12 -16
  14. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +1 -1
  15. data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +44 -0
  16. data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +44 -0
  17. data/lib/super_diff/active_support/inspection_tree_builders.rb +14 -0
  18. data/lib/super_diff/active_support/object_inspection.rb +16 -4
  19. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +1 -1
  21. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +1 -1
  22. data/lib/super_diff/active_support.rb +11 -14
  23. data/lib/super_diff/basic/diff_formatters/collection.rb +135 -0
  24. data/lib/super_diff/basic/diff_formatters/multiline_string.rb +34 -0
  25. data/lib/super_diff/basic/diff_formatters.rb +11 -0
  26. data/lib/super_diff/basic/differs/array.rb +17 -0
  27. data/lib/super_diff/basic/differs/custom_object.rb +19 -0
  28. data/lib/super_diff/basic/differs/date_like.rb +17 -0
  29. data/lib/super_diff/basic/differs/default_object.rb +24 -0
  30. data/lib/super_diff/basic/differs/hash.rb +17 -0
  31. data/lib/super_diff/basic/differs/multiline_string.rb +18 -0
  32. data/lib/super_diff/basic/differs/time_like.rb +17 -0
  33. data/lib/super_diff/basic/differs.rb +24 -0
  34. data/lib/super_diff/basic/inspection_tree_builders/array.rb +53 -0
  35. data/lib/super_diff/basic/inspection_tree_builders/custom_object.rb +41 -0
  36. data/lib/super_diff/basic/inspection_tree_builders/date_like.rb +51 -0
  37. data/lib/super_diff/basic/inspection_tree_builders/default_object.rb +77 -0
  38. data/lib/super_diff/basic/inspection_tree_builders/hash.rb +63 -0
  39. data/lib/super_diff/basic/inspection_tree_builders/primitive.rb +19 -0
  40. data/lib/super_diff/basic/inspection_tree_builders/time_like.rb +58 -0
  41. data/lib/super_diff/basic/inspection_tree_builders.rb +20 -0
  42. data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
  43. data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
  44. data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
  45. data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
  46. data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
  47. data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
  48. data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
  49. data/lib/super_diff/basic/operation_tree_builders.rb +34 -0
  50. data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
  51. data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
  52. data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
  53. data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
  54. data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
  55. data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
  56. data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
  57. data/lib/super_diff/basic/operation_trees/array.rb +17 -0
  58. data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
  59. data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
  60. data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
  61. data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
  62. data/lib/super_diff/basic/operation_trees.rb +25 -0
  63. data/lib/super_diff/basic.rb +48 -0
  64. data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
  65. data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
  66. data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
  67. data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
  68. data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
  69. data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
  70. data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
  71. data/lib/super_diff/core/configuration.rb +192 -0
  72. data/lib/super_diff/core/differ_dispatcher.rb +33 -0
  73. data/lib/super_diff/core/gem_version.rb +47 -0
  74. data/lib/super_diff/core/helpers.rb +88 -0
  75. data/lib/super_diff/core/implementation_checks.rb +21 -0
  76. data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +32 -26
  77. data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
  78. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +12 -5
  79. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
  80. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
  81. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
  82. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
  83. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
  84. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
  85. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
  86. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
  87. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
  88. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
  89. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
  90. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
  91. data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
  92. data/lib/super_diff/core/line.rb +85 -0
  93. data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
  94. data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
  95. data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
  96. data/lib/super_diff/{errors/no_operational_sequencer_available_error.rb → core/no_operation_tree_builder_available_error.rb} +6 -4
  97. data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
  98. data/lib/super_diff/core/operation_tree_finder.rb +27 -0
  99. data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
  100. data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
  101. data/lib/super_diff/core/recursion_guard.rb +52 -0
  102. data/lib/super_diff/core/tiered_lines.rb +6 -0
  103. data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
  104. data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
  105. data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
  106. data/lib/super_diff/core.rb +69 -0
  107. data/lib/super_diff/differs.rb +19 -11
  108. data/lib/super_diff/equality_matchers/array.rb +3 -3
  109. data/lib/super_diff/equality_matchers/default.rb +8 -3
  110. data/lib/super_diff/equality_matchers/hash.rb +3 -3
  111. data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
  112. data/lib/super_diff/equality_matchers/primitive.rb +3 -3
  113. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  114. data/lib/super_diff/errors.rb +12 -12
  115. data/lib/super_diff/object_inspection.rb +63 -14
  116. data/lib/super_diff/operation_tree_builders.rb +19 -14
  117. data/lib/super_diff/operation_tree_flatteners.rb +19 -16
  118. data/lib/super_diff/operation_trees.rb +19 -9
  119. data/lib/super_diff/operations.rb +12 -2
  120. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  121. data/lib/super_diff/rspec/differ.rb +4 -5
  122. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
  123. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  124. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  125. data/lib/super_diff/rspec/differs/object_having_attributes.rb +1 -1
  126. data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
  127. data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
  128. data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
  129. data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
  130. data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
  131. data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
  132. data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
  133. data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
  134. data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
  135. data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
  136. data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
  137. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +3 -7
  138. data/lib/super_diff/rspec/monkey_patches.rb +59 -8
  139. data/lib/super_diff/rspec/object_inspection.rb +14 -4
  140. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
  141. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
  142. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
  143. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
  144. data/lib/super_diff/rspec.rb +28 -25
  145. data/lib/super_diff/version.rb +1 -1
  146. data/lib/super_diff.rb +78 -21
  147. data/spec/examples.txt +704 -493
  148. data/spec/integration/rails/engines_spec.rb +8 -3
  149. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
  150. data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
  151. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  152. data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
  153. data/spec/integration/rspec/include_matcher_spec.rb +23 -23
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
  156. data/spec/integration/rspec/match_matcher_spec.rb +93 -93
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
  158. data/spec/internal/log/test.log +0 -0
  159. data/spec/spec_helper.rb +3 -0
  160. data/spec/support/integration/helpers.rb +19 -11
  161. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
  162. data/spec/support/integration/matchers.rb +34 -0
  163. data/spec/support/integration/test_programs/base.rb +6 -6
  164. data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
  165. data/spec/support/models/active_record/person.rb +8 -1
  166. data/spec/support/shared_examples/active_record.rb +38 -38
  167. data/spec/support/shared_examples/active_support.rb +125 -4
  168. data/spec/support/shared_examples/elided_diffs.rb +48 -48
  169. data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
  170. data/spec/support/shared_examples/key.rb +10 -10
  171. data/spec/support/unit/helpers.rb +12 -1
  172. data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
  173. data/spec/unit/active_record/object_inspection_spec.rb +5 -5
  174. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  175. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
  176. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
  177. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
  178. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
  179. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
  180. data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
  181. data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
  182. data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
  183. data/spec/unit/deprecations_spec.rb +176 -0
  184. data/spec/unit/equality_matchers/main_spec.rb +5 -5
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  186. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  187. data/spec/unit/rspec/object_inspection_spec.rb +2 -2
  188. data/spec/unit/super_diff_spec.rb +64 -0
  189. data/super_diff.gemspec +6 -0
  190. metadata +137 -112
  191. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -39
  192. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -27
  193. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
  194. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -31
  195. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -12
  196. data/lib/super_diff/colorized_document_extensions.rb +0 -18
  197. data/lib/super_diff/configuration.rb +0 -149
  198. data/lib/super_diff/diff_formatters/collection.rb +0 -132
  199. data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
  200. data/lib/super_diff/differs/array.rb +0 -15
  201. data/lib/super_diff/differs/custom_object.rb +0 -17
  202. data/lib/super_diff/differs/default_object.rb +0 -19
  203. data/lib/super_diff/differs/defaults.rb +0 -12
  204. data/lib/super_diff/differs/empty.rb +0 -13
  205. data/lib/super_diff/differs/hash.rb +0 -15
  206. data/lib/super_diff/differs/main.rb +0 -31
  207. data/lib/super_diff/differs/multiline_string.rb +0 -16
  208. data/lib/super_diff/differs/time_like.rb +0 -15
  209. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  210. data/lib/super_diff/gem_version.rb +0 -45
  211. data/lib/super_diff/helpers.rb +0 -86
  212. data/lib/super_diff/implementation_checks.rb +0 -19
  213. data/lib/super_diff/line.rb +0 -83
  214. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +0 -34
  215. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
  216. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +0 -31
  217. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +0 -54
  218. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -14
  219. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +0 -38
  220. data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
  221. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +0 -21
  222. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +0 -47
  223. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -44
  224. data/lib/super_diff/object_inspection/nodes.rb +0 -50
  225. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
  226. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
  227. data/lib/super_diff/operation_tree_builders/array.rb +0 -107
  228. data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
  229. data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
  230. data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
  231. data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
  232. data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
  233. data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
  234. data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
  235. data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
  236. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
  237. data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
  238. data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
  239. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
  240. data/lib/super_diff/operation_trees/array.rb +0 -15
  241. data/lib/super_diff/operation_trees/custom_object.rb +0 -15
  242. data/lib/super_diff/operation_trees/default_object.rb +0 -40
  243. data/lib/super_diff/operation_trees/defaults.rb +0 -5
  244. data/lib/super_diff/operation_trees/hash.rb +0 -15
  245. data/lib/super_diff/operation_trees/main.rb +0 -35
  246. data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
  247. data/lib/super_diff/recursion_guard.rb +0 -50
  248. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -29
  249. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -36
  250. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -98
  251. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -37
  252. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -28
  253. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -28
  254. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -29
  255. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
  256. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -33
  257. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -44
  258. data/lib/super_diff/tiered_lines.rb +0 -4
  259. data/lib/super_diff/tiered_lines_elider.rb +0 -462
  260. data/lib/super_diff/tiered_lines_formatter.rb +0 -75
@@ -1,136 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeFlatteners
3
- class Collection < Base
4
- protected
5
-
6
- def build_tiered_lines
7
- [
8
- Line.new(
9
- type: :noop,
10
- indentation_level: indentation_level,
11
- value: open_token,
12
- collection_bookend: :open
13
- ),
14
- *inner_lines,
15
- Line.new(
16
- type: :noop,
17
- indentation_level: indentation_level,
18
- value: close_token,
19
- collection_bookend: :close
20
- )
21
- ]
22
- end
23
-
24
- def inner_lines
25
- @_inner_lines ||=
26
- operation_tree.flat_map do |operation|
27
- lines =
28
- if operation.name == :change
29
- build_lines_for_change_operation(operation)
30
- else
31
- build_lines_for_non_change_operation(operation)
32
- end
33
-
34
- maybe_add_prefix_at_beginning_of_lines(
35
- maybe_add_comma_at_end_of_lines(lines, operation),
36
- operation
37
- )
38
- end
39
- end
40
-
41
- def maybe_add_prefix_at_beginning_of_lines(lines, operation)
42
- if add_prefix_at_beginning_of_lines?(operation)
43
- add_prefix_at_beginning_of_lines(lines, operation)
44
- else
45
- lines
46
- end
47
- end
48
-
49
- def add_prefix_at_beginning_of_lines?(operation)
50
- !!item_prefix_for(operation)
51
- end
52
-
53
- def add_prefix_at_beginning_of_lines(lines, operation)
54
- [lines[0].prefixed_with(item_prefix_for(operation))] + lines[1..-1]
55
- end
56
-
57
- def maybe_add_comma_at_end_of_lines(lines, operation)
58
- if last_item_in_collection?(operation)
59
- lines
60
- else
61
- add_comma_at_end_of_lines(lines)
62
- end
63
- end
64
-
65
- def last_item_in_collection?(operation)
66
- if operation.name == :change
67
- operation.left_index == operation.left_collection.size - 1 &&
68
- operation.right_index == operation.right_collection.size - 1
69
- else
70
- operation.index == operation.collection.size - 1
71
- end
72
- end
73
-
74
- def add_comma_at_end_of_lines(lines)
75
- lines[0..-2] + [lines[-1].with_comma]
76
- end
77
-
78
- def build_lines_for_change_operation(operation)
79
- SuperDiff::RecursionGuard.guarding_recursion_of(
80
- operation.left_collection,
81
- operation.right_collection
82
- ) do |already_seen|
83
- if already_seen
84
- raise InfiniteRecursionError
85
- else
86
- operation.children.flatten(indentation_level: indentation_level + 1)
87
- end
88
- end
89
- end
90
-
91
- def build_lines_for_non_change_operation(operation)
92
- indentation_level = @indentation_level + 1
93
-
94
- if recursive_operation?(operation)
95
- [
96
- Line.new(
97
- type: operation.name,
98
- indentation_level: indentation_level,
99
- value: SuperDiff::RecursionGuard::PLACEHOLDER
100
- )
101
- ]
102
- else
103
- build_lines_from_inspection_of(
104
- operation.value,
105
- type: operation.name,
106
- indentation_level: indentation_level
107
- )
108
- end
109
- end
110
-
111
- def recursive_operation?(operation)
112
- operation.value.equal?(operation.collection) ||
113
- SuperDiff::RecursionGuard.already_seen?(operation.value)
114
- end
115
-
116
- def item_prefix_for(_operation)
117
- ""
118
- end
119
-
120
- def build_lines_from_inspection_of(value, type:, indentation_level:)
121
- SuperDiff.inspect_object(
122
- value,
123
- as_lines: true,
124
- type: type,
125
- indentation_level: indentation_level
126
- )
127
- end
128
-
129
- class InfiniteRecursionError < StandardError
130
- def initialize(_message = nil)
131
- super("Unhandled recursive data structure encountered!")
132
- end
133
- end
134
- end
135
- end
136
- end
@@ -1,28 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeFlatteners
3
- class CustomObject < Collection
4
- protected
5
-
6
- def open_token
7
- "#<%<class>s {" % { class: operation_tree.underlying_object.class }
8
- end
9
-
10
- def close_token
11
- "}>"
12
- end
13
-
14
- def item_prefix_for(operation)
15
- key =
16
- # Note: We could have used the right_key here too, they're both the
17
- # same keys
18
- if operation.respond_to?(:left_key)
19
- operation.left_key
20
- else
21
- operation.key
22
- end
23
-
24
- "#{key}: "
25
- end
26
- end
27
- end
28
- end
@@ -1,31 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeFlatteners
3
- class DefaultObject < Collection
4
- protected
5
-
6
- def open_token
7
- "#<#{operation_tree.underlying_object.class.name}:" +
8
- SuperDiff::Helpers.object_address_for(
9
- operation_tree.underlying_object
10
- ) + " {"
11
- end
12
-
13
- def close_token
14
- "}>"
15
- end
16
-
17
- def item_prefix_for(operation)
18
- key =
19
- # Note: We could have used the right_key here too, they're both the
20
- # same keys
21
- if operation.respond_to?(:left_key)
22
- operation.left_key
23
- else
24
- operation.key
25
- end
26
-
27
- "@#{key}="
28
- end
29
- end
30
- end
31
- end
@@ -1,33 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeFlatteners
3
- class Hash < Collection
4
- protected
5
-
6
- def open_token
7
- "{"
8
- end
9
-
10
- def close_token
11
- "}"
12
- end
13
-
14
- def item_prefix_for(operation)
15
- key = key_for(operation)
16
-
17
- format_keys_as_kwargs? ? "#{key}: " : "#{key.inspect} => "
18
- end
19
-
20
- private
21
-
22
- def format_keys_as_kwargs?
23
- operation_tree.all? { |operation| key_for(operation).is_a?(Symbol) }
24
- end
25
-
26
- def key_for(operation)
27
- # Note: We could have used the right_key here too, they're both the
28
- # same keys
29
- operation.respond_to?(:left_key) ? operation.left_key : operation.key
30
- end
31
- end
32
- end
33
- end
@@ -1,18 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeFlatteners
3
- class MultilineString < Base
4
- def build_tiered_lines
5
- operation_tree.map do |operation|
6
- Line.new(
7
- type: operation.name,
8
- indentation_level: indentation_level,
9
- # TODO: Test that quotes and things don't get escaped but escape
10
- # characters do
11
- value:
12
- operation.value.inspect[1..-2].gsub(/\\"/, '"').gsub(/\\'/, "'")
13
- )
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module OperationTrees
3
- class Array < Base
4
- def self.applies_to?(value)
5
- value.is_a?(::Array)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_flattener_class
11
- OperationTreeFlatteners::Array
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module OperationTrees
3
- class CustomObject < DefaultObject
4
- def self.applies_to?(value)
5
- value.respond_to?(:attributes_for_super_diff)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_flattener_class
11
- OperationTreeFlatteners::CustomObject
12
- end
13
- end
14
- end
15
- end
@@ -1,40 +0,0 @@
1
- module SuperDiff
2
- module OperationTrees
3
- class DefaultObject < Base
4
- def self.applies_to?(*)
5
- true
6
- end
7
-
8
- attr_reader :underlying_object
9
-
10
- def initialize(operations, underlying_object:)
11
- super(operations)
12
- @underlying_object = underlying_object
13
- end
14
-
15
- def pretty_print(pp)
16
- pp.text "#<#{self.class.name} "
17
- pp.nest(1) do
18
- pp.breakable
19
- pp.text ":operations=>"
20
- pp.group(1, "[", "]") do
21
- pp.breakable
22
- pp.seplist(self) { |value| pp.pp value }
23
- end
24
- pp.comma_breakable
25
- pp.text ":underlying_object=>"
26
- pp.object_address_group underlying_object do
27
- # do nothing
28
- end
29
- end
30
- pp.text ">"
31
- end
32
-
33
- protected
34
-
35
- def operation_tree_flattener_class
36
- OperationTreeFlatteners::DefaultObject
37
- end
38
- end
39
- end
40
- end
@@ -1,5 +0,0 @@
1
- module SuperDiff
2
- module OperationTrees
3
- DEFAULTS = [Array, Hash, CustomObject, DefaultObject].freeze
4
- end
5
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module OperationTrees
3
- class Hash < Base
4
- def self.applies_to?(value)
5
- value.is_a?(::Hash)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_flattener_class
11
- OperationTreeFlatteners::Hash
12
- end
13
- end
14
- end
15
- end
@@ -1,35 +0,0 @@
1
- module SuperDiff
2
- module OperationTrees
3
- class Main
4
- extend AttrExtras.mixin
5
-
6
- method_object :value
7
-
8
- def call
9
- if resolved_class
10
- begin
11
- resolved_class.new([], underlying_object: value)
12
- rescue ArgumentError
13
- resolved_class.new([])
14
- end
15
- else
16
- raise Errors::NoOperationalSequenceAvailableError.create(value)
17
- end
18
- end
19
-
20
- private
21
-
22
- def resolved_class
23
- if value.respond_to?(:attributes_for_super_diff)
24
- CustomObject
25
- else
26
- available_classes.find { |klass| klass.applies_to?(value) }
27
- end
28
- end
29
-
30
- def available_classes
31
- SuperDiff.configuration.extra_operation_tree_classes + DEFAULTS
32
- end
33
- end
34
- end
35
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module OperationTrees
3
- class MultilineString < Base
4
- def self.applies_to?(value)
5
- value.is_a?(::String) && value.is_a?(::String)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_flattener_class
11
- OperationTreeFlatteners::MultilineString
12
- end
13
- end
14
- end
15
- end
@@ -1,50 +0,0 @@
1
- require "set"
2
-
3
- module SuperDiff
4
- module RecursionGuard
5
- RECURSION_GUARD_KEY = "super_diff_recursion_guard_key".freeze
6
- PLACEHOLDER = "∙∙∙".freeze
7
-
8
- def self.guarding_recursion_of(*objects, &block)
9
- already_seen_objects, first_seen_objects =
10
- objects.partition do |object|
11
- !SuperDiff.primitive?(object) && already_seen?(object)
12
- end
13
-
14
- first_seen_objects.each do |object|
15
- already_seen_object_ids.add(object.object_id)
16
- end
17
-
18
- result =
19
- if block.arity > 0
20
- block.call(already_seen_objects.any?)
21
- else
22
- block.call
23
- end
24
-
25
- first_seen_objects.each do |object|
26
- already_seen_object_ids.delete(object.object_id)
27
- end
28
-
29
- result
30
- end
31
-
32
- def self.substituting_recursion_of(*objects)
33
- guarding_recursion_of(*objects) do |already_seen|
34
- if already_seen
35
- PLACEHOLDER
36
- else
37
- yield
38
- end
39
- end
40
- end
41
-
42
- def self.already_seen?(object)
43
- already_seen_object_ids.include?(object.object_id)
44
- end
45
-
46
- def self.already_seen_object_ids
47
- Thread.current[RECURSION_GUARD_KEY] ||= Set.new
48
- end
49
- end
50
- end
@@ -1,29 +0,0 @@
1
- module SuperDiff
2
- module RSpec
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class CollectionContainingExactly < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
- def self.applies_to?(value)
7
- SuperDiff::RSpec.a_collection_containing_exactly_something?(value)
8
- end
9
-
10
- def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do
12
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
13
- add_text "#<a collection containing exactly ("
14
- end
15
-
16
- nested do |aliased_matcher|
17
- insert_array_inspection_of(aliased_matcher.expected)
18
- end
19
-
20
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
21
- add_text ")>"
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,36 +0,0 @@
1
- module SuperDiff
2
- module RSpec
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class CollectionIncluding < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
- def self.applies_to?(value)
7
- SuperDiff::RSpec.a_collection_including_something?(value) ||
8
- SuperDiff::RSpec.array_including_something?(value)
9
- end
10
-
11
- def call
12
- SuperDiff::ObjectInspection::InspectionTree.new do
13
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
14
- add_text "#<a collection including ("
15
- end
16
-
17
- nested do |value|
18
- array =
19
- if SuperDiff::RSpec.a_collection_including_something?(value)
20
- value.expecteds
21
- else
22
- value.instance_variable_get(:@expected)
23
- end
24
- insert_array_inspection_of(array)
25
- end
26
-
27
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
28
- add_text ")>"
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,98 +0,0 @@
1
- module SuperDiff
2
- module RSpec
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class Double < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
- def self.applies_to?(value)
7
- value.is_a?(::RSpec::Mocks::Double)
8
- end
9
-
10
- def call
11
- builder = self
12
- empty = -> { empty? }
13
- nonempty = -> { !empty? }
14
-
15
- SuperDiff::ObjectInspection::InspectionTree.new do
16
- only_when empty do
17
- as_lines_when_rendering_to_lines do
18
- add_text do |object|
19
- inspected_class = builder.inspected_class
20
- inspected_name = builder.inspected_name
21
- "#<#{inspected_class} #{inspected_name}>"
22
- end
23
- end
24
- end
25
-
26
- only_when nonempty do
27
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
28
- add_text do |object|
29
- inspected_class = builder.inspected_class
30
- inspected_name = builder.inspected_name
31
- "#<#{inspected_class} #{inspected_name}"
32
- end
33
-
34
- when_rendering_to_lines { add_text " {" }
35
- end
36
-
37
- when_rendering_to_string { add_text " " }
38
-
39
- nested do |object|
40
- insert_hash_inspection_of(builder.doubled_methods)
41
- end
42
-
43
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
44
- when_rendering_to_lines { add_text "}" }
45
-
46
- add_text ">"
47
- end
48
- end
49
- end
50
- end
51
-
52
- def empty?
53
- doubled_methods.empty?
54
- end
55
-
56
- def nonempty?
57
- !empty?
58
- end
59
-
60
- def inspected_class
61
- case object
62
- when ::RSpec::Mocks::InstanceVerifyingDouble
63
- "InstanceDouble"
64
- when ::RSpec::Mocks::ClassVerifyingDouble
65
- "ClassDouble"
66
- when ::RSpec::Mocks::ObjectVerifyingDouble
67
- "ObjectDouble"
68
- else
69
- "Double"
70
- end
71
- end
72
-
73
- def inspected_name
74
- if object.instance_variable_get("@name")
75
- object.instance_variable_get("@name").inspect
76
- else
77
- "(anonymous)"
78
- end
79
- end
80
-
81
- def doubled_methods
82
- @_doubled_methods ||=
83
- doubled_method_names.reduce({}) do |hash, key|
84
- hash.merge(key => object.public_send(key))
85
- end
86
- end
87
-
88
- def doubled_method_names
89
- object
90
- .__send__(:__mock_proxy)
91
- .instance_variable_get("@method_doubles")
92
- .keys
93
- end
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,37 +0,0 @@
1
- module SuperDiff
2
- module RSpec
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class HashIncluding < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
- def self.applies_to?(value)
7
- SuperDiff::RSpec.a_hash_including_something?(value) ||
8
- SuperDiff::RSpec.hash_including_something?(value)
9
- end
10
-
11
- def call
12
- SuperDiff::ObjectInspection::InspectionTree.new do
13
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
14
- add_text "#<a hash including ("
15
- end
16
-
17
- nested do |value|
18
- hash =
19
- if SuperDiff::RSpec.a_hash_including_something?(value)
20
- value.expecteds.first
21
- else
22
- value.instance_variable_get(:@expected)
23
- end
24
-
25
- insert_hash_inspection_of(hash)
26
- end
27
-
28
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
29
- add_text ")>"
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,28 +0,0 @@
1
- module SuperDiff
2
- module RSpec
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class InstanceOf < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
- def self.applies_to?(value)
7
- SuperDiff::RSpec.an_instance_of_something?(value) ||
8
- SuperDiff::RSpec.instance_of_something?(value)
9
- end
10
-
11
- def call
12
- SuperDiff::ObjectInspection::InspectionTree.new do
13
- add_text do |value|
14
- klass =
15
- if SuperDiff::RSpec.an_instance_of_something?(value)
16
- value.expected
17
- else
18
- value.instance_variable_get(:@klass)
19
- end
20
- "#<an instance of #{klass}>"
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end