super_diff 0.9.0 → 0.10.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 (193) 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 +5 -13
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
  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 +3 -9
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
  19. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  21. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  22. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  23. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  24. data/lib/super_diff/active_support.rb +6 -11
  25. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  26. data/lib/super_diff/configuration.rb +14 -8
  27. data/lib/super_diff/csi/color.rb +4 -4
  28. data/lib/super_diff/csi/colorized_document.rb +12 -16
  29. data/lib/super_diff/csi/document.rb +8 -19
  30. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  31. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  32. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  33. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  34. data/lib/super_diff/csi.rb +10 -14
  35. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  36. data/lib/super_diff/differs/default_object.rb +1 -1
  37. data/lib/super_diff/differs/defaults.rb +1 -1
  38. data/lib/super_diff/differs/main.rb +2 -13
  39. data/lib/super_diff/equality_matchers/array.rb +10 -12
  40. data/lib/super_diff/equality_matchers/base.rb +1 -1
  41. data/lib/super_diff/equality_matchers/default.rb +2 -4
  42. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  43. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  44. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  45. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  46. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  47. data/lib/super_diff/equality_matchers.rb +1 -1
  48. data/lib/super_diff/errors.rb +3 -3
  49. data/lib/super_diff/gem_version.rb +3 -3
  50. data/lib/super_diff/helpers.rb +10 -10
  51. data/lib/super_diff/implementation_checks.rb +2 -2
  52. data/lib/super_diff/line.rb +3 -3
  53. data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
  54. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
  60. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
  61. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
  62. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  63. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  64. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  65. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  66. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  67. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  68. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  69. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  70. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  71. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  72. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  74. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  75. data/lib/super_diff/object_inspection.rb +3 -3
  76. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  77. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  78. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  79. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  80. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  81. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  82. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  83. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  84. data/lib/super_diff/operation_tree_builders.rb +1 -1
  85. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  86. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  87. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  88. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  89. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  90. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  91. data/lib/super_diff/operation_trees/base.rb +3 -5
  92. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  93. data/lib/super_diff/operations/binary_operation.rb +2 -2
  94. data/lib/super_diff/operations/unary_operation.rb +1 -1
  95. data/lib/super_diff/rails.rb +2 -1
  96. data/lib/super_diff/recursion_guard.rb +5 -4
  97. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  98. data/lib/super_diff/rspec/differ.rb +6 -13
  99. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  100. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  101. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  102. data/lib/super_diff/rspec/differs.rb +3 -3
  103. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  104. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  108. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  109. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  110. data/lib/super_diff/rspec/monkey_patches.rb +122 -116
  111. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
  117. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  118. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  119. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  120. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  121. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  122. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  123. data/lib/super_diff/rspec.rb +11 -13
  124. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  125. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  126. data/lib/super_diff/version.rb +1 -1
  127. data/lib/super_diff.rb +4 -9
  128. data/spec/examples.txt +493 -485
  129. data/spec/integration/rails/active_record_spec.rb +3 -1
  130. data/spec/integration/rails/engines_spec.rb +20 -0
  131. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  132. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  133. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  134. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  135. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  136. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  137. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
  138. data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
  139. data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
  140. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  141. data/spec/integration/rspec/include_matcher_spec.rb +317 -215
  142. data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
  143. data/spec/integration/rspec/match_matcher_spec.rb +847 -834
  144. data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
  145. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  146. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  147. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  148. data/spec/spec_helper.rb +17 -20
  149. data/spec/support/command_runner.rb +34 -57
  150. data/spec/support/integration/helpers.rb +35 -28
  151. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  152. data/spec/support/integration/test_programs/base.rb +12 -17
  153. data/spec/support/integration/test_programs/plain.rb +6 -0
  154. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  155. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  156. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  157. data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
  158. data/spec/support/models/active_record/person.rb +6 -4
  159. data/spec/support/models/active_record/shipping_address.rb +9 -10
  160. data/spec/support/models/customer.rb +2 -4
  161. data/spec/support/models/player.rb +3 -6
  162. data/spec/support/models/shipping_address.rb +4 -13
  163. data/spec/support/shared_examples/active_record.rb +232 -214
  164. data/spec/support/shared_examples/active_support.rb +53 -51
  165. data/spec/support/shared_examples/elided_diffs.rb +405 -381
  166. data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
  167. data/spec/support/shared_examples/key.rb +123 -0
  168. data/spec/support/unit/helpers.rb +1 -3
  169. data/spec/support/unit/matchers/match_output.rb +12 -13
  170. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  171. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  172. data/spec/unit/helpers_spec.rb +14 -21
  173. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  174. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  175. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  176. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  177. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  178. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  179. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  180. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  181. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  182. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  183. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  184. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
  186. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  187. data/spec/unit/rspec/object_inspection_spec.rb +349 -324
  188. data/spec/unit/super_diff_spec.rb +1542 -1449
  189. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  190. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  191. data/super_diff.gemspec +13 -12
  192. metadata +73 -73
  193. 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: bb5307b0f4dab85f765805443f6315ea45ec58d81f94211292326e32b98e1539
4
+ data.tar.gz: 3af49d5f9a3d7396828fdc6c1b74cd8e4103ff35fc2ebced5dbef15071fe0bab
5
5
  SHA512:
6
- metadata.gz: 78535779a6e462100afb0ec019ea0b1241e5f6710c40005150d3d8784d34227dc0b549de20fe3dbbc453b6563903df78fc21925701f8d5c7f0d3d466c8345641
7
- data.tar.gz: 5a049b0606ae5ff5ac18978e8591ede3edcdcecf6e48eb58ced6655527b481bf2f4a17623c981b902c5ea86295e3dc9bd633905502113edbc162724edd475389
6
+ metadata.gz: 9aea5c125c0dbde9f754f4d0fd72dd20142cfe4f49077d9f7ab7e47994ea09297c5f58fc3cd59f564fe9534e17ae7e2a062433c03830dc3d209ee2217d503270
7
+ data.tar.gz: f1f31c074ce8f043f7ac72127b5bd46158433a5ec6af3a0b79250f08e276fba8d1936b5ed5a09e2134e1ee3e4087b7bec36535da556f7b0b04953690edb949b9
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
@@ -10,31 +10,23 @@ module SuperDiff
10
10
  def call
11
11
  SuperDiff::ObjectInspection::InspectionTree.new do
12
12
  as_lines_when_rendering_to_lines(collection_bookend: :open) do
13
- add_text do |object|
14
- "#<#{object.class} "
15
- end
13
+ add_text { |object| "#<#{object.class} " }
16
14
 
17
- when_rendering_to_lines do
18
- add_text "{"
19
- end
15
+ when_rendering_to_lines { add_text "{" }
20
16
  end
21
17
 
22
18
  nested do |object|
23
19
  insert_separated_list(
24
- ["id"] + (object.attributes.keys.sort - ["id"]),
20
+ ["id"] + (object.attributes.keys.sort - ["id"])
25
21
  ) do |name|
26
- as_prefix_when_rendering_to_lines do
27
- add_text "#{name}: "
28
- end
22
+ as_prefix_when_rendering_to_lines { add_text "#{name}: " }
29
23
 
30
24
  add_inspection_of object.read_attribute(name)
31
25
  end
32
26
  end
33
27
 
34
28
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
35
- when_rendering_to_lines do
36
- add_text "}"
37
- end
29
+ when_rendering_to_lines { add_text "}" }
38
30
 
39
31
  add_text ">"
40
32
  end
@@ -13,9 +13,7 @@ module SuperDiff
13
13
  add_text "#<ActiveRecord::Relation ["
14
14
  end
15
15
 
16
- nested do |array|
17
- insert_array_inspection_of(array)
18
- end
16
+ nested { |array| insert_array_inspection_of(array) }
19
17
 
20
18
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
21
19
  add_text "]>"
@@ -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
@@ -13,17 +13,11 @@ module SuperDiff
13
13
  add_text "#<HashWithIndifferentAccess {"
14
14
  end
15
15
 
16
- when_rendering_to_string do
17
- add_text " "
18
- end
16
+ when_rendering_to_string { add_text " " }
19
17
 
20
- nested do |hash|
21
- insert_hash_inspection_of(hash)
22
- end
18
+ nested { |hash| insert_hash_inspection_of(hash) }
23
19
 
24
- when_rendering_to_string do
25
- add_text " "
26
- end
20
+ when_rendering_to_string { add_text " " }
27
21
 
28
22
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
29
23
  add_text "}>"
@@ -4,7 +4,7 @@ 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
8
  )
9
9
  end
10
10
  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
@@ -2,28 +2,23 @@ module SuperDiff
2
2
  module ActiveSupport
3
3
  autoload :Differs, "super_diff/active_support/differs"
4
4
  autoload :ObjectInspection, "super_diff/active_support/object_inspection"
5
- autoload(
6
- :OperationTrees,
7
- "super_diff/active_support/operation_trees",
8
- )
5
+ autoload(:OperationTrees, "super_diff/active_support/operation_trees")
9
6
  autoload(
10
7
  :OperationTreeBuilders,
11
- "super_diff/active_support/operation_tree_builders",
8
+ "super_diff/active_support/operation_tree_builders"
12
9
  )
13
10
  autoload(
14
11
  :OperationTreeFlatteners,
15
- "super_diff/active_support/operation_tree_flatteners",
12
+ "super_diff/active_support/operation_tree_flatteners"
16
13
  )
17
14
 
18
15
  SuperDiff.configure do |config|
19
- config.add_extra_differ_classes(
20
- Differs::HashWithIndifferentAccess,
21
- )
16
+ config.add_extra_differ_classes(Differs::HashWithIndifferentAccess)
22
17
  config.add_extra_operation_tree_builder_classes(
23
- OperationTreeBuilders::HashWithIndifferentAccess,
18
+ OperationTreeBuilders::HashWithIndifferentAccess
24
19
  )
25
20
  config.add_extra_inspection_tree_builder_classes(
26
- ObjectInspection::InspectionTreeBuilders::HashWithIndifferentAccess,
21
+ ObjectInspection::InspectionTreeBuilders::HashWithIndifferentAccess
27
22
  )
28
23
  end
29
24
  end
@@ -1,12 +1,10 @@
1
1
  module SuperDiff
2
2
  module ColorizedDocumentExtensions
3
3
  def self.extended(extendee)
4
- extendee.singleton_class.class_eval do
5
- alias_method :normal, :text
6
- end
4
+ extendee.singleton_class.class_eval { alias_method :normal, :text }
7
5
  end
8
6
 
9
- [:actual, :border, :elision_marker, :expected, :header].each do |method_name|
7
+ %i[actual border elision_marker expected header].each do |method_name|
10
8
  define_method(method_name) do |*args, **opts, &block|
11
9
  colorize(
12
10
  *args,