super_diff 0.9.0 → 0.11.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 (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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3338e91a7e03a6c0447a56b0c612653bd8f56f27a95ebeba081546dea8fdc7da
4
- data.tar.gz: c840b79a7dd98e31cce823df4bdb67b704dec07ae340c889c86d38bae735ea41
3
+ metadata.gz: '08f4b984e0530c5c4ca5e1ba34b98b380a76712009a1b552a5e21106975293aa'
4
+ data.tar.gz: 12b49818665c952553c0b052e3fe8166de0c45a5eac7f9862c317560e0a06763
5
5
  SHA512:
6
- metadata.gz: 78535779a6e462100afb0ec019ea0b1241e5f6710c40005150d3d8784d34227dc0b549de20fe3dbbc453b6563903df78fc21925701f8d5c7f0d3d466c8345641
7
- data.tar.gz: 5a049b0606ae5ff5ac18978e8591ede3edcdcecf6e48eb58ced6655527b481bf2f4a17623c981b902c5ea86295e3dc9bd633905502113edbc162724edd475389
6
+ metadata.gz: c6df90629d86a0c50680b10803cd1839ba0c94828627775fa840e1726fc70b57c6b13be7614ff35c00af960f3ea05530af6ba2d7dc7a3b9f9670fa8d17f75c72
7
+ data.tar.gz: 56015f9b40eb6f8b03be2c7b02dc641ea7493db0d7d4a8dae929753f7bf94d9a925f0678b8f68c1c2bf7eb705e2c019b3b38f7bfafb805379d8b37b9016f453d
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [version-badge]: http://img.shields.io/gem/v/super_diff.svg
4
4
  [rubygems]: http://rubygems.org/gems/super_diff
5
- [gh-actions-badge]: http://img.shields.io/github/workflow/status/mcmire/super_diff/SuperDiff/master
5
+ [gh-actions-badge]: https://img.shields.io/github/actions/workflow/status/mcmire/super_diff/super_diff.yml?branch=master
6
6
  [downloads-badge]: http://img.shields.io/gem/dtv/super_diff.svg
7
7
  [hound]: https://houndci.com
8
8
  [issuehunt-badge]: https://img.shields.io/badge/sponsored_through-IssueHunt-2EC28C
@@ -36,7 +36,7 @@ the output it produces leaves much to be desired.
36
36
  For instance,
37
37
  let's say you wanted to compare these two hashes:
38
38
 
39
- ``` ruby
39
+ ```ruby
40
40
  actual = {
41
41
  customer: {
42
42
  person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
@@ -48,11 +48,7 @@ actual = {
48
48
  }
49
49
  },
50
50
  items: [
51
- {
52
- name: "Fender Stratocaster",
53
- cost: 100_000,
54
- options: ["red", "blue", "green"]
55
- },
51
+ { name: "Fender Stratocaster", cost: 100_000, options: %w[red blue green] },
56
52
  { name: "Mattel Hoverboard" }
57
53
  ]
58
54
  }
@@ -68,11 +64,7 @@ expected = {
68
64
  }
69
65
  },
70
66
  items: [
71
- {
72
- name: "Fender Stratocaster",
73
- cost: 100_000,
74
- options: ["red", "blue", "green"]
75
- },
67
+ { name: "Fender Stratocaster", cost: 100_000, options: %w[red blue green] },
76
68
  { name: "Chevy 4x4" }
77
69
  ]
78
70
  }
@@ -80,7 +72,7 @@ expected = {
80
72
 
81
73
  If, somewhere in a test, you were to say:
82
74
 
83
- ``` ruby
75
+ ```ruby
84
76
  expect(actual).to eq(expected)
85
77
  ```
86
78
 
@@ -107,7 +99,7 @@ depending on your type of project.
107
99
  If you're developing a Rails app,
108
100
  add the following to your Gemfile:
109
101
 
110
- ``` ruby
102
+ ```ruby
111
103
  group :test do
112
104
  gem "super_diff"
113
105
  end
@@ -116,7 +108,7 @@ end
116
108
  After running `bundle install`,
117
109
  add the following to your `rails_helper`:
118
110
 
119
- ``` ruby
111
+ ```ruby
120
112
  require "super_diff/rspec-rails"
121
113
  ```
122
114
 
@@ -126,14 +118,14 @@ If you're developing an app using Hanami or Sinatra,
126
118
  or merely using a part of Rails such as ActiveModel,
127
119
  add the following to your Gemfile where appropriate:
128
120
 
129
- ``` ruby
121
+ ```ruby
130
122
  gem "super_diff"
131
123
  ```
132
124
 
133
125
  After running `bundle install`,
134
126
  add the following to your `spec_helper`:
135
127
 
136
- ``` ruby
128
+ ```ruby
137
129
  require "super_diff/rspec"
138
130
  require "super_diff/active_support"
139
131
  ```
@@ -143,13 +135,13 @@ require "super_diff/active_support"
143
135
  If you're developing a gem,
144
136
  add the following to your gemspec:
145
137
 
146
- ``` ruby
138
+ ```ruby
147
139
  spec.add_development_dependency "super_diff"
148
140
  ```
149
141
 
150
142
  Now add the following to your `spec_helper`:
151
143
 
152
- ``` ruby
144
+ ```ruby
153
145
  require "super_diff/rspec"
154
146
  ```
155
147
 
@@ -161,7 +153,7 @@ to your test helper file
161
153
  (`rails_helper` or `spec_helper`)
162
154
  which looks something like this:
163
155
 
164
- ``` ruby
156
+ ```ruby
165
157
  SuperDiff.configure do |config|
166
158
  # ...
167
159
  end
@@ -172,7 +164,7 @@ end
172
164
  If you don't like the colors that SuperDiff uses,
173
165
  you can change them like this:
174
166
 
175
- ``` ruby
167
+ ```ruby
176
168
  SuperDiff.configure do |config|
177
169
  config.actual_color = :green
178
170
  config.expected_color = :red
@@ -184,6 +176,53 @@ end
184
176
  See [eight_bit_color.rb](lib/super_diff/csi/eight_bit_color.rb)
185
177
  for the list of available colors.
186
178
 
179
+ You can also completely disable colorized output.
180
+
181
+ <!-- prettier-ignore-start -->
182
+ ```ruby
183
+ SuperDiff.configure do |config|
184
+ config.color_enabled = false
185
+ end
186
+ ```
187
+ <!-- prettier-ignore-end -->
188
+
189
+ ### Disabling the key
190
+
191
+ You can disable the key by changing the following config (default: true):
192
+
193
+ <!-- prettier-ignore-start -->
194
+ ```ruby
195
+ SuperDiff.configure do |config|
196
+ config.key_enabled = false
197
+ end
198
+ ```
199
+ <!-- prettier-ignore-end -->
200
+
201
+ ### Hiding unimportant lines
202
+
203
+ When looking at a large diff for which many of the lines do not change,
204
+ it can be difficult to locate the lines which do. Text-oriented
205
+ diffs such as those you get from a conventional version control system
206
+ solve this problem by removing those unchanged lines from the diff
207
+ entirely. The same can be done in SuperDiff.
208
+
209
+ ```ruby
210
+ SuperDiff.configure do |config|
211
+ config.diff_elision_enabled = false
212
+ config.diff_elision_maximum = 3
213
+ end
214
+ ```
215
+
216
+ - `diff_elision_enabled` — The elision logic is disabled by default so
217
+ as not to surprise people, so setting this to `true` will turn it on.
218
+ - `diff_elision_maximum` — This number controls what happens to
219
+ unchanged lines (i.e. lines that are neither "insert" lines nor
220
+ "delete" lines) that are in between changed lines. If a section of
221
+ unchanged lines is beyond this number, the gem will elide (a fancy
222
+ word for remove) the data structures within that section as much as
223
+ possible until the limit is reached or it cannot go further. Elided
224
+ lines are replaced with a `# ...` marker.
225
+
187
226
  ### Diffing custom objects
188
227
 
189
228
  If you are comparing two data structures
@@ -197,7 +236,7 @@ of key pieces involved in the diffing process.
197
236
  I'll have more about how that works soon,
198
237
  but here is what such a configuration would look like:
199
238
 
200
- ``` ruby
239
+ ```ruby
201
240
  SuperDiff.configure do |config|
202
241
  config.add_extra_differ_class(YourDiffer)
203
242
  config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
@@ -231,9 +270,9 @@ I'll get notified right away!
231
270
  ## Compatibility
232
271
 
233
272
  `super_diff` is [tested][gh-actions] to work with
234
- Ruby >= 2.5.x,
273
+ Ruby >= 3.x,
235
274
  RSpec 3.x,
236
- and Rails >= 5.x.
275
+ and Rails >= 6.x.
237
276
 
238
277
  [gh-actions]: https://github.com/mcmire/super_diff/actions?query=workflow%3ASuperDiff
239
278
 
@@ -242,10 +281,10 @@ and Rails >= 5.x.
242
281
  In developing this gem
243
282
  I made use of or was heavily inspired by these libraries:
244
283
 
245
- * [Diff::LCS][diff-lcs],
284
+ - [Diff::LCS][diff-lcs],
246
285
  the library I started with in the [original version of this gem][original-version]
247
286
  (made in 2011!)
248
- * The pretty-printing algorithms and API within [PrettyPrinter][pretty-printer] and [AwesomePrint][awesome-print],
287
+ - The pretty-printing algorithms and API within [PrettyPrinter][pretty-printer] and [AwesomePrint][awesome-print],
249
288
  from which I borrowed ideas to develop the [inspectors][inspection-tree].
250
289
 
251
290
  Thank you to the authors of these libraries!
@@ -3,8 +3,7 @@ module SuperDiff
3
3
  module Differs
4
4
  class ActiveRecordRelation < SuperDiff::Differs::Base
5
5
  def self.applies_to?(expected, actual)
6
- expected.is_a?(::Array) &&
7
- actual.is_a?(::ActiveRecord::Relation)
6
+ expected.is_a?(::Array) && actual.is_a?(::ActiveRecord::Relation)
8
7
  end
9
8
 
10
9
  protected
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module Differs
4
4
  autoload(
5
5
  :ActiveRecordRelation,
6
- "super_diff/active_record/differs/active_record_relation",
6
+ "super_diff/active_record/differs/active_record_relation"
7
7
  )
8
8
  end
9
9
  end
@@ -8,35 +8,39 @@ module SuperDiff
8
8
  end
9
9
 
10
10
  def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do
12
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
13
- add_text do |object|
14
- "#<#{object.class} "
15
- end
11
+ SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
+ t1.as_lines_when_rendering_to_lines(
13
+ collection_bookend: :open
14
+ ) do |t2|
15
+ t2.add_text "#<#{object.class} "
16
16
 
17
- when_rendering_to_lines do
18
- add_text "{"
17
+ # stree-ignore
18
+ t2.when_rendering_to_lines do |t3|
19
+ t3.add_text "{"
19
20
  end
20
21
  end
21
22
 
22
- nested do |object|
23
- insert_separated_list(
24
- ["id"] + (object.attributes.keys.sort - ["id"]),
25
- ) do |name|
26
- as_prefix_when_rendering_to_lines do
27
- add_text "#{name}: "
23
+ t1.nested do |t2|
24
+ t2.insert_separated_list(
25
+ ["id"] + (object.attributes.keys.sort - ["id"])
26
+ ) do |t3, name|
27
+ t3.as_prefix_when_rendering_to_lines do |t4|
28
+ t4.add_text "#{name}: "
28
29
  end
29
30
 
30
- add_inspection_of object.read_attribute(name)
31
+ t3.add_inspection_of object.read_attribute(name)
31
32
  end
32
33
  end
33
34
 
34
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
35
- when_rendering_to_lines do
36
- add_text "}"
35
+ t1.as_lines_when_rendering_to_lines(
36
+ collection_bookend: :close
37
+ ) do |t2|
38
+ # stree-ignore
39
+ t2.when_rendering_to_lines do |t3|
40
+ t3.add_text "}"
37
41
  end
38
42
 
39
- add_text ">"
43
+ t2.add_text ">"
40
44
  end
41
45
  end
42
46
  end
@@ -8,17 +8,24 @@ module SuperDiff
8
8
  end
9
9
 
10
10
  def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do
12
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
13
- add_text "#<ActiveRecord::Relation ["
11
+ SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
+ # stree-ignore
13
+ t1.as_lines_when_rendering_to_lines(
14
+ collection_bookend: :open
15
+ ) do |t2|
16
+ t2.add_text "#<ActiveRecord::Relation ["
14
17
  end
15
18
 
16
- nested do |array|
17
- insert_array_inspection_of(array)
19
+ # stree-ignore
20
+ t1.nested do |t2|
21
+ t2.insert_array_inspection_of(object)
18
22
  end
19
23
 
20
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
21
- add_text "]>"
24
+ # stree-ignore
25
+ t1.as_lines_when_rendering_to_lines(
26
+ collection_bookend: :close
27
+ ) do |t2|
28
+ t2.add_text "]>"
22
29
  end
23
30
  end
24
31
  end
@@ -4,11 +4,11 @@ module SuperDiff
4
4
  module InspectionTreeBuilders
5
5
  autoload(
6
6
  :ActiveRecordModel,
7
- "super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model",
7
+ "super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model"
8
8
  )
9
9
  autoload(
10
10
  :ActiveRecordRelation,
11
- "super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation",
11
+ "super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation"
12
12
  )
13
13
  end
14
14
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module ObjectInspection
4
4
  autoload(
5
5
  :InspectionTreeBuilders,
6
- "super_diff/active_record/object_inspection/inspection_tree_builders",
6
+ "super_diff/active_record/object_inspection/inspection_tree_builders"
7
7
  )
8
8
  end
9
9
  end
@@ -4,8 +4,7 @@ module SuperDiff
4
4
  class ActiveRecordModel < SuperDiff::OperationTreeBuilders::CustomObject
5
5
  def self.applies_to?(expected, actual)
6
6
  expected.is_a?(::ActiveRecord::Base) &&
7
- actual.is_a?(::ActiveRecord::Base) &&
8
- expected.class == actual.class
7
+ actual.is_a?(::ActiveRecord::Base) && expected.class == actual.class
9
8
  end
10
9
 
11
10
  protected
@@ -3,8 +3,7 @@ module SuperDiff
3
3
  module OperationTreeBuilders
4
4
  class ActiveRecordRelation < SuperDiff::OperationTreeBuilders::Array
5
5
  def self.applies_to?(expected, actual)
6
- expected.is_a?(::Array) &&
7
- actual.is_a?(::ActiveRecord::Relation)
6
+ expected.is_a?(::Array) && actual.is_a?(::ActiveRecord::Relation)
8
7
  end
9
8
 
10
9
  def initialize(actual:, **rest)
@@ -3,11 +3,11 @@ module SuperDiff
3
3
  module OperationTreeBuilders
4
4
  autoload(
5
5
  :ActiveRecordModel,
6
- "super_diff/active_record/operation_tree_builders/active_record_model",
6
+ "super_diff/active_record/operation_tree_builders/active_record_model"
7
7
  )
8
8
  autoload(
9
9
  :ActiveRecordRelation,
10
- "super_diff/active_record/operation_tree_builders/active_record_relation",
10
+ "super_diff/active_record/operation_tree_builders/active_record_relation"
11
11
  )
12
12
  end
13
13
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module OperationTreeFlatteners
4
4
  autoload(
5
5
  :ActiveRecordRelation,
6
- "super_diff/active_record/operation_tree_flatteners/active_record_relation",
6
+ "super_diff/active_record/operation_tree_flatteners/active_record_relation"
7
7
  )
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module OperationTrees
4
4
  autoload(
5
5
  :ActiveRecordRelation,
6
- "super_diff/active_record/operation_trees/active_record_relation",
6
+ "super_diff/active_record/operation_trees/active_record_relation"
7
7
  )
8
8
  end
9
9
  end
@@ -3,34 +3,26 @@ require "super_diff/active_support"
3
3
  module SuperDiff
4
4
  module ActiveRecord
5
5
  autoload :Differs, "super_diff/active_record/differs"
6
- autoload(
7
- :ObjectInspection,
8
- "super_diff/active_record/object_inspection",
9
- )
10
- autoload(
11
- :OperationTrees,
12
- "super_diff/active_record/operation_trees",
13
- )
6
+ autoload(:ObjectInspection, "super_diff/active_record/object_inspection")
7
+ autoload(:OperationTrees, "super_diff/active_record/operation_trees")
14
8
  autoload(
15
9
  :OperationTreeBuilders,
16
- "super_diff/active_record/operation_tree_builders",
10
+ "super_diff/active_record/operation_tree_builders"
17
11
  )
18
12
  autoload(
19
13
  :OperationTreeFlatteners,
20
- "super_diff/active_record/operation_tree_flatteners",
14
+ "super_diff/active_record/operation_tree_flatteners"
21
15
  )
22
16
 
23
17
  SuperDiff.configure do |config|
24
- config.add_extra_differ_classes(
25
- Differs::ActiveRecordRelation,
26
- )
18
+ config.add_extra_differ_classes(Differs::ActiveRecordRelation)
27
19
  config.add_extra_operation_tree_builder_classes(
28
20
  OperationTreeBuilders::ActiveRecordModel,
29
- OperationTreeBuilders::ActiveRecordRelation,
21
+ OperationTreeBuilders::ActiveRecordRelation
30
22
  )
31
23
  config.add_extra_inspection_tree_builder_classes(
32
24
  ObjectInspection::InspectionTreeBuilders::ActiveRecordModel,
33
- ObjectInspection::InspectionTreeBuilders::ActiveRecordRelation,
25
+ ObjectInspection::InspectionTreeBuilders::ActiveRecordRelation
34
26
  )
35
27
  end
36
28
  end
@@ -4,13 +4,12 @@ module SuperDiff
4
4
  class HashWithIndifferentAccess < SuperDiff::Differs::Hash
5
5
  def self.applies_to?(expected, actual)
6
6
  (
7
- expected.is_a?(::HashWithIndifferentAccess) &&
8
- actual.is_a?(::Hash)
7
+ expected.is_a?(::HashWithIndifferentAccess) && actual.is_a?(::Hash)
9
8
  ) ||
10
- (
11
- expected.is_a?(::Hash) &&
12
- actual.is_a?(::HashWithIndifferentAccess)
13
- )
9
+ (
10
+ expected.is_a?(::Hash) &&
11
+ actual.is_a?(::HashWithIndifferentAccess)
12
+ )
14
13
  end
15
14
 
16
15
  protected
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module Differs
4
4
  autoload(
5
5
  :HashWithIndifferentAccess,
6
- "super_diff/active_support/differs/hash_with_indifferent_access",
6
+ "super_diff/active_support/differs/hash_with_indifferent_access"
7
7
  )
8
8
  end
9
9
  end
@@ -8,25 +8,34 @@ module SuperDiff
8
8
  end
9
9
 
10
10
  def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do
12
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
13
- add_text "#<HashWithIndifferentAccess {"
11
+ SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
+ # stree-ignore
13
+ t1.as_lines_when_rendering_to_lines(
14
+ collection_bookend: :open
15
+ ) do |t2|
16
+ t2.add_text "#<HashWithIndifferentAccess {"
14
17
  end
15
18
 
16
- when_rendering_to_string do
17
- add_text " "
19
+ # stree-ignore
20
+ t1.when_rendering_to_string do |t2|
21
+ t2.add_text " "
18
22
  end
19
23
 
20
- nested do |hash|
21
- insert_hash_inspection_of(hash)
24
+ # stree-ignore
25
+ t1.nested do |t2|
26
+ t2.insert_hash_inspection_of(object)
22
27
  end
23
28
 
24
- when_rendering_to_string do
25
- add_text " "
29
+ # stree-ignore
30
+ t1.when_rendering_to_string do |t2|
31
+ t2.add_text " "
26
32
  end
27
33
 
28
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
29
- add_text "}>"
34
+ # stree-ignore
35
+ t1.as_lines_when_rendering_to_lines(
36
+ collection_bookend: :close
37
+ ) do |t2|
38
+ t2.add_text "}>"
30
39
  end
31
40
  end
32
41
  end
@@ -0,0 +1,46 @@
1
+ module SuperDiff
2
+ module ActiveSupport
3
+ module ObjectInspection
4
+ module InspectionTreeBuilders
5
+ class OrderedOptions < SuperDiff::ObjectInspection::InspectionTreeBuilders::Hash
6
+ def self.applies_to?(value)
7
+ value.is_a?(::ActiveSupport::OrderedOptions)
8
+ end
9
+
10
+ def call
11
+ SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
+ # stree-ignore
13
+ t1.as_lines_when_rendering_to_lines(
14
+ collection_bookend: :open
15
+ ) do |t2|
16
+ t2.add_text "#<OrderedOptions {"
17
+ end
18
+
19
+ # stree-ignore
20
+ t1.when_rendering_to_string do |t2|
21
+ t2.add_text " "
22
+ end
23
+
24
+ # stree-ignore
25
+ t1.nested do |t2|
26
+ t2.insert_hash_inspection_of(object.to_hash)
27
+ end
28
+
29
+ # stree-ignore
30
+ t1.when_rendering_to_string do |t2|
31
+ t2.add_text " "
32
+ end
33
+
34
+ # stree-ignore
35
+ t1.as_lines_when_rendering_to_lines(
36
+ collection_bookend: :close
37
+ ) do |t2|
38
+ t2.add_text "}>"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -4,7 +4,11 @@ module SuperDiff
4
4
  module InspectionTreeBuilders
5
5
  autoload(
6
6
  :HashWithIndifferentAccess,
7
- "super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access",
7
+ "super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access"
8
+ )
9
+ autoload(
10
+ :OrderedOptions,
11
+ "super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options"
8
12
  )
9
13
  end
10
14
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module ObjectInspection
4
4
  autoload(
5
5
  :InspectionTreeBuilders,
6
- "super_diff/active_support/object_inspection/inspection_tree_builders",
6
+ "super_diff/active_support/object_inspection/inspection_tree_builders"
7
7
  )
8
8
  end
9
9
  end
@@ -4,13 +4,12 @@ module SuperDiff
4
4
  class HashWithIndifferentAccess < SuperDiff::OperationTreeBuilders::Hash
5
5
  def self.applies_to?(expected, actual)
6
6
  (
7
- expected.is_a?(::HashWithIndifferentAccess) &&
8
- actual.is_a?(::Hash)
7
+ expected.is_a?(::HashWithIndifferentAccess) && actual.is_a?(::Hash)
9
8
  ) ||
10
- (
11
- expected.is_a?(::Hash) &&
12
- actual.is_a?(::HashWithIndifferentAccess)
13
- )
9
+ (
10
+ expected.is_a?(::Hash) &&
11
+ actual.is_a?(::HashWithIndifferentAccess)
12
+ )
14
13
  end
15
14
 
16
15
  def initialize(expected:, actual:, **rest)
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module OperationTreeBuilders
4
4
  autoload(
5
5
  :HashWithIndifferentAccess,
6
- "super_diff/active_support/operation_tree_builders/hash_with_indifferent_access",
6
+ "super_diff/active_support/operation_tree_builders/hash_with_indifferent_access"
7
7
  )
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module OperationTreeFlatteners
4
4
  autoload(
5
5
  :HashWithIndifferentAccess,
6
- "super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access",
6
+ "super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access"
7
7
  )
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module OperationTrees
4
4
  autoload(
5
5
  :HashWithIndifferentAccess,
6
- "super_diff/active_support/operation_trees/hash_with_indifferent_access",
6
+ "super_diff/active_support/operation_trees/hash_with_indifferent_access"
7
7
  )
8
8
  end
9
9
  end