super_diff 0.9.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  19. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
  20. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  21. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  22. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  23. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  24. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  25. data/lib/super_diff/active_support.rb +6 -10
  26. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  27. data/lib/super_diff/configuration.rb +14 -8
  28. data/lib/super_diff/csi/color.rb +4 -4
  29. data/lib/super_diff/csi/colorized_document.rb +12 -16
  30. data/lib/super_diff/csi/document.rb +8 -19
  31. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  32. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  33. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  34. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  35. data/lib/super_diff/csi.rb +10 -14
  36. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  37. data/lib/super_diff/differs/date_like.rb +15 -0
  38. data/lib/super_diff/differs/default_object.rb +1 -1
  39. data/lib/super_diff/differs/defaults.rb +2 -1
  40. data/lib/super_diff/differs/main.rb +2 -13
  41. data/lib/super_diff/differs.rb +1 -0
  42. data/lib/super_diff/equality_matchers/array.rb +10 -12
  43. data/lib/super_diff/equality_matchers/base.rb +1 -1
  44. data/lib/super_diff/equality_matchers/default.rb +2 -4
  45. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  46. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  47. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  48. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  49. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  50. data/lib/super_diff/equality_matchers.rb +1 -1
  51. data/lib/super_diff/errors.rb +2 -6
  52. data/lib/super_diff/gem_version.rb +3 -3
  53. data/lib/super_diff/helpers.rb +10 -10
  54. data/lib/super_diff/implementation_checks.rb +2 -2
  55. data/lib/super_diff/line.rb +3 -3
  56. data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  60. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
  61. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
  62. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
  63. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  64. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
  65. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
  66. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
  67. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  68. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  69. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  70. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  72. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  74. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  75. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  76. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  77. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  78. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  79. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  80. data/lib/super_diff/object_inspection.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  82. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  83. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  84. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  85. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  86. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  87. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  88. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  89. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  90. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  91. data/lib/super_diff/operation_tree_builders.rb +2 -1
  92. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  93. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  94. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  95. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  96. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  97. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  98. data/lib/super_diff/operation_trees/base.rb +3 -5
  99. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  100. data/lib/super_diff/operations/binary_operation.rb +2 -2
  101. data/lib/super_diff/operations/unary_operation.rb +1 -1
  102. data/lib/super_diff/rails.rb +2 -1
  103. data/lib/super_diff/recursion_guard.rb +5 -4
  104. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  105. data/lib/super_diff/rspec/differ.rb +6 -13
  106. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  107. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  108. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  109. data/lib/super_diff/rspec/differs.rb +3 -3
  110. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  111. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  112. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  113. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
  114. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  115. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  116. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  117. data/lib/super_diff/rspec/monkey_patches.rb +180 -123
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
  120. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
  121. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  122. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
  123. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
  124. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
  125. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  126. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  127. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
  128. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  129. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  130. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  131. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  132. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  133. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  134. data/lib/super_diff/rspec.rb +17 -18
  135. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  136. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  137. data/lib/super_diff/version.rb +1 -1
  138. data/lib/super_diff.rb +13 -9
  139. data/spec/examples.txt +541 -483
  140. data/spec/integration/rails/active_record_spec.rb +3 -1
  141. data/spec/integration/rails/engines_spec.rb +25 -0
  142. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  143. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  144. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  145. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  146. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  147. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  148. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
  149. data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
  150. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
  152. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  153. data/spec/integration/rspec/include_matcher_spec.rb +327 -225
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
  156. data/spec/integration/rspec/match_matcher_spec.rb +916 -903
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
  158. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  159. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  160. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  161. data/spec/internal/log/test.log +0 -0
  162. data/spec/spec_helper.rb +20 -20
  163. data/spec/support/command_runner.rb +34 -57
  164. data/spec/support/integration/helpers.rb +44 -32
  165. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  166. data/spec/support/integration/matchers.rb +34 -0
  167. data/spec/support/integration/test_programs/base.rb +17 -22
  168. data/spec/support/integration/test_programs/plain.rb +6 -0
  169. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  170. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  171. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  172. data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
  173. data/spec/support/models/active_record/person.rb +6 -4
  174. data/spec/support/models/active_record/shipping_address.rb +9 -10
  175. data/spec/support/models/customer.rb +2 -4
  176. data/spec/support/models/player.rb +3 -6
  177. data/spec/support/models/shipping_address.rb +4 -13
  178. data/spec/support/shared_examples/active_record.rb +258 -240
  179. data/spec/support/shared_examples/active_support.rb +174 -51
  180. data/spec/support/shared_examples/elided_diffs.rb +447 -423
  181. data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
  182. data/spec/support/shared_examples/key.rb +123 -0
  183. data/spec/support/unit/helpers.rb +1 -3
  184. data/spec/support/unit/matchers/match_output.rb +12 -13
  185. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  186. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  187. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  188. data/spec/unit/helpers_spec.rb +14 -21
  189. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  190. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  191. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  192. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  193. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  194. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  195. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  196. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  197. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  198. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  199. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  200. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  201. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  202. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  203. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  204. data/spec/unit/rspec/object_inspection_spec.rb +351 -326
  205. data/spec/unit/super_diff_spec.rb +1594 -1437
  206. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  207. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  208. data/super_diff.gemspec +13 -12
  209. metadata +88 -75
  210. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  211. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
  212. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -8,7 +8,7 @@ module SuperDiff
8
8
  extend AttrExtras.mixin
9
9
  include ImplementationChecks
10
10
 
11
- method_object [:expected!, :actual!]
11
+ method_object %i[expected! actual!]
12
12
 
13
13
  def call
14
14
  operation_tree
@@ -33,16 +33,20 @@ module SuperDiff
33
33
 
34
34
  unary_operations.each_with_index do |operation, index|
35
35
  if (
36
- operation.name == :insert &&
37
- (delete_operation = unmatched_delete_operations.find { |op| op.key == operation.key }) &&
38
- (insert_operation = operation)
39
- )
36
+ operation.name == :insert &&
37
+ (
38
+ delete_operation =
39
+ unmatched_delete_operations.find do |op|
40
+ op.key == operation.key
41
+ end
42
+ ) && (insert_operation = operation)
43
+ )
40
44
  unmatched_delete_operations.delete(delete_operation)
41
45
 
42
- if (children = possible_comparison_of(
43
- delete_operation,
44
- insert_operation,
45
- ))
46
+ if (
47
+ children =
48
+ possible_comparison_of(delete_operation, insert_operation)
49
+ )
46
50
  operation_tree.delete(delete_operation)
47
51
  operation_tree << Operations::BinaryOperation.new(
48
52
  name: :change,
@@ -54,7 +58,7 @@ module SuperDiff
54
58
  right_value: insert_operation.collection[operation.key],
55
59
  left_index: delete_operation.index,
56
60
  right_index: insert_operation.index,
57
- children: children,
61
+ children: children
58
62
  )
59
63
  else
60
64
  operation_tree << insert_operation
@@ -80,17 +84,15 @@ module SuperDiff
80
84
  end
81
85
 
82
86
  def should_compare?(operation, next_operation)
83
- next_operation &&
84
- operation.name == :delete &&
85
- next_operation.name == :insert &&
86
- next_operation.key == operation.key
87
+ next_operation && operation.name == :delete &&
88
+ next_operation.name == :insert && next_operation.key == operation.key
87
89
  end
88
90
 
89
91
  def compare(expected, actual)
90
92
  OperationTreeBuilders::Main.call(
91
93
  expected: expected,
92
94
  actual: actual,
93
- all_or_nothing: false,
95
+ all_or_nothing: false
94
96
  )
95
97
  end
96
98
  end
@@ -25,13 +25,15 @@ module SuperDiff
25
25
  attr_reader :expected_attributes, :actual_attributes
26
26
 
27
27
  def establish_expected_and_actual_attributes
28
- @expected_attributes = attribute_names.reduce({}) do |hash, name|
29
- hash.merge(name => expected.public_send(name))
30
- end
28
+ @expected_attributes =
29
+ attribute_names.reduce({}) do |hash, name|
30
+ hash.merge(name => expected.public_send(name))
31
+ end
31
32
 
32
- @actual_attributes = attribute_names.reduce({}) do |hash, name|
33
- hash.merge(name => actual.public_send(name))
34
- end
33
+ @actual_attributes =
34
+ attribute_names.reduce({}) do |hash, name|
35
+ hash.merge(name => actual.public_send(name))
36
+ end
35
37
  end
36
38
  end
37
39
  end
@@ -0,0 +1,15 @@
1
+ module SuperDiff
2
+ module OperationTreeBuilders
3
+ class DateLike < CustomObject
4
+ def self.applies_to?(expected, actual)
5
+ SuperDiff.date_like?(expected) && SuperDiff.date_like?(actual)
6
+ end
7
+
8
+ protected
9
+
10
+ def attribute_names
11
+ %w[year month day]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -33,8 +33,9 @@ module SuperDiff
33
33
  end
34
34
 
35
35
  def attribute_names
36
- (expected.instance_variables.sort & actual.instance_variables.sort).
37
- map { |variable_name| variable_name[1..-1] }
36
+ (
37
+ expected.instance_variables.sort & actual.instance_variables.sort
38
+ ).map { |variable_name| variable_name[1..-1] }
38
39
  end
39
40
 
40
41
  private
@@ -42,13 +43,15 @@ module SuperDiff
42
43
  attr_reader :expected_attributes, :actual_attributes
43
44
 
44
45
  def establish_expected_and_actual_attributes
45
- @expected_attributes = attribute_names.reduce({}) do |hash, name|
46
- hash.merge(name => expected.instance_variable_get("@#{name}"))
47
- end
48
-
49
- @actual_attributes = attribute_names.reduce({}) do |hash, name|
50
- hash.merge(name => actual.instance_variable_get("@#{name}"))
51
- end
46
+ @expected_attributes =
47
+ attribute_names.reduce({}) do |hash, name|
48
+ hash.merge(name => expected.instance_variable_get("@#{name}"))
49
+ end
50
+
51
+ @actual_attributes =
52
+ attribute_names.reduce({}) do |hash, name|
53
+ hash.merge(name => actual.instance_variable_get("@#{name}"))
54
+ end
52
55
  end
53
56
 
54
57
  def possibly_add_noop_operation_to(operations, attribute_name)
@@ -58,7 +61,7 @@ module SuperDiff
58
61
  collection: actual_attributes,
59
62
  key: attribute_name,
60
63
  index: attribute_names.index(attribute_name),
61
- value: actual_attributes[attribute_name],
64
+ value: actual_attributes[attribute_name]
62
65
  )
63
66
  end
64
67
  end
@@ -66,7 +69,8 @@ module SuperDiff
66
69
  def should_add_noop_operation?(attribute_name)
67
70
  expected_attributes.include?(attribute_name) &&
68
71
  actual_attributes.include?(attribute_name) &&
69
- expected_attributes[attribute_name] == actual_attributes[attribute_name]
72
+ expected_attributes[attribute_name] ==
73
+ actual_attributes[attribute_name]
70
74
  end
71
75
 
72
76
  def possibly_add_delete_operation_to(operations, attribute_name)
@@ -76,16 +80,18 @@ module SuperDiff
76
80
  collection: expected_attributes,
77
81
  key: attribute_name,
78
82
  index: attribute_names.index(attribute_name),
79
- value: expected_attributes[attribute_name],
83
+ value: expected_attributes[attribute_name]
80
84
  )
81
85
  end
82
86
  end
83
87
 
84
88
  def should_add_delete_operation?(attribute_name)
85
- expected_attributes.include?(attribute_name) && (
86
- !actual_attributes.include?(attribute_name) ||
87
- expected_attributes[attribute_name] != actual_attributes[attribute_name]
88
- )
89
+ expected_attributes.include?(attribute_name) &&
90
+ (
91
+ !actual_attributes.include?(attribute_name) ||
92
+ expected_attributes[attribute_name] !=
93
+ actual_attributes[attribute_name]
94
+ )
89
95
  end
90
96
 
91
97
  def possibly_add_insert_operation_to(operations, attribute_name)
@@ -95,16 +101,18 @@ module SuperDiff
95
101
  collection: actual_attributes,
96
102
  key: attribute_name,
97
103
  index: attribute_names.index(attribute_name),
98
- value: actual_attributes[attribute_name],
104
+ value: actual_attributes[attribute_name]
99
105
  )
100
106
  end
101
107
  end
102
108
 
103
109
  def should_add_insert_operation?(attribute_name)
104
- !expected_attributes.include?(attribute_name) || (
105
- actual_attributes.include?(attribute_name) &&
106
- expected_attributes[attribute_name] != actual_attributes[attribute_name]
107
- )
110
+ !expected_attributes.include?(attribute_name) ||
111
+ (
112
+ actual_attributes.include?(attribute_name) &&
113
+ expected_attributes[attribute_name] !=
114
+ actual_attributes[attribute_name]
115
+ )
108
116
  end
109
117
  end
110
118
  end
@@ -1,5 +1,5 @@
1
1
  module SuperDiff
2
2
  module OperationTreeBuilders
3
- DEFAULTS = [Array, Hash, TimeLike, CustomObject].freeze
3
+ DEFAULTS = [Array, Hash, TimeLike, DateLike, CustomObject].freeze
4
4
  end
5
5
  end
@@ -53,18 +53,18 @@ module SuperDiff
53
53
  ev2, av2 = expected[ek], actual[ek]
54
54
 
55
55
  if (
56
- (!actual.include?(ek) || ev2 != av2) &&
57
- operations.none? { |operation|
58
- [:delete, :noop].include?(operation.name) &&
59
- operation.key == ek
60
- }
61
- )
56
+ (!actual.include?(ek) || ev2 != av2) &&
57
+ operations.none? do |operation|
58
+ %i[delete noop].include?(operation.name) &&
59
+ operation.key == ek
60
+ end
61
+ )
62
62
  operations << Operations::UnaryOperation.new(
63
63
  name: :delete,
64
64
  collection: expected,
65
65
  key: ek,
66
66
  value: ev2,
67
- index: ei2,
67
+ index: ei2
68
68
  )
69
69
  end
70
70
  end
@@ -75,16 +75,16 @@ module SuperDiff
75
75
  collection: actual,
76
76
  key: ak,
77
77
  value: av,
78
- index: ai,
78
+ index: ai
79
79
  )
80
80
  else
81
81
  # (If we're here, it probably means that the key in 'actual' isn't
82
82
  # present in 'expected' or the values don't match.)
83
83
 
84
84
  if (
85
- (operations.empty? || operations.last.name == :noop) &&
86
- (ai == 0 || eks.include?(aks[ai - 1]))
87
- )
85
+ (operations.empty? || operations.last.name == :noop) &&
86
+ (ai == 0 || eks.include?(aks[ai - 1]))
87
+ )
88
88
  # If we go from a match in the last iteration to a missing or
89
89
  # extra key in this one, or we're at the first key in 'actual' and
90
90
  # it's missing or extra, look for deletes in the 'expected' hash
@@ -113,10 +113,10 @@ module SuperDiff
113
113
  # handled in some future iteration of the 'actual' loop.
114
114
  break
115
115
  elsif (
116
- aks[ai + 1 .. -1].any? { |k|
117
- expected.include?(k) && expected[k] != actual[k]
118
- }
119
- )
116
+ aks[ai + 1..-1].any? do |k|
117
+ expected.include?(k) && expected[k] != actual[k]
118
+ end
119
+ )
120
120
  # While we backtracked a bit to iterate over 'expected', we
121
121
  # now have to look ahead. If we will end up encountering a
122
122
  # insert that matches this delete later, stop and go back to
@@ -130,7 +130,7 @@ module SuperDiff
130
130
  collection: expected,
131
131
  key: ek,
132
132
  value: ev,
133
- index: ei2,
133
+ index: ei2
134
134
  )
135
135
  end
136
136
 
@@ -144,17 +144,16 @@ module SuperDiff
144
144
  collection: actual,
145
145
  key: ak,
146
146
  value: av,
147
- index: ai,
147
+ index: ai
148
148
  )
149
149
  end
150
150
  end
151
151
  end
152
152
 
153
153
  if (
154
- expected.include?(ak) &&
155
- ev != av &&
156
- operations.none? { |op| op.name == :delete && op.key == ak }
157
- )
154
+ expected.include?(ak) && ev != av &&
155
+ operations.none? { |op| op.name == :delete && op.key == ak }
156
+ )
158
157
  # If we're here, it means that we didn't encounter any delete
159
158
  # operations above for whatever reason and so we need to add a
160
159
  # delete to represent the fact that the value for this key has
@@ -164,7 +163,7 @@ module SuperDiff
164
163
  collection: expected,
165
164
  key: ak,
166
165
  value: expected[ak],
167
- index: ei,
166
+ index: ei
168
167
  )
169
168
  end
170
169
 
@@ -178,7 +177,7 @@ module SuperDiff
178
177
  collection: actual,
179
178
  key: ak,
180
179
  value: av,
181
- index: ai,
180
+ index: ai
182
181
  )
183
182
  end
184
183
  end
@@ -200,7 +199,7 @@ module SuperDiff
200
199
  collection: expected,
201
200
  key: ek,
202
201
  value: ev,
203
- index: ei,
202
+ index: ei
204
203
  )
205
204
  end
206
205
 
@@ -3,14 +3,11 @@ module SuperDiff
3
3
  class Main
4
4
  extend AttrExtras.mixin
5
5
 
6
- method_object [:expected!, :actual!, :all_or_nothing!]
6
+ method_object %i[expected! actual! all_or_nothing!]
7
7
 
8
8
  def call
9
9
  if resolved_class
10
- resolved_class.call(
11
- expected: expected,
12
- actual: actual,
13
- )
10
+ resolved_class.call(expected: expected, actual: actual)
14
11
  elsif all_or_nothing?
15
12
  raise NoOperationTreeBuilderAvailableError.create(expected, actual)
16
13
  else
@@ -29,13 +26,9 @@ module SuperDiff
29
26
  def available_classes
30
27
  classes =
31
28
  SuperDiff.configuration.extra_operation_tree_builder_classes +
32
- DEFAULTS
29
+ DEFAULTS
33
30
 
34
- if all_or_nothing?
35
- classes + [DefaultObject]
36
- else
37
- classes
38
- end
31
+ all_or_nothing? ? classes + [DefaultObject] : classes
39
32
  end
40
33
  end
41
34
  end
@@ -53,7 +53,7 @@ module SuperDiff
53
53
  collection: expected,
54
54
  key: index,
55
55
  index: index,
56
- value: expected[index],
56
+ value: expected[index]
57
57
  )
58
58
  end
59
59
  end
@@ -65,7 +65,7 @@ module SuperDiff
65
65
  collection: actual,
66
66
  key: index,
67
67
  index: index,
68
- value: actual[index],
68
+ value: actual[index]
69
69
  )
70
70
  end
71
71
  end
@@ -77,7 +77,7 @@ module SuperDiff
77
77
  collection: actual,
78
78
  key: index,
79
79
  index: index,
80
- value: actual[index],
80
+ value: actual[index]
81
81
  )
82
82
  end
83
83
  end
@@ -8,17 +8,7 @@ module SuperDiff
8
8
  protected
9
9
 
10
10
  def attribute_names
11
- base = [
12
- "year",
13
- "month",
14
- "day",
15
- "hour",
16
- "min",
17
- "sec",
18
- "subsec",
19
- "zone",
20
- "utc_offset",
21
- ]
11
+ base = %w[year month day hour min sec subsec zone utc_offset]
22
12
 
23
13
  # If timezones are different, also show a normalized timestamp at the
24
14
  # end of the diff to help visualize why they are different moments in
@@ -9,9 +9,10 @@ module SuperDiff
9
9
  # TODO: Where is this used?
10
10
  autoload(
11
11
  :MultilineString,
12
- "super_diff/operation_tree_builders/multiline_string",
12
+ "super_diff/operation_tree_builders/multiline_string"
13
13
  )
14
14
  autoload :TimeLike, "super_diff/operation_tree_builders/time_like"
15
+ autoload :DateLike, "super_diff/operation_tree_builders/date_like"
15
16
  end
16
17
  end
17
18
 
@@ -29,11 +29,7 @@ module SuperDiff
29
29
  end
30
30
 
31
31
  def middle_lines
32
- if tiered_lines.empty?
33
- []
34
- else
35
- tiered_lines[1..-2]
36
- end
32
+ tiered_lines.empty? ? [] : tiered_lines[1..-2]
37
33
  end
38
34
 
39
35
  def ending_lines
@@ -9,21 +9,21 @@ module SuperDiff
9
9
  type: :noop,
10
10
  indentation_level: indentation_level,
11
11
  value: open_token,
12
- collection_bookend: :open,
12
+ collection_bookend: :open
13
13
  ),
14
14
  *inner_lines,
15
15
  Line.new(
16
16
  type: :noop,
17
17
  indentation_level: indentation_level,
18
18
  value: close_token,
19
- collection_bookend: :close,
20
- ),
19
+ collection_bookend: :close
20
+ )
21
21
  ]
22
22
  end
23
23
 
24
24
  def inner_lines
25
- @_inner_lines ||= operation_tree.
26
- flat_map do |operation|
25
+ @_inner_lines ||=
26
+ operation_tree.flat_map do |operation|
27
27
  lines =
28
28
  if operation.name == :change
29
29
  build_lines_for_change_operation(operation)
@@ -33,7 +33,7 @@ module SuperDiff
33
33
 
34
34
  maybe_add_prefix_at_beginning_of_lines(
35
35
  maybe_add_comma_at_end_of_lines(lines, operation),
36
- operation,
36
+ operation
37
37
  )
38
38
  end
39
39
  end
@@ -51,8 +51,7 @@ module SuperDiff
51
51
  end
52
52
 
53
53
  def add_prefix_at_beginning_of_lines(lines, operation)
54
- [lines[0].prefixed_with(item_prefix_for(operation))] +
55
- lines[1..-1]
54
+ [lines[0].prefixed_with(item_prefix_for(operation))] + lines[1..-1]
56
55
  end
57
56
 
58
57
  def maybe_add_comma_at_end_of_lines(lines, operation)
@@ -79,14 +78,12 @@ module SuperDiff
79
78
  def build_lines_for_change_operation(operation)
80
79
  SuperDiff::RecursionGuard.guarding_recursion_of(
81
80
  operation.left_collection,
82
- operation.right_collection,
81
+ operation.right_collection
83
82
  ) do |already_seen|
84
83
  if already_seen
85
84
  raise InfiniteRecursionError
86
85
  else
87
- operation.children.flatten(
88
- indentation_level: indentation_level + 1,
89
- )
86
+ operation.children.flatten(indentation_level: indentation_level + 1)
90
87
  end
91
88
  end
92
89
  end
@@ -99,14 +96,14 @@ module SuperDiff
99
96
  Line.new(
100
97
  type: operation.name,
101
98
  indentation_level: indentation_level,
102
- value: SuperDiff::RecursionGuard::PLACEHOLDER,
103
- ),
99
+ value: SuperDiff::RecursionGuard::PLACEHOLDER
100
+ )
104
101
  ]
105
102
  else
106
103
  build_lines_from_inspection_of(
107
104
  operation.value,
108
105
  type: operation.name,
109
- indentation_level: indentation_level,
106
+ indentation_level: indentation_level
110
107
  )
111
108
  end
112
109
  end
@@ -125,7 +122,7 @@ module SuperDiff
125
122
  value,
126
123
  as_lines: true,
127
124
  type: type,
128
- indentation_level: indentation_level,
125
+ indentation_level: indentation_level
129
126
  )
130
127
  end
131
128
 
@@ -7,8 +7,7 @@ module SuperDiff
7
7
  "#<#{operation_tree.underlying_object.class.name}:" +
8
8
  SuperDiff::Helpers.object_address_for(
9
9
  operation_tree.underlying_object
10
- ) +
11
- " {"
10
+ ) + " {"
12
11
  end
13
12
 
14
13
  def close_token
@@ -14,11 +14,7 @@ module SuperDiff
14
14
  def item_prefix_for(operation)
15
15
  key = key_for(operation)
16
16
 
17
- if format_keys_as_kwargs?
18
- "#{key}: "
19
- else
20
- "#{key.inspect} => "
21
- end
17
+ format_keys_as_kwargs? ? "#{key}: " : "#{key.inspect} => "
22
18
  end
23
19
 
24
20
  private
@@ -30,11 +26,7 @@ module SuperDiff
30
26
  def key_for(operation)
31
27
  # Note: We could have used the right_key here too, they're both the
32
28
  # same keys
33
- if operation.respond_to?(:left_key)
34
- operation.left_key
35
- else
36
- operation.key
37
- end
29
+ operation.respond_to?(:left_key) ? operation.left_key : operation.key
38
30
  end
39
31
  end
40
32
  end
@@ -8,7 +8,8 @@ module SuperDiff
8
8
  indentation_level: indentation_level,
9
9
  # TODO: Test that quotes and things don't get escaped but escape
10
10
  # characters do
11
- value: operation.value.inspect[1..-2].gsub(/\\"/, '"').gsub(/\\'/, "'")
11
+ value:
12
+ operation.value.inspect[1..-2].gsub(/\\"/, '"').gsub(/\\'/, "'")
12
13
  )
13
14
  end
14
15
  end
@@ -5,16 +5,16 @@ module SuperDiff
5
5
  autoload :Collection, "super_diff/operation_tree_flatteners/collection"
6
6
  autoload(
7
7
  :CustomObject,
8
- "super_diff/operation_tree_flatteners/custom_object",
8
+ "super_diff/operation_tree_flatteners/custom_object"
9
9
  )
10
10
  autoload(
11
11
  :DefaultObject,
12
- "super_diff/operation_tree_flatteners/default_object",
12
+ "super_diff/operation_tree_flatteners/default_object"
13
13
  )
14
14
  autoload :Hash, "super_diff/operation_tree_flatteners/hash"
15
15
  autoload(
16
16
  :MultilineString,
17
- "super_diff/operation_tree_flatteners/multiline_string",
17
+ "super_diff/operation_tree_flatteners/multiline_string"
18
18
  )
19
19
  end
20
20
  end
@@ -20,23 +20,21 @@ module SuperDiff
20
20
 
21
21
  def to_diff(indentation_level:)
22
22
  TieredLinesFormatter.call(
23
- perhaps_elide(flatten(indentation_level: indentation_level)),
23
+ perhaps_elide(flatten(indentation_level: indentation_level))
24
24
  )
25
25
  end
26
26
 
27
27
  def flatten(indentation_level:)
28
28
  operation_tree_flattener_class.call(
29
29
  self,
30
- indentation_level: indentation_level,
30
+ indentation_level: indentation_level
31
31
  )
32
32
  end
33
33
 
34
34
  def pretty_print(pp)
35
35
  pp.group(1, "#<#{self.class.name} [", "]>") do
36
36
  pp.breakable
37
- pp.seplist(self) do |value|
38
- pp.pp value
39
- end
37
+ pp.seplist(self) { |value| pp.pp value }
40
38
  end
41
39
  end
42
40
 
@@ -19,9 +19,7 @@ module SuperDiff
19
19
  pp.text ":operations=>"
20
20
  pp.group(1, "[", "]") do
21
21
  pp.breakable
22
- pp.seplist(self) do |value|
23
- pp.pp value
24
- end
22
+ pp.seplist(self) { |value| pp.pp value }
25
23
  end
26
24
  pp.comma_breakable
27
25
  pp.text ":underlying_object=>"
@@ -14,8 +14,8 @@ module SuperDiff
14
14
  :right_value!,
15
15
  :left_index!,
16
16
  :right_index!,
17
- children: [],
18
- ],
17
+ children: []
18
+ ]
19
19
  )
20
20
  end
21
21
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  class UnaryOperation
4
4
  extend AttrExtras.mixin
5
5
 
6
- rattr_initialize [:name!, :collection!, :key!, :value!, :index!]
6
+ rattr_initialize %i[name! collection! key! value! index!]
7
7
  end
8
8
  end
9
9
  end
@@ -1 +1,2 @@
1
- require "super_diff/active_record"
1
+ require "super_diff/active_support"
2
+ require "super_diff/active_record" if defined?(ActiveRecord)