super_diff 0.11.0 → 0.13.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 (242) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -182
  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 -15
  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/{object_inspection → basic}/inspection_tree_builders/array.rb +3 -3
  35. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/custom_object.rb +3 -3
  36. data/lib/super_diff/basic/inspection_tree_builders/data_object.rb +40 -0
  37. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/date_like.rb +3 -3
  38. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/default_object.rb +5 -7
  39. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/hash.rb +3 -3
  40. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/primitive.rb +4 -4
  41. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/time_like.rb +3 -3
  42. data/lib/super_diff/basic/inspection_tree_builders.rb +24 -0
  43. data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
  44. data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
  45. data/lib/super_diff/basic/operation_tree_builders/data_object.rb +18 -0
  46. data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
  47. data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
  48. data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
  49. data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
  50. data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
  51. data/lib/super_diff/basic/operation_tree_builders.rb +38 -0
  52. data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
  53. data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
  54. data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
  55. data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
  56. data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
  57. data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
  58. data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
  59. data/lib/super_diff/basic/operation_trees/array.rb +17 -0
  60. data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
  61. data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
  62. data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
  63. data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
  64. data/lib/super_diff/basic/operation_trees.rb +25 -0
  65. data/lib/super_diff/basic.rb +50 -0
  66. data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
  67. data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
  68. data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
  69. data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
  70. data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
  71. data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
  72. data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
  73. data/lib/super_diff/core/configuration.rb +196 -0
  74. data/lib/super_diff/core/differ_dispatcher.rb +31 -0
  75. data/lib/super_diff/core/gem_version.rb +47 -0
  76. data/lib/super_diff/core/helpers.rb +88 -0
  77. data/lib/super_diff/core/implementation_checks.rb +21 -0
  78. data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +7 -6
  79. data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
  80. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +9 -3
  81. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
  82. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
  83. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
  84. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
  85. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
  86. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
  87. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
  88. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
  89. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
  90. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
  91. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
  92. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
  93. data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
  94. data/lib/super_diff/core/line.rb +85 -0
  95. data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
  96. data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
  97. data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
  98. data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +24 -0
  99. data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
  100. data/lib/super_diff/core/operation_tree_finder.rb +27 -0
  101. data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
  102. data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
  103. data/lib/super_diff/core/recursion_guard.rb +52 -0
  104. data/lib/super_diff/core/tiered_lines.rb +6 -0
  105. data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
  106. data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
  107. data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
  108. data/lib/super_diff/core.rb +69 -0
  109. data/lib/super_diff/csi.rb +0 -32
  110. data/lib/super_diff/differs.rb +19 -12
  111. data/lib/super_diff/equality_matchers/array.rb +3 -3
  112. data/lib/super_diff/equality_matchers/default.rb +8 -3
  113. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  114. data/lib/super_diff/equality_matchers/hash.rb +3 -3
  115. data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
  116. data/lib/super_diff/equality_matchers/primitive.rb +3 -3
  117. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  118. data/lib/super_diff/errors.rb +12 -8
  119. data/lib/super_diff/object_inspection.rb +63 -14
  120. data/lib/super_diff/operation_tree_builders.rb +19 -15
  121. data/lib/super_diff/operation_tree_flatteners.rb +19 -16
  122. data/lib/super_diff/operation_trees.rb +19 -9
  123. data/lib/super_diff/operations.rb +12 -2
  124. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  125. data/lib/super_diff/rspec/differ.rb +4 -5
  126. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
  127. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  128. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  129. data/lib/super_diff/rspec/differs/object_having_attributes.rb +1 -1
  130. data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
  131. data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
  132. data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
  133. data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
  134. data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
  135. data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
  136. data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
  137. data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
  138. data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
  139. data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
  140. data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
  141. data/lib/super_diff/rspec/object_inspection.rb +14 -4
  142. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
  143. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
  144. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
  145. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
  146. data/lib/super_diff/rspec.rb +20 -18
  147. data/lib/super_diff/version.rb +1 -1
  148. data/lib/super_diff.rb +70 -23
  149. data/spec/examples.txt +450 -543
  150. data/spec/spec_helper.rb +1 -0
  151. data/spec/support/integration/helpers.rb +4 -1
  152. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
  153. data/spec/support/models/active_record/person.rb +8 -1
  154. data/spec/support/models/point.rb +7 -0
  155. data/spec/support/shared_examples/active_record.rb +5 -5
  156. data/spec/support/unit/helpers.rb +12 -1
  157. data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
  158. data/spec/unit/active_record/object_inspection_spec.rb +5 -5
  159. data/spec/unit/basic/inspection_tree_builders/data_object_spec.rb +146 -0
  160. data/spec/unit/basic/operation_tree_builders/data_object_spec.rb +82 -0
  161. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
  162. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
  163. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
  164. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
  165. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
  166. data/spec/unit/core/configuration_no_rspec_spec.rb +58 -0
  167. data/spec/unit/core/configuration_spec.rb +176 -0
  168. data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
  169. data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
  170. data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
  171. data/spec/unit/deprecations_spec.rb +176 -0
  172. data/spec/unit/equality_matchers/main_spec.rb +5 -5
  173. data/super_diff.gemspec +10 -3
  174. metadata +144 -120
  175. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -51
  176. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -36
  177. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
  178. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -46
  179. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +0 -46
  180. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -16
  181. data/lib/super_diff/colorized_document_extensions.rb +0 -18
  182. data/lib/super_diff/configuration.rb +0 -149
  183. data/lib/super_diff/diff_formatters/collection.rb +0 -132
  184. data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
  185. data/lib/super_diff/differs/array.rb +0 -15
  186. data/lib/super_diff/differs/custom_object.rb +0 -17
  187. data/lib/super_diff/differs/date_like.rb +0 -15
  188. data/lib/super_diff/differs/default_object.rb +0 -19
  189. data/lib/super_diff/differs/defaults.rb +0 -13
  190. data/lib/super_diff/differs/empty.rb +0 -13
  191. data/lib/super_diff/differs/hash.rb +0 -15
  192. data/lib/super_diff/differs/main.rb +0 -31
  193. data/lib/super_diff/differs/multiline_string.rb +0 -16
  194. data/lib/super_diff/differs/time_like.rb +0 -15
  195. data/lib/super_diff/gem_version.rb +0 -45
  196. data/lib/super_diff/helpers.rb +0 -86
  197. data/lib/super_diff/implementation_checks.rb +0 -19
  198. data/lib/super_diff/line.rb +0 -83
  199. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
  200. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -15
  201. data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
  202. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -48
  203. data/lib/super_diff/object_inspection/nodes.rb +0 -50
  204. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
  205. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
  206. data/lib/super_diff/operation_tree_builders/array.rb +0 -107
  207. data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
  208. data/lib/super_diff/operation_tree_builders/date_like.rb +0 -15
  209. data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
  210. data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
  211. data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
  212. data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
  213. data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
  214. data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
  215. data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
  216. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
  217. data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
  218. data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
  219. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
  220. data/lib/super_diff/operation_trees/array.rb +0 -15
  221. data/lib/super_diff/operation_trees/custom_object.rb +0 -15
  222. data/lib/super_diff/operation_trees/default_object.rb +0 -40
  223. data/lib/super_diff/operation_trees/defaults.rb +0 -5
  224. data/lib/super_diff/operation_trees/hash.rb +0 -15
  225. data/lib/super_diff/operation_trees/main.rb +0 -35
  226. data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
  227. data/lib/super_diff/recursion_guard.rb +0 -50
  228. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -36
  229. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -42
  230. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -102
  231. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +0 -19
  232. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -42
  233. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -27
  234. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -27
  235. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -36
  236. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
  237. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -32
  238. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -48
  239. data/lib/super_diff/tiered_lines.rb +0 -4
  240. data/lib/super_diff/tiered_lines_elider.rb +0 -462
  241. data/lib/super_diff/tiered_lines_formatter.rb +0 -75
  242. data/spec/internal/log/test.log +0 -0
data/spec/spec_helper.rb CHANGED
@@ -68,6 +68,7 @@ RSpec.configure do |config|
68
68
  unless defined?(ActiveSupport)
69
69
  config.filter_run_excluding active_support: true
70
70
  end
71
+ config.filter_run_excluding with_superdiff_rspec: false
71
72
 
72
73
  config.order = :random
73
74
  Kernel.srand config.seed
@@ -115,7 +115,10 @@ module SuperDiff
115
115
  end
116
116
 
117
117
  def colored(color_enabled: true, &block)
118
- SuperDiff::Helpers.style(color_enabled: color_enabled, &block).to_s.chomp
118
+ SuperDiff::Core::Helpers
119
+ .style(color_enabled: color_enabled, &block)
120
+ .to_s
121
+ .chomp
119
122
  end
120
123
  end
121
124
  end
@@ -12,7 +12,7 @@ module SuperDiff
12
12
  end
13
13
 
14
14
  def removing_object_ids
15
- first_replacing(/#<([\w:]+):0x[a-f0-9]+/, '#<\1')
15
+ first_replacing(/#<([\w_:]+):0x[a-f0-9]+/, '#<\1')
16
16
  self
17
17
  end
18
18
 
@@ -3,6 +3,7 @@ module SuperDiff
3
3
  module Models
4
4
  module ActiveRecord
5
5
  class Person < ::ActiveRecord::Base
6
+ self.primary_key = "person_id"
6
7
  end
7
8
  end
8
9
  end
@@ -13,7 +14,13 @@ RSpec.configure do |config|
13
14
  config.before do
14
15
  ActiveRecord::Base
15
16
  .connection
16
- .create_table(:people, force: true) do |t|
17
+ .create_table(
18
+ :people,
19
+ id: false,
20
+ primary_key: "person_id",
21
+ force: true
22
+ ) do |t|
23
+ t.primary_key :person_id, null: false
17
24
  t.string :name, null: false
18
25
  t.integer :age, null: false
19
26
  end
@@ -0,0 +1,7 @@
1
+ if defined?(Data)
2
+ module SuperDiff
3
+ module Test
4
+ Point = Data.define(:x, :y)
5
+ end
6
+ end
7
+ end
@@ -86,7 +86,7 @@ shared_examples_for "integration with ActiveRecord" do
86
86
  proc do
87
87
  line do
88
88
  plain "Expected "
89
- actual %|#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">|
89
+ actual %|#<SuperDiff::Test::Models::ActiveRecord::Person person_id: nil, age: 31, name: "Elliot">|
90
90
  end
91
91
 
92
92
  line do
@@ -244,7 +244,7 @@ shared_examples_for "integration with ActiveRecord" do
244
244
  proc do
245
245
  line do
246
246
  plain "Expected "
247
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot"> }|
247
+ actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person person_id: nil, age: 31, name: "Elliot"> }|
248
248
  end
249
249
 
250
250
  line do
@@ -265,7 +265,7 @@ shared_examples_for "integration with ActiveRecord" do
265
265
  expected_line %|- zip: "90382"|
266
266
  expected_line "- }>"
267
267
  actual_line "+ shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person {"
268
- actual_line "+ id: nil,"
268
+ actual_line "+ person_id: nil,"
269
269
  actual_line "+ age: 31,"
270
270
  actual_line %|+ name: "Elliot"|
271
271
  actual_line "+ }>"
@@ -390,7 +390,7 @@ shared_examples_for "integration with ActiveRecord" do
390
390
  proc do
391
391
  line do
392
392
  plain "Expected "
393
- actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 20, name: "Murphy">]>>]|
393
+ actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person person_id: 1, age: 20, name: "Murphy">]>>]|
394
394
  end
395
395
 
396
396
  line do
@@ -404,7 +404,7 @@ shared_examples_for "integration with ActiveRecord" do
404
404
  plain_line " #<SuperDiff::Test::Models::ActiveRecord::Query {"
405
405
  plain_line " @results=#<ActiveRecord::Relation ["
406
406
  plain_line " #<SuperDiff::Test::Models::ActiveRecord::Person {"
407
- plain_line " id: 1,"
407
+ plain_line " person_id: 1,"
408
408
  # expected_line %|- age: 19,| # TODO
409
409
  expected_line "- age: 19"
410
410
  actual_line "+ age: 20,"
@@ -1,5 +1,7 @@
1
1
  module SuperDiff
2
2
  module UnitTests
3
+ extend self
4
+
3
5
  def with_configuration(configuration)
4
6
  old_configuration = SuperDiff.configuration.dup
5
7
  SuperDiff.configuration.merge!(configuration)
@@ -7,7 +9,16 @@ module SuperDiff
7
9
  end
8
10
 
9
11
  def colored(*args, **opts, &block)
10
- SuperDiff::Helpers.style(*args, **opts, &block).to_s.chomp
12
+ SuperDiff::Core::Helpers.style(*args, **opts, &block).to_s.chomp
13
+ end
14
+
15
+ def capture_warnings
16
+ fake_stderr = StringIO.new
17
+ original_stderr = $stderr
18
+ $stderr = fake_stderr
19
+ yield
20
+ $stderr = original_stderr
21
+ fake_stderr.string
11
22
  end
12
23
  end
13
24
  end
@@ -0,0 +1,39 @@
1
+ module SuperDiff
2
+ module UnitTests
3
+ def be_deprecated_in_favor_of(new_constant_name)
4
+ BeDeprecatedInFavorOfMatcher.new(new_constant_name)
5
+ end
6
+
7
+ class BeDeprecatedInFavorOfMatcher
8
+ extend AttrExtras.mixin
9
+
10
+ pattr_initialize :new_constant_name
11
+ attr_private :actual_output, :old_constant_name
12
+
13
+ def matches?(old_constant_name)
14
+ @old_constant_name = old_constant_name
15
+ @actual_output =
16
+ SuperDiff::UnitTests.capture_warnings do
17
+ Object.const_get(old_constant_name)
18
+ end
19
+ @actual_output.start_with?(expected_prefix)
20
+ end
21
+
22
+ def failure_message
23
+ "Expected stderr to start with:\n\n" +
24
+ SuperDiff::Test::OutputHelpers.bookended(expected_prefix) + "\n" +
25
+ "Actual output:\n\n" +
26
+ SuperDiff::Test::OutputHelpers.bookended(actual_output)
27
+ end
28
+
29
+ private
30
+
31
+ def expected_prefix
32
+ <<~EOT.rstrip
33
+ WARNING: #{old_constant_name} is deprecated and will be removed in the next major release.
34
+ Please use #{new_constant_name} instead.
35
+ EOT
36
+ end
37
+ end
38
+ end
39
+ end
@@ -14,7 +14,7 @@ RSpec.describe SuperDiff, type: :unit do
14
14
  as_lines: false
15
15
  )
16
16
  expect(string).to eq(
17
- %(#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">)
17
+ %(#<SuperDiff::Test::Models::ActiveRecord::Person person_id: nil, age: 31, name: "Elliot">)
18
18
  )
19
19
  end
20
20
  end
@@ -42,7 +42,7 @@ RSpec.describe SuperDiff, type: :unit do
42
42
  an_object_having_attributes(
43
43
  type: :delete,
44
44
  indentation_level: 2,
45
- prefix: "id: ",
45
+ prefix: "person_id: ",
46
46
  value: "nil",
47
47
  add_comma: true
48
48
  ),
@@ -91,7 +91,7 @@ RSpec.describe SuperDiff, type: :unit do
91
91
  )
92
92
 
93
93
  expect(string).to eq(
94
- %(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person id: 2, age: 17, name: "Jennifer">]>)
94
+ %(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person person_id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person person_id: 2, age: 17, name: "Jennifer">]>)
95
95
  )
96
96
  end
97
97
  end
@@ -132,7 +132,7 @@ RSpec.describe SuperDiff, type: :unit do
132
132
  an_object_having_attributes(
133
133
  type: :delete,
134
134
  indentation_level: 3,
135
- prefix: "id: ",
135
+ prefix: "person_id: ",
136
136
  value: "1",
137
137
  add_comma: true
138
138
  ),
@@ -165,7 +165,7 @@ RSpec.describe SuperDiff, type: :unit do
165
165
  an_object_having_attributes(
166
166
  type: :delete,
167
167
  indentation_level: 3,
168
- prefix: "id: ",
168
+ prefix: "person_id: ",
169
169
  value: "2",
170
170
  add_comma: true
171
171
  ),
@@ -0,0 +1,146 @@
1
+ require "spec_helper"
2
+
3
+ if defined?(Data)
4
+ RSpec.describe SuperDiff, type: :unit do
5
+ describe ".inspect_object" do
6
+ context "given as_lines: false" do
7
+ subject(:output) do
8
+ described_class.inspect_object(object, as_lines: false)
9
+ end
10
+
11
+ context "given an anonymous Data object" do
12
+ let(:object) { Data.define(:x, :y).new(1, 2) }
13
+
14
+ it "shows the data" do
15
+ expect(output).to eq("#<data x: 1, y: 2>")
16
+ end
17
+ end
18
+
19
+ context "given a named Data object" do
20
+ let(:object) { SuperDiff::Test::Point.new(1, 2) }
21
+
22
+ it "shows the data" do
23
+ expect(output).to eq("#<data SuperDiff::Test::Point x: 1, y: 2>")
24
+ end
25
+ end
26
+
27
+ context "given a Data object that defines #attributes_for_super_diff" do
28
+ let(:klass) do
29
+ Data.define(:x, :y) do
30
+ def attributes_for_super_diff
31
+ { beep: :boop }
32
+ end
33
+ end
34
+ end
35
+ let(:object) { klass.new(1, 2) }
36
+
37
+ it "uses the custom attributes" do
38
+ expect(output).to start_with("#<#<Class:0x").and end_with(
39
+ "beep: :boop>"
40
+ )
41
+ end
42
+ end
43
+ end
44
+
45
+ context "given as_lines: true" do
46
+ subject(:tiered_lines) do
47
+ described_class.inspect_object(
48
+ object,
49
+ as_lines: true,
50
+ type: :noop,
51
+ indentation_level: 1
52
+ )
53
+ end
54
+
55
+ context "given an anonymous Data object" do
56
+ let(:object) { Data.define(:x, :y).new(1, 2) }
57
+
58
+ it "shows the data" do
59
+ expect(tiered_lines).to match(
60
+ [
61
+ an_object_having_attributes(
62
+ value: "#<data {",
63
+ collection_bookend: :open
64
+ ),
65
+ an_object_having_attributes(
66
+ prefix: "x: ",
67
+ value: "1",
68
+ add_comma: true
69
+ ),
70
+ an_object_having_attributes(
71
+ prefix: "y: ",
72
+ value: "2",
73
+ add_comma: false
74
+ ),
75
+ an_object_having_attributes(
76
+ value: "}>",
77
+ collection_bookend: :close
78
+ )
79
+ ]
80
+ )
81
+ end
82
+ end
83
+
84
+ context "given a named Data object" do
85
+ let(:object) { SuperDiff::Test::Point.new(1, 2) }
86
+
87
+ it "shows the data" do
88
+ expect(tiered_lines).to match(
89
+ [
90
+ an_object_having_attributes(
91
+ value: "#<data SuperDiff::Test::Point {",
92
+ collection_bookend: :open
93
+ ),
94
+ an_object_having_attributes(
95
+ prefix: "x: ",
96
+ value: "1",
97
+ add_comma: true
98
+ ),
99
+ an_object_having_attributes(
100
+ prefix: "y: ",
101
+ value: "2",
102
+ add_comma: false
103
+ ),
104
+ an_object_having_attributes(
105
+ value: "}>",
106
+ collection_bookend: :close
107
+ )
108
+ ]
109
+ )
110
+ end
111
+ end
112
+
113
+ context "given a Data object that defines #attributes_for_super_diff" do
114
+ let(:klass) do
115
+ Data.define(:x, :y) do
116
+ def attributes_for_super_diff
117
+ { beep: :boop }
118
+ end
119
+ end
120
+ end
121
+ let(:object) { klass.new(1, 2) }
122
+
123
+ it "uses the custom attributes" do
124
+ expect(tiered_lines).to match(
125
+ [
126
+ an_object_having_attributes(
127
+ value: /\A#<#<Class:0x.*> {/,
128
+ collection_bookend: :open
129
+ ),
130
+ an_object_having_attributes(
131
+ prefix: "beep: ",
132
+ value: ":boop",
133
+ add_comma: false
134
+ ),
135
+ an_object_having_attributes(
136
+ value: "}>",
137
+ collection_bookend: :close
138
+ )
139
+ ]
140
+ )
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ if defined?(Data)
4
+ RSpec.describe SuperDiff, type: :unit do
5
+ describe ".diff" do
6
+ subject(:diff) { described_class.diff(a, b) }
7
+
8
+ context "when given two Data objects of the same class" do
9
+ let(:a) { SuperDiff::Test::Point.new(1, 2) }
10
+ let(:b) { SuperDiff::Test::Point.new(1, 3) }
11
+
12
+ it "diffs their member attributes" do
13
+ expected_output =
14
+ SuperDiff::Core::Helpers
15
+ .style(color_enabled: true) do
16
+ plain_line " #<SuperDiff::Test::Point {"
17
+ plain_line " x: 1,"
18
+ expected_line "- y: 2"
19
+ actual_line "+ y: 3"
20
+ plain_line " }>"
21
+ end
22
+ .to_s
23
+ .chomp
24
+
25
+ expect(diff).to eq(expected_output)
26
+ end
27
+
28
+ context "when the Data class defines #attributes_for_super_diff" do
29
+ let(:klass) do
30
+ Class.new(Data.define(:attribute)) do
31
+ def self.to_s = "TestClass"
32
+
33
+ def attributes_for_super_diff
34
+ { attribute: :does_not_matter }
35
+ end
36
+ end
37
+ end
38
+
39
+ let(:a) { klass.new(1) }
40
+ let(:b) { klass.new(2) }
41
+
42
+ it "diffs their member attributes" do
43
+ expected_output =
44
+ SuperDiff::Core::Helpers
45
+ .style(color_enabled: true) do
46
+ plain_line " #<TestClass {"
47
+ expected_line "- attribute: 1"
48
+ actual_line "+ attribute: 2"
49
+ plain_line " }>"
50
+ end
51
+ .to_s
52
+ .chomp
53
+
54
+ expect(diff).to eq(expected_output)
55
+ end
56
+ end
57
+ end
58
+
59
+ context "when given two Data objects of different classes" do
60
+ let(:a) { SuperDiff::Test::Point.new(1, 2) }
61
+ let(:b) { Data.define(:one, :two).new(1, 2) }
62
+
63
+ it "raises" do
64
+ expect { SuperDiff.diff(a, b) }.to raise_error(
65
+ SuperDiff::Core::NoDifferAvailableError
66
+ )
67
+ end
68
+ end
69
+
70
+ context "when given a Data object and a hash" do
71
+ let(:a) { Data.define(:one, :two).new(1, 2) }
72
+ let(:b) { { one: 1, two: 2 } }
73
+
74
+ it "raises" do
75
+ expect { SuperDiff.diff(a, b) }.to raise_error(
76
+ SuperDiff::Core::NoDifferAvailableError
77
+ )
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
3
+ RSpec.describe SuperDiff::Basic::OperationTreeFlatteners::Array do
4
4
  context "given an empty tree" do
5
5
  it "returns a set of lines which are simply the open token and close token" do
6
6
  expect(described_class.call([])).to match(
@@ -30,7 +30,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
30
30
  it "returns a series of lines from inspecting each value, creating multiple lines upon encountering inner data structures" do
31
31
  collection = Array.new(3) { :some_value }
32
32
  operation_tree =
33
- SuperDiff::OperationTrees::Array.new(
33
+ SuperDiff::Basic::OperationTrees::Array.new(
34
34
  [
35
35
  double(
36
36
  :operation,
@@ -134,7 +134,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
134
134
  expected = Array.new(3) { :some_value }
135
135
  actual = Array.new(4) { :some_value }
136
136
  operation_tree =
137
- SuperDiff::OperationTrees::Array.new(
137
+ SuperDiff::Basic::OperationTrees::Array.new(
138
138
  [
139
139
  double(
140
140
  :operation,
@@ -266,7 +266,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
266
266
  collection = Array.new(3) { :some_value }
267
267
  subcollection = Array.new(2) { :some_value }
268
268
  operation_tree =
269
- SuperDiff::OperationTrees::Array.new(
269
+ SuperDiff::Basic::OperationTrees::Array.new(
270
270
  [
271
271
  double(
272
272
  :operation,
@@ -283,7 +283,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
283
283
  right_collection: collection,
284
284
  right_index: 1,
285
285
  children:
286
- SuperDiff::OperationTrees::Array.new(
286
+ SuperDiff::Basic::OperationTrees::Array.new(
287
287
  [
288
288
  double(
289
289
  :operation,
@@ -406,7 +406,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
406
406
  right_collection << right_collection
407
407
 
408
408
  operation_tree =
409
- SuperDiff::OperationTrees::Array.new(
409
+ SuperDiff::Basic::OperationTrees::Array.new(
410
410
  [
411
411
  double(
412
412
  :operation,
@@ -502,7 +502,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
502
502
  right_subcollection << right_subcollection
503
503
 
504
504
  operation_tree =
505
- SuperDiff::OperationTrees::Array.new(
505
+ SuperDiff::Basic::OperationTrees::Array.new(
506
506
  [
507
507
  double(
508
508
  :operation,
@@ -519,7 +519,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::Array do
519
519
  right_collection: collection,
520
520
  right_index: 1,
521
521
  children:
522
- SuperDiff::OperationTrees::Array.new(
522
+ SuperDiff::Basic::OperationTrees::Array.new(
523
523
  [
524
524
  double(
525
525
  :operation,
@@ -1,10 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
3
+ RSpec.describe SuperDiff::Basic::OperationTreeFlatteners::CustomObject do
4
4
  context "given an empty tree" do
5
5
  it "returns a set of lines which are simply the open token and close token" do
6
6
  operation_tree =
7
- SuperDiff::OperationTrees::CustomObject.new(
7
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
8
8
  [],
9
9
  underlying_object: underlying_object
10
10
  )
@@ -38,7 +38,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
38
38
  it "returns a series of lines from inspecting each value, creating multiple lines upon encountering inner data structures" do
39
39
  collection = Array.new(3) { :some_value }
40
40
  operation_tree =
41
- SuperDiff::OperationTrees::CustomObject.new(
41
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
42
42
  [
43
43
  double(
44
44
  :operation,
@@ -146,7 +146,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
146
146
  expected = Array.new(3) { :some_value }
147
147
  actual = Array.new(4) { :some_value }
148
148
  operation_tree =
149
- SuperDiff::OperationTrees::CustomObject.new(
149
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
150
150
  [
151
151
  double(
152
152
  :operation,
@@ -284,7 +284,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
284
284
  collection = Array.new(3) { :some_value }
285
285
  subcollection = Array.new(2) { :some_value }
286
286
  operation_tree =
287
- SuperDiff::OperationTrees::CustomObject.new(
287
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
288
288
  [
289
289
  double(
290
290
  :operation,
@@ -304,7 +304,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
304
304
  right_key: :baz,
305
305
  right_index: 1,
306
306
  children:
307
- SuperDiff::OperationTrees::CustomObject.new(
307
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
308
308
  [
309
309
  double(
310
310
  :operation,
@@ -435,7 +435,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
435
435
  .tap { |collection| collection << right_collection }
436
436
 
437
437
  operation_tree =
438
- SuperDiff::OperationTrees::CustomObject.new(
438
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
439
439
  [
440
440
  double(
441
441
  :operation,
@@ -536,7 +536,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
536
536
  Array.new(1) { :some_value }.tap { |coll| coll << right_subcollection }
537
537
 
538
538
  operation_tree =
539
- SuperDiff::OperationTrees::CustomObject.new(
539
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
540
540
  [
541
541
  double(
542
542
  :operation,
@@ -556,7 +556,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::CustomObject do
556
556
  right_key: :baz,
557
557
  right_index: 1,
558
558
  children:
559
- SuperDiff::OperationTrees::CustomObject.new(
559
+ SuperDiff::Basic::OperationTrees::CustomObject.new(
560
560
  [
561
561
  double(
562
562
  :operation,
@@ -1,10 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
3
+ RSpec.describe SuperDiff::Basic::OperationTreeFlatteners::DefaultObject do
4
4
  context "given an empty tree" do
5
5
  it "returns a set of lines which are simply the open token and close token" do
6
6
  operation_tree =
7
- SuperDiff::OperationTrees::DefaultObject.new(
7
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
8
8
  [],
9
9
  underlying_object: underlying_object
10
10
  )
@@ -38,7 +38,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
38
38
  it "returns a series of lines from inspecting each value, creating multiple lines upon encountering inner data structures" do
39
39
  collection = Array.new(3) { :some_value }
40
40
  operation_tree =
41
- SuperDiff::OperationTrees::DefaultObject.new(
41
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
42
42
  [
43
43
  double(
44
44
  :operation,
@@ -146,7 +146,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
146
146
  expected = Array.new(3) { :some_value }
147
147
  actual = Array.new(4) { :some_value }
148
148
  operation_tree =
149
- SuperDiff::OperationTrees::DefaultObject.new(
149
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
150
150
  [
151
151
  double(
152
152
  :operation,
@@ -284,7 +284,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
284
284
  collection = Array.new(3) { :some_value }
285
285
  subcollection = Array.new(2) { :some_value }
286
286
  operation_tree =
287
- SuperDiff::OperationTrees::DefaultObject.new(
287
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
288
288
  [
289
289
  double(
290
290
  :operation,
@@ -304,7 +304,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
304
304
  right_key: :baz,
305
305
  right_index: 1,
306
306
  children:
307
- SuperDiff::OperationTrees::DefaultObject.new(
307
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
308
308
  [
309
309
  double(
310
310
  :operation,
@@ -435,7 +435,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
435
435
  .tap { |collection| collection << right_collection }
436
436
 
437
437
  operation_tree =
438
- SuperDiff::OperationTrees::DefaultObject.new(
438
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
439
439
  [
440
440
  double(
441
441
  :operation,
@@ -536,7 +536,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
536
536
  Array.new(1) { :some_value }.tap { |coll| coll << right_subcollection }
537
537
 
538
538
  operation_tree =
539
- SuperDiff::OperationTrees::DefaultObject.new(
539
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
540
540
  [
541
541
  double(
542
542
  :operation,
@@ -556,7 +556,7 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::DefaultObject do
556
556
  right_key: :baz,
557
557
  right_index: 1,
558
558
  children:
559
- SuperDiff::OperationTrees::DefaultObject.new(
559
+ SuperDiff::Basic::OperationTrees::DefaultObject.new(
560
560
  [
561
561
  double(
562
562
  :operation,