super_diff 0.4.2 → 0.6.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.
- checksums.yaml +4 -4
- data/README.md +64 -24
- data/lib/super_diff.rb +20 -17
- data/lib/super_diff/active_record.rb +20 -24
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
- data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
- data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
- data/lib/super_diff/active_support.rb +16 -19
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
- data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
- data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/colorized_document_extensions.rb +4 -4
- data/lib/super_diff/configuration.rb +70 -0
- data/lib/super_diff/csi.rb +2 -1
- data/lib/super_diff/diff_formatters.rb +3 -3
- data/lib/super_diff/diff_formatters/array.rb +3 -3
- data/lib/super_diff/diff_formatters/base.rb +3 -2
- data/lib/super_diff/diff_formatters/collection.rb +3 -3
- data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
- data/lib/super_diff/diff_formatters/default_object.rb +6 -8
- data/lib/super_diff/diff_formatters/defaults.rb +10 -0
- data/lib/super_diff/diff_formatters/hash.rb +3 -3
- data/lib/super_diff/diff_formatters/main.rb +41 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +7 -7
- data/lib/super_diff/differs.rb +4 -11
- data/lib/super_diff/differs/array.rb +2 -11
- data/lib/super_diff/differs/base.rb +20 -3
- data/lib/super_diff/differs/custom_object.rb +2 -11
- data/lib/super_diff/differs/default_object.rb +2 -8
- data/lib/super_diff/differs/defaults.rb +12 -0
- data/lib/super_diff/differs/hash.rb +2 -11
- data/lib/super_diff/differs/main.rb +48 -0
- data/lib/super_diff/differs/multiline_string.rb +2 -14
- data/lib/super_diff/differs/time_like.rb +15 -0
- data/lib/super_diff/equality_matchers.rb +3 -9
- data/lib/super_diff/equality_matchers/array.rb +3 -9
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +3 -9
- data/lib/super_diff/equality_matchers/defaults.rb +12 -0
- data/lib/super_diff/equality_matchers/hash.rb +3 -9
- data/lib/super_diff/equality_matchers/main.rb +21 -0
- data/lib/super_diff/equality_matchers/multiline_string.rb +3 -9
- data/lib/super_diff/equality_matchers/primitive.rb +2 -2
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/errors.rb +16 -0
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
- data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
- data/lib/super_diff/gem_version.rb +45 -0
- data/lib/super_diff/implementation_checks.rb +19 -0
- data/lib/super_diff/object_inspection.rb +1 -10
- data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
- data/lib/super_diff/object_inspection/inspectors.rb +5 -1
- data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
- data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
- data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
- data/lib/super_diff/operation_tree_builders.rb +18 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
- data/lib/super_diff/operation_tree_builders/base.rb +98 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
- data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
- data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
- data/lib/super_diff/operation_tree_builders/main.rb +42 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
- data/lib/super_diff/operation_trees.rb +13 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/base.rb +9 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
- data/lib/super_diff/operation_trees/defaults.rb +5 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
- data/lib/super_diff/operation_trees/main.rb +35 -0
- data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
- data/lib/super_diff/operations/unary_operation.rb +3 -0
- data/lib/super_diff/recursion_guard.rb +2 -0
- data/lib/super_diff/rspec.rb +49 -13
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +2 -17
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +2 -7
- data/lib/super_diff/rspec/differs/collection_including.rb +2 -7
- data/lib/super_diff/rspec/differs/hash_including.rb +2 -7
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +2 -7
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
- data/lib/super_diff/rspec/monkey_patches.rb +23 -14
- data/lib/super_diff/rspec/object_inspection.rb +0 -1
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +16 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +15 -9
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +20 -10
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +20 -11
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
- data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +17 -6
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_including.rb +2 -2
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/hash_including.rb +3 -11
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/object_having_attributes.rb +4 -8
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +393 -393
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_matcher_spec.rb +100 -100
- data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +107 -107
- data/spec/integration/rspec/eq_matcher_spec.rb +230 -230
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +360 -233
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
- data/spec/integration/rspec/include_matcher_spec.rb +73 -73
- data/spec/integration/rspec/match_array_matcher_spec.rb +149 -107
- data/spec/integration/rspec/match_matcher_spec.rb +274 -274
- data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
- data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
- data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
- data/spec/integration/rspec/unhandled_errors_spec.rb +69 -13
- data/spec/spec_helper.rb +22 -13
- data/spec/support/command_runner.rb +3 -0
- data/spec/support/integration/helpers.rb +15 -95
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +15 -30
- data/spec/support/integration/test_programs/base.rb +122 -0
- data/spec/support/integration/test_programs/plain.rb +13 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
- data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
- data/spec/support/models/active_record/person.rb +4 -11
- data/spec/support/models/active_record/shipping_address.rb +10 -14
- data/spec/support/object_id.rb +6 -5
- data/spec/support/shared_examples/active_record.rb +108 -108
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
- data/spec/tmp/integration_spec.rb +15 -0
- data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +518 -362
- data/spec/unit/object_inspection_spec.rb +77 -1
- data/super_diff.gemspec +3 -2
- metadata +83 -54
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
- data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
- data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
- data/lib/super_diff/diff_formatter.rb +0 -32
- data/lib/super_diff/differ.rb +0 -51
- data/lib/super_diff/differs/time.rb +0 -24
- data/lib/super_diff/equality_matcher.rb +0 -32
- data/lib/super_diff/no_differ_available_error.rb +0 -22
- data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
- data/lib/super_diff/object_inspection/inspector.rb +0 -27
- data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
- data/lib/super_diff/object_inspection/map.rb +0 -30
- data/lib/super_diff/operation_sequences.rb +0 -9
- data/lib/super_diff/operational_sequencer.rb +0 -48
- data/lib/super_diff/operational_sequencers.rb +0 -17
- data/lib/super_diff/operational_sequencers/base.rb +0 -89
- data/lib/super_diff/operational_sequencers/hash.rb +0 -85
- data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
- data/lib/super_diff/rspec/configuration.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
- data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 854afb65d4337f48bd39a3e8529eb73f0ff01590a74a0a59b0df84827aff8746
|
4
|
+
data.tar.gz: '07356729294beab45bb4402398ed832819b8c9f5aba888b5004c251aaab97935'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 240e383f75cd8fc6256c4951d288b16171e97b26267772e1af707c0fc33497547bccae2049647ed669d071fbfc8c2c6547c69488bdd3e3ce42a046d74e73dbe4
|
7
|
+
data.tar.gz: 3a3c30108caf9f15704f3c8c21c753b5e8d89ac900bdbc00cca4909a4b5a13d152cde73d0a72ea74d8a9a1b4a8775d42f87619765d22fc7b7ac00e235d70576b
|
data/README.md
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
# SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][
|
1
|
+
# SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][gh-actions-badge]][gh-actions] ![Downloads][downloads-badge] [![IssueHunt][issuehunt-badge]][issuehunt]
|
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
|
-
[
|
5
|
+
[gh-actions-badge]: http://img.shields.io/github/workflow/status/mcmire/super_diff/SuperDiff/master
|
6
6
|
[downloads-badge]: http://img.shields.io/gem/dtv/super_diff.svg
|
7
|
-
[hound-badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
|
8
7
|
[hound]: https://houndci.com
|
8
|
+
[issuehunt-badge]: https://img.shields.io/badge/sponsored_through-IssueHunt-2EC28C
|
9
|
+
[issuehunt]: https://issuehunt.io/r/mcmire/super_diff
|
9
10
|
|
10
11
|
SuperDiff is a gem that hooks into RSpec
|
11
12
|
to intelligently display the differences between two data structures of any type.
|
12
13
|
|
13
|
-
📢 **[See what's changed in
|
14
|
+
📢 **[See what's changed in recent versions.][changelog]**
|
14
15
|
|
15
16
|
[changelog]: CHANGELOG.md
|
16
17
|
|
@@ -85,7 +86,7 @@ expect(actual).to eq(expected)
|
|
85
86
|
|
86
87
|
You would get output that looks like this:
|
87
88
|
|
88
|
-

|
89
90
|
|
90
91
|
What this library does
|
91
92
|
is to provide a diff engine
|
@@ -94,7 +95,7 @@ and display them in a sensible way.
|
|
94
95
|
So, using the example above,
|
95
96
|
you'd get this instead:
|
96
97
|
|
97
|
-

|
98
99
|
|
99
100
|
## Installation
|
100
101
|
|
@@ -154,26 +155,57 @@ require "super_diff/rspec"
|
|
154
155
|
|
155
156
|
## Configuration
|
156
157
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
In that case
|
163
|
-
you would add something like this to your test helper file
|
164
|
-
(`rails_helper` or `spec_helper`):
|
158
|
+
You can customize the behavior of the gem
|
159
|
+
by adding a configuration block
|
160
|
+
to your test helper file
|
161
|
+
(`rails_helper` or `spec_helper`)
|
162
|
+
which looks something like this:
|
165
163
|
|
166
164
|
``` ruby
|
167
|
-
SuperDiff
|
165
|
+
SuperDiff.configure do |config|
|
166
|
+
# ...
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
### Customizing colors
|
171
|
+
|
172
|
+
If you don't like the colors that SuperDiff uses,
|
173
|
+
you can change them like this:
|
174
|
+
|
175
|
+
``` ruby
|
176
|
+
SuperDiff.configure do |config|
|
177
|
+
config.actual_color = :green
|
178
|
+
config.expected_color = :red
|
179
|
+
config.border_color = :yellow
|
180
|
+
config.header_color = :yellow
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
See [eight_bit_color.rb](lib/super_diff/csi/eight_bit_color.rb)
|
185
|
+
for the list of available colors.
|
186
|
+
|
187
|
+
### Diffing custom objects
|
188
|
+
|
189
|
+
If you are comparing two data structures
|
190
|
+
that involve a class that is specific to your project,
|
191
|
+
the resulting diff may not look as good as diffs involving native or primitive objects.
|
192
|
+
This happens because if SuperDiff doesn't recognize a class,
|
193
|
+
it will fall back to a generic representation when diffing instances of that class.
|
194
|
+
Fortunately, the gem has a pluggable interface
|
195
|
+
that allows you to insert your own implementations
|
196
|
+
of key pieces involved in the diffing process.
|
197
|
+
I'll have more about how that works soon,
|
198
|
+
but here is what such a configuration would look like:
|
199
|
+
|
200
|
+
``` ruby
|
201
|
+
SuperDiff.configure do |config|
|
168
202
|
config.add_extra_differ_class(YourDiffer)
|
169
|
-
config.
|
203
|
+
config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
|
204
|
+
config.add_extra_operation_tree_class(YourOperationTree)
|
170
205
|
config.add_extra_diff_formatter_class(YourDiffFormatter)
|
171
206
|
end
|
172
207
|
```
|
173
208
|
|
174
|
-
*(More info here in the future on adding a custom differ, operational sequencer, and diff formatter.
|
175
|
-
Also explanations on what these are.)*
|
176
|
-
|
177
209
|
## Support
|
178
210
|
|
179
211
|
My goal for this library is to improve your development experience.
|
@@ -186,17 +218,25 @@ I'll try to respond to it as soon as I can!
|
|
186
218
|
|
187
219
|
## Contributing
|
188
220
|
|
189
|
-
Any contributions to improve this library are welcome!
|
221
|
+
Any code contributions to improve this library are welcome!
|
190
222
|
Please see the [contributing](./CONTRIBUTING.md) document for more on how to do that.
|
191
223
|
|
224
|
+
## Sponsoring
|
225
|
+
|
226
|
+
If there's a change you want implemented, you can choose to sponsor that change!
|
227
|
+
`super_diff` is set up on IssueHunt,
|
228
|
+
so feel free to search for an existing issue (or make your own)
|
229
|
+
and [add a bounty](https://issuehunt.io/r/mcmire/super_diff).
|
230
|
+
I'll get notified right away!
|
231
|
+
|
192
232
|
## Compatibility
|
193
233
|
|
194
|
-
`super_diff` is [tested][
|
195
|
-
Ruby >= 2.
|
234
|
+
`super_diff` is [tested][gh-actions] to work with
|
235
|
+
Ruby >= 2.5.x,
|
196
236
|
RSpec 3.x,
|
197
237
|
and Rails >= 5.x.
|
198
238
|
|
199
|
-
[
|
239
|
+
[gh-actions]: https://github.com/mcmire/super_diff/actions?query=workflow%3ASuperDiff
|
200
240
|
|
201
241
|
## Inspiration/Thanks
|
202
242
|
|
@@ -219,5 +259,5 @@ Thank you to the authors of these libraries!
|
|
219
259
|
|
220
260
|
## Author/License
|
221
261
|
|
222
|
-
|
262
|
+
SuperDiff was created and is maintained by Elliot Winkler.
|
223
263
|
It is released under the [MIT license](LICENSE).
|
data/lib/super_diff.rb
CHANGED
@@ -7,30 +7,33 @@ module SuperDiff
|
|
7
7
|
:ColorizedDocumentExtensions,
|
8
8
|
"super_diff/colorized_document_extensions",
|
9
9
|
)
|
10
|
+
autoload :Configuration, "super_diff/configuration"
|
10
11
|
autoload :Csi, "super_diff/csi"
|
11
|
-
autoload :DiffFormatter, "super_diff/diff_formatter"
|
12
12
|
autoload :DiffFormatters, "super_diff/diff_formatters"
|
13
|
-
autoload :Differ, "super_diff/differ"
|
14
13
|
autoload :Differs, "super_diff/differs"
|
15
|
-
autoload :EqualityMatcher, "super_diff/equality_matcher"
|
16
14
|
autoload :EqualityMatchers, "super_diff/equality_matchers"
|
15
|
+
autoload :Errors, "super_diff/errors"
|
16
|
+
autoload :GemVersion, "super_diff/gem_version"
|
17
17
|
autoload :Helpers, "super_diff/helpers"
|
18
|
-
autoload :
|
19
|
-
autoload(
|
20
|
-
:NoOperationalSequencerAvailableError,
|
21
|
-
"super_diff/no_operational_sequencer_available_error",
|
22
|
-
)
|
18
|
+
autoload :ImplementationChecks, "super_diff/implementation_checks"
|
23
19
|
autoload :ObjectInspection, "super_diff/object_inspection"
|
24
|
-
autoload :
|
25
|
-
autoload :
|
26
|
-
autoload :OperationSequences, "super_diff/operation_sequences"
|
20
|
+
autoload :OperationTrees, "super_diff/operation_trees"
|
21
|
+
autoload :OperationTreeBuilders, "super_diff/operation_tree_builders"
|
27
22
|
autoload :Operations, "super_diff/operations"
|
28
23
|
autoload :RecursionGuard, "super_diff/recursion_guard"
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
def self.configure
|
26
|
+
yield configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.configuration
|
30
|
+
@_configuration ||= Configuration.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.time_like?(value)
|
34
|
+
# Check for ActiveSupport's #acts_like_time? for their time-like objects
|
35
|
+
# (like ActiveSupport::TimeWithZone).
|
36
|
+
(value.respond_to?(:acts_like_time?) && value.acts_like_time?) ||
|
37
|
+
value.is_a?(Time)
|
38
|
+
end
|
36
39
|
end
|
@@ -9,35 +9,31 @@ module SuperDiff
|
|
9
9
|
"super_diff/active_record/object_inspection",
|
10
10
|
)
|
11
11
|
autoload(
|
12
|
-
:
|
13
|
-
"super_diff/active_record/
|
12
|
+
:OperationTrees,
|
13
|
+
"super_diff/active_record/operation_trees",
|
14
14
|
)
|
15
15
|
autoload(
|
16
|
-
:
|
17
|
-
"super_diff/active_record/
|
16
|
+
:OperationTreeBuilders,
|
17
|
+
"super_diff/active_record/operation_tree_builders",
|
18
18
|
)
|
19
|
-
end
|
20
|
-
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
20
|
+
SuperDiff.configure do |config|
|
21
|
+
config.add_extra_differ_classes(
|
22
|
+
Differs::ActiveRecordRelation,
|
23
|
+
)
|
24
|
+
config.add_extra_operation_tree_builder_classes(
|
25
|
+
OperationTreeBuilders::ActiveRecordModel,
|
26
|
+
OperationTreeBuilders::ActiveRecordRelation,
|
27
|
+
)
|
28
|
+
config.add_extra_diff_formatter_classes(
|
29
|
+
DiffFormatters::ActiveRecordRelation,
|
30
|
+
)
|
31
|
+
config.add_extra_inspector_classes(
|
32
|
+
ObjectInspection::Inspectors::ActiveRecordModel,
|
33
|
+
ObjectInspection::Inspectors::ActiveRecordRelation,
|
34
|
+
)
|
35
|
+
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
require "super_diff/active_record/monkey_patches"
|
40
|
-
|
41
|
-
SuperDiff::ObjectInspection.map.prepend(
|
42
|
-
SuperDiff::ActiveRecord::ObjectInspection::MapExtension,
|
43
|
-
)
|
@@ -2,8 +2,8 @@ module SuperDiff
|
|
2
2
|
module ActiveRecord
|
3
3
|
module DiffFormatters
|
4
4
|
class ActiveRecordRelation < SuperDiff::DiffFormatters::Base
|
5
|
-
def self.applies_to?(
|
6
|
-
|
5
|
+
def self.applies_to?(operation_tree)
|
6
|
+
operation_tree.is_a?(OperationTrees::ActiveRecordRelation)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
@@ -12,7 +12,7 @@ module SuperDiff
|
|
12
12
|
close_token: "]>",
|
13
13
|
collection_prefix: collection_prefix,
|
14
14
|
build_item_prefix: proc { "" },
|
15
|
-
|
15
|
+
operation_tree: operation_tree,
|
16
16
|
indent_level: indent_level,
|
17
17
|
add_comma: add_comma?,
|
18
18
|
)
|
@@ -9,19 +9,17 @@ module SuperDiff
|
|
9
9
|
|
10
10
|
def call
|
11
11
|
DiffFormatters::ActiveRecordRelation.call(
|
12
|
-
|
12
|
+
operation_tree,
|
13
13
|
indent_level: indent_level,
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def operation_tree
|
20
|
+
OperationTreeBuilders::ActiveRecordRelation.call(
|
21
21
|
expected: expected,
|
22
22
|
actual: actual,
|
23
|
-
extra_operational_sequencer_classes: extra_operational_sequencer_classes,
|
24
|
-
extra_diff_formatter_classes: extra_diff_formatter_classes,
|
25
23
|
)
|
26
24
|
end
|
27
25
|
end
|
@@ -2,35 +2,45 @@ module SuperDiff
|
|
2
2
|
module ActiveRecord
|
3
3
|
module ObjectInspection
|
4
4
|
module Inspectors
|
5
|
-
ActiveRecordModel
|
6
|
-
|
7
|
-
|
5
|
+
class ActiveRecordModel < SuperDiff::ObjectInspection::Inspectors::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
value.is_a?(::ActiveRecord::Base)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
add_text "{"
|
12
|
-
end
|
10
|
+
protected
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
def inspection_tree
|
13
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
+
add_text do |object|
|
15
|
+
"#<#{object.class} "
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
) do |name|
|
21
|
-
add_text name
|
22
|
-
add_text ": "
|
23
|
-
add_inspection_of object.read_attribute(name)
|
24
|
-
end
|
25
|
-
end
|
18
|
+
when_multiline do
|
19
|
+
add_text "{"
|
20
|
+
end
|
26
21
|
|
27
|
-
|
22
|
+
nested do |object|
|
23
|
+
add_break
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
insert_separated_list(
|
26
|
+
["id"] + (object.attributes.keys.sort - ["id"]),
|
27
|
+
separator: ",",
|
28
|
+
) do |name|
|
29
|
+
add_text name
|
30
|
+
add_text ": "
|
31
|
+
add_inspection_of object.read_attribute(name)
|
32
|
+
end
|
33
|
+
end
|
32
34
|
|
33
|
-
|
35
|
+
add_break
|
36
|
+
|
37
|
+
when_multiline do
|
38
|
+
add_text "}"
|
39
|
+
end
|
40
|
+
|
41
|
+
add_text ">"
|
42
|
+
end
|
43
|
+
end
|
34
44
|
end
|
35
45
|
end
|
36
46
|
end
|
@@ -2,15 +2,25 @@ module SuperDiff
|
|
2
2
|
module ActiveRecord
|
3
3
|
module ObjectInspection
|
4
4
|
module Inspectors
|
5
|
-
ActiveRecordRelation
|
6
|
-
|
7
|
-
|
8
|
-
nested do |array|
|
9
|
-
insert_array_inspection_of(array)
|
5
|
+
class ActiveRecordRelation < SuperDiff::ObjectInspection::Inspectors::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
value.is_a?(::ActiveRecord::Relation)
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
protected
|
11
|
+
|
12
|
+
def inspection_tree
|
13
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
+
add_text "#<ActiveRecord::Relation ["
|
15
|
+
|
16
|
+
nested do |array|
|
17
|
+
insert_array_inspection_of(array)
|
18
|
+
end
|
19
|
+
|
20
|
+
add_break
|
21
|
+
add_text "]>"
|
22
|
+
end
|
23
|
+
end
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveRecord
|
3
|
+
module OperationTreeBuilders
|
4
|
+
autoload(
|
5
|
+
:ActiveRecordModel,
|
6
|
+
"super_diff/active_record/operation_tree_builders/active_record_model",
|
7
|
+
)
|
8
|
+
autoload(
|
9
|
+
:ActiveRecordRelation,
|
10
|
+
"super_diff/active_record/operation_tree_builders/active_record_relation",
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
|
-
module
|
4
|
-
class ActiveRecordModel < SuperDiff::
|
3
|
+
module OperationTreeBuilders
|
4
|
+
class ActiveRecordModel < SuperDiff::OperationTreeBuilders::CustomObject
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
expected.is_a?(::ActiveRecord::Base) &&
|
7
7
|
actual.is_a?(::ActiveRecord::Base) &&
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
|
-
module
|
4
|
-
class ActiveRecordRelation < SuperDiff::
|
3
|
+
module OperationTreeBuilders
|
4
|
+
class ActiveRecordRelation < SuperDiff::OperationTreeBuilders::Array
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
expected.is_a?(::Array) &&
|
7
7
|
actual.is_a?(::ActiveRecord::Relation)
|
@@ -15,8 +15,8 @@ module SuperDiff
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def
|
19
|
-
@
|
18
|
+
def operation_tree
|
19
|
+
@_operation_tree ||= OperationTrees::ActiveRecordRelation.new([])
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|