super_diff 0.11.0 → 0.12.1
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 +19 -166
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +57 -0
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +34 -0
- data/lib/super_diff/active_record/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/monkey_patches.rb +6 -3
- data/lib/super_diff/active_record/object_inspection.rb +16 -4
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +6 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record.rb +12 -16
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_support/object_inspection.rb +16 -4
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support.rb +11 -15
- data/lib/super_diff/basic/diff_formatters/collection.rb +135 -0
- data/lib/super_diff/basic/diff_formatters/multiline_string.rb +34 -0
- data/lib/super_diff/basic/diff_formatters.rb +11 -0
- data/lib/super_diff/basic/differs/array.rb +17 -0
- data/lib/super_diff/basic/differs/custom_object.rb +19 -0
- data/lib/super_diff/basic/differs/date_like.rb +17 -0
- data/lib/super_diff/basic/differs/default_object.rb +24 -0
- data/lib/super_diff/basic/differs/hash.rb +17 -0
- data/lib/super_diff/basic/differs/multiline_string.rb +18 -0
- data/lib/super_diff/basic/differs/time_like.rb +17 -0
- data/lib/super_diff/basic/differs.rb +24 -0
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/array.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/custom_object.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/date_like.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/default_object.rb +5 -7
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/hash.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/primitive.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/time_like.rb +3 -3
- data/lib/super_diff/basic/inspection_tree_builders.rb +20 -0
- data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
- data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
- data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
- data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
- data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
- data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
- data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
- data/lib/super_diff/basic/operation_tree_builders.rb +34 -0
- data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
- data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
- data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
- data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
- data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
- data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
- data/lib/super_diff/basic/operation_trees/array.rb +17 -0
- data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
- data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
- data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
- data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
- data/lib/super_diff/basic/operation_trees.rb +25 -0
- data/lib/super_diff/basic.rb +48 -0
- data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
- data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
- data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
- data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
- data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
- data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
- data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
- data/lib/super_diff/core/configuration.rb +192 -0
- data/lib/super_diff/core/differ_dispatcher.rb +31 -0
- data/lib/super_diff/core/gem_version.rb +47 -0
- data/lib/super_diff/core/helpers.rb +88 -0
- data/lib/super_diff/core/implementation_checks.rb +21 -0
- data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +7 -6
- data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +9 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
- data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
- data/lib/super_diff/core/line.rb +85 -0
- data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
- data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
- data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
- data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +24 -0
- data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
- data/lib/super_diff/core/operation_tree_finder.rb +27 -0
- data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/recursion_guard.rb +52 -0
- data/lib/super_diff/core/tiered_lines.rb +6 -0
- data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
- data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
- data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
- data/lib/super_diff/core.rb +69 -0
- data/lib/super_diff/differs.rb +19 -12
- data/lib/super_diff/equality_matchers/array.rb +3 -3
- data/lib/super_diff/equality_matchers/default.rb +8 -3
- data/lib/super_diff/equality_matchers/hash.rb +3 -3
- data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
- data/lib/super_diff/equality_matchers/primitive.rb +3 -3
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/errors.rb +12 -8
- data/lib/super_diff/object_inspection.rb +63 -14
- data/lib/super_diff/operation_tree_builders.rb +19 -15
- data/lib/super_diff/operation_tree_flatteners.rb +19 -16
- data/lib/super_diff/operation_trees.rb +19 -9
- data/lib/super_diff/operations.rb +12 -2
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +4 -5
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +1 -1
- data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
- data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
- data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
- data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
- data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
- data/lib/super_diff/rspec/object_inspection.rb +14 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
- data/lib/super_diff/rspec.rb +20 -18
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +69 -21
- data/spec/examples.txt +704 -543
- data/spec/support/integration/helpers.rb +4 -1
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
- data/spec/support/models/active_record/person.rb +8 -1
- data/spec/support/shared_examples/active_record.rb +5 -5
- data/spec/support/unit/helpers.rb +12 -1
- data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
- data/spec/unit/active_record/object_inspection_spec.rb +5 -5
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
- data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
- data/spec/unit/deprecations_spec.rb +176 -0
- data/spec/unit/equality_matchers/main_spec.rb +5 -5
- data/super_diff.gemspec +6 -0
- metadata +127 -115
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -51
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -36
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -46
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +0 -46
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -16
- data/lib/super_diff/colorized_document_extensions.rb +0 -18
- data/lib/super_diff/configuration.rb +0 -149
- data/lib/super_diff/diff_formatters/collection.rb +0 -132
- data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
- data/lib/super_diff/differs/array.rb +0 -15
- data/lib/super_diff/differs/custom_object.rb +0 -17
- data/lib/super_diff/differs/date_like.rb +0 -15
- data/lib/super_diff/differs/default_object.rb +0 -19
- data/lib/super_diff/differs/defaults.rb +0 -13
- data/lib/super_diff/differs/empty.rb +0 -13
- data/lib/super_diff/differs/hash.rb +0 -15
- data/lib/super_diff/differs/main.rb +0 -31
- data/lib/super_diff/differs/multiline_string.rb +0 -16
- data/lib/super_diff/differs/time_like.rb +0 -15
- data/lib/super_diff/gem_version.rb +0 -45
- data/lib/super_diff/helpers.rb +0 -86
- data/lib/super_diff/implementation_checks.rb +0 -19
- data/lib/super_diff/line.rb +0 -83
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -15
- data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -48
- data/lib/super_diff/object_inspection/nodes.rb +0 -50
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
- data/lib/super_diff/operation_tree_builders/array.rb +0 -107
- data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
- data/lib/super_diff/operation_tree_builders/date_like.rb +0 -15
- data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
- data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
- data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
- data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
- data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
- data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
- data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
- data/lib/super_diff/operation_trees/array.rb +0 -15
- data/lib/super_diff/operation_trees/custom_object.rb +0 -15
- data/lib/super_diff/operation_trees/default_object.rb +0 -40
- data/lib/super_diff/operation_trees/defaults.rb +0 -5
- data/lib/super_diff/operation_trees/hash.rb +0 -15
- data/lib/super_diff/operation_trees/main.rb +0 -35
- data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
- data/lib/super_diff/recursion_guard.rb +0 -50
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -42
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -102
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +0 -19
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -42
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -27
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -27
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -32
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -48
- data/lib/super_diff/tiered_lines.rb +0 -4
- data/lib/super_diff/tiered_lines_elider.rb +0 -462
- data/lib/super_diff/tiered_lines_formatter.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b261fa1a942123632f87e74d6b123826571840e9d779d21424ca590b6a646f8f
|
4
|
+
data.tar.gz: a2a780bc9752ec935edfd34bfb7588aa13c8a2357f1422037102e1c7774c31db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45a49cec47615c6c82e1cbae577c1bd9ad57852469f7a69d13c7daa8425971f8fdb109de7991db7b3f810dfcd9eb58d0cd1635c9497b913496ef8e5ab9e0f73b
|
7
|
+
data.tar.gz: 8bf439969e3e15fe39661e25e65abca5a442a055efad43089d16bdd0a383c36c0ff02c67a6f73644d04c5581c8cf2a0c72b50f5a67d543046acd875a8c081e64
|
data/README.md
CHANGED
@@ -8,24 +8,23 @@
|
|
8
8
|
[issuehunt-badge]: https://img.shields.io/badge/sponsored_through-IssueHunt-2EC28C
|
9
9
|
[issuehunt]: https://issuehunt.io/r/mcmire/super_diff
|
10
10
|
|
11
|
-
SuperDiff is a gem
|
12
|
-
to
|
11
|
+
**SuperDiff** is a Ruby gem
|
12
|
+
which is designed to display the differences between two objects of any type
|
13
|
+
in a familiar and intelligent fashion.
|
13
14
|
|
14
15
|
📢 **[See what's changed in recent versions.][changelog]**
|
15
16
|
|
16
|
-
[changelog]: CHANGELOG.md
|
17
|
+
[changelog]: ./CHANGELOG.md
|
17
18
|
|
18
19
|
## Introduction
|
19
20
|
|
20
21
|
The primary motivation behind this gem
|
21
22
|
is to vastly improve upon RSpec's built-in diffing capabilities.
|
22
|
-
|
23
|
-
|
23
|
+
RSpec has many nice features,
|
24
|
+
and one of them is that whenever you use a matcher such as `eq`, `match`, `include`, or `have_attributes`,
|
24
25
|
you will get a diff of the two data structures you are trying to match against.
|
25
26
|
This is great if all you want to do is compare multi-line strings.
|
26
|
-
But if you want to compare other, more "real world" kinds of values,
|
27
|
-
such as what you might work with when developing API endpoints
|
28
|
-
or testing methods that make database calls and return a set of model objects,
|
27
|
+
But if you want to compare other, more "real world" kinds of values such as API or database data,
|
29
28
|
then you are out of luck.
|
30
29
|
Since [RSpec merely runs your `expected` and `actual` values through Ruby's PrettyPrinter library][rspec-differ-fail]
|
31
30
|
and then performs a diff of these strings,
|
@@ -33,8 +32,7 @@ the output it produces leaves much to be desired.
|
|
33
32
|
|
34
33
|
[rspec-differ-fail]: https://github.com/rspec/rspec-support/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
|
35
34
|
|
36
|
-
For instance,
|
37
|
-
let's say you wanted to compare these two hashes:
|
35
|
+
For instance, let's say you wanted to compare these two hashes:
|
38
36
|
|
39
37
|
```ruby
|
40
38
|
actual = {
|
@@ -78,7 +76,7 @@ expect(actual).to eq(expected)
|
|
78
76
|
|
79
77
|
You would get output that looks like this:
|
80
78
|
|
81
|
-

|
79
|
+

|
82
80
|
|
83
81
|
What this library does
|
84
82
|
is to provide a diff engine
|
@@ -87,162 +85,14 @@ and display them in a sensible way.
|
|
87
85
|
So, using the example above,
|
88
86
|
you'd get this instead:
|
89
87
|
|
90
|
-

|
91
|
-
|
92
|
-
## Installation
|
93
|
-
|
94
|
-
There are a few different ways to install `super_diff`
|
95
|
-
depending on your type of project.
|
96
|
-
|
97
|
-
### Rails apps
|
98
|
-
|
99
|
-
If you're developing a Rails app,
|
100
|
-
add the following to your Gemfile:
|
101
|
-
|
102
|
-
```ruby
|
103
|
-
group :test do
|
104
|
-
gem "super_diff"
|
105
|
-
end
|
106
|
-
```
|
107
|
-
|
108
|
-
After running `bundle install`,
|
109
|
-
add the following to your `rails_helper`:
|
110
|
-
|
111
|
-
```ruby
|
112
|
-
require "super_diff/rspec-rails"
|
113
|
-
```
|
114
|
-
|
115
|
-
### Projects using some part of Rails (e.g. ActiveModel)
|
116
|
-
|
117
|
-
If you're developing an app using Hanami or Sinatra,
|
118
|
-
or merely using a part of Rails such as ActiveModel,
|
119
|
-
add the following to your Gemfile where appropriate:
|
120
|
-
|
121
|
-
```ruby
|
122
|
-
gem "super_diff"
|
123
|
-
```
|
124
|
-
|
125
|
-
After running `bundle install`,
|
126
|
-
add the following to your `spec_helper`:
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
require "super_diff/rspec"
|
130
|
-
require "super_diff/active_support"
|
131
|
-
```
|
132
|
-
|
133
|
-
### Gems
|
134
|
-
|
135
|
-
If you're developing a gem,
|
136
|
-
add the following to your gemspec:
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
spec.add_development_dependency "super_diff"
|
140
|
-
```
|
141
|
-
|
142
|
-
Now add the following to your `spec_helper`:
|
143
|
-
|
144
|
-
```ruby
|
145
|
-
require "super_diff/rspec"
|
146
|
-
```
|
147
|
-
|
148
|
-
## Configuration
|
149
|
-
|
150
|
-
You can customize the behavior of the gem
|
151
|
-
by adding a configuration block
|
152
|
-
to your test helper file
|
153
|
-
(`rails_helper` or `spec_helper`)
|
154
|
-
which looks something like this:
|
155
|
-
|
156
|
-
```ruby
|
157
|
-
SuperDiff.configure do |config|
|
158
|
-
# ...
|
159
|
-
end
|
160
|
-
```
|
161
|
-
|
162
|
-
### Customizing colors
|
163
|
-
|
164
|
-
If you don't like the colors that SuperDiff uses,
|
165
|
-
you can change them like this:
|
88
|
+

|
166
89
|
|
167
|
-
|
168
|
-
SuperDiff.configure do |config|
|
169
|
-
config.actual_color = :green
|
170
|
-
config.expected_color = :red
|
171
|
-
config.border_color = :yellow
|
172
|
-
config.header_color = :yellow
|
173
|
-
end
|
174
|
-
```
|
175
|
-
|
176
|
-
See [eight_bit_color.rb](lib/super_diff/csi/eight_bit_color.rb)
|
177
|
-
for the list of available colors.
|
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 -->
|
90
|
+
## Installation & Usage
|
188
91
|
|
189
|
-
|
92
|
+
📘 For more on how to install and use SuperDiff,
|
93
|
+
[read the user documentation][user-docs].
|
190
94
|
|
191
|
-
|
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
|
-
|
226
|
-
### Diffing custom objects
|
227
|
-
|
228
|
-
If you are comparing two data structures
|
229
|
-
that involve a class that is specific to your project,
|
230
|
-
the resulting diff may not look as good as diffs involving native or primitive objects.
|
231
|
-
This happens because if SuperDiff doesn't recognize a class,
|
232
|
-
it will fall back to a generic representation when diffing instances of that class.
|
233
|
-
Fortunately, the gem has a pluggable interface
|
234
|
-
that allows you to insert your own implementations
|
235
|
-
of key pieces involved in the diffing process.
|
236
|
-
I'll have more about how that works soon,
|
237
|
-
but here is what such a configuration would look like:
|
238
|
-
|
239
|
-
```ruby
|
240
|
-
SuperDiff.configure do |config|
|
241
|
-
config.add_extra_differ_class(YourDiffer)
|
242
|
-
config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
|
243
|
-
config.add_extra_operation_tree_class(YourOperationTree)
|
244
|
-
end
|
245
|
-
```
|
95
|
+
[user-docs]: ./docs/users/getting-started.md
|
246
96
|
|
247
97
|
## Support
|
248
98
|
|
@@ -257,16 +107,19 @@ I'll try to respond to it as soon as I can!
|
|
257
107
|
## Contributing
|
258
108
|
|
259
109
|
Any code contributions to improve this library are welcome!
|
260
|
-
Please see the [contributing](./
|
110
|
+
Please see the [contributing](./docs/contributors/index.md) document
|
111
|
+
for more on how to do that.
|
261
112
|
|
262
113
|
## Sponsoring
|
263
114
|
|
264
115
|
If there's a change you want implemented, you can choose to sponsor that change!
|
265
116
|
`super_diff` is set up on IssueHunt,
|
266
117
|
so feel free to search for an existing issue (or make your own)
|
267
|
-
and [add a bounty]
|
118
|
+
and [add a bounty][issuehunt].
|
268
119
|
I'll get notified right away!
|
269
120
|
|
121
|
+
[issuehunt]: https://issuehunt.io/r/mcmire/super_diff
|
122
|
+
|
270
123
|
## Compatibility
|
271
124
|
|
272
125
|
`super_diff` is [tested][gh-actions] to work with
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
3
|
module Differs
|
4
|
-
class ActiveRecordRelation <
|
4
|
+
class ActiveRecordRelation < Core::AbstractDiffer
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
expected.is_a?(::Array) && actual.is_a?(::ActiveRecord::Relation)
|
7
7
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveRecord
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class ActiveRecordModel < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::ActiveRecord::Base)
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
object.class.primary_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
Core::InspectionTree.new do |t1|
|
15
|
+
t1.as_lines_when_rendering_to_lines(
|
16
|
+
collection_bookend: :open
|
17
|
+
) do |t2|
|
18
|
+
t2.add_text "#<#{object.class} "
|
19
|
+
|
20
|
+
# stree-ignore
|
21
|
+
t2.when_rendering_to_lines do |t3|
|
22
|
+
t3.add_text "{"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
t1.nested do |t2|
|
27
|
+
t2.insert_separated_list(
|
28
|
+
[id] + (object.attributes.keys.sort - [id])
|
29
|
+
) do |t3, name|
|
30
|
+
t3.as_prefix_when_rendering_to_lines do |t4|
|
31
|
+
t4.add_text "#{name}: "
|
32
|
+
end
|
33
|
+
|
34
|
+
if name == id
|
35
|
+
t3.add_inspection_of object.id
|
36
|
+
else
|
37
|
+
t3.add_inspection_of object.read_attribute(name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
t1.as_lines_when_rendering_to_lines(
|
43
|
+
collection_bookend: :close
|
44
|
+
) do |t2|
|
45
|
+
# stree-ignore
|
46
|
+
t2.when_rendering_to_lines do |t3|
|
47
|
+
t3.add_text "}"
|
48
|
+
end
|
49
|
+
|
50
|
+
t2.add_text ">"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveRecord
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class ActiveRecordRelation < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::ActiveRecord::Relation)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
|
+
# stree-ignore
|
12
|
+
t1.as_lines_when_rendering_to_lines(
|
13
|
+
collection_bookend: :open
|
14
|
+
) do |t2|
|
15
|
+
t2.add_text "#<ActiveRecord::Relation ["
|
16
|
+
end
|
17
|
+
|
18
|
+
# stree-ignore
|
19
|
+
t1.nested do |t2|
|
20
|
+
t2.insert_array_inspection_of(object)
|
21
|
+
end
|
22
|
+
|
23
|
+
# stree-ignore
|
24
|
+
t1.as_lines_when_rendering_to_lines(
|
25
|
+
collection_bookend: :close
|
26
|
+
) do |t2|
|
27
|
+
t2.add_text "]>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveRecord
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
autoload(
|
5
|
+
:ActiveRecordModel,
|
6
|
+
"super_diff/active_record/inspection_tree_builders/active_record_model"
|
7
|
+
)
|
8
|
+
autoload(
|
9
|
+
:ActiveRecordRelation,
|
10
|
+
"super_diff/active_record/inspection_tree_builders/active_record_relation"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
# rubocop:disable Style/BracesAroundHashParameters, Style/ClassAndModuleChildren
|
2
2
|
class ActiveRecord::Base
|
3
|
+
# TODO: Remove this monkey patch if possible
|
3
4
|
def attributes_for_super_diff
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
id_attr = self.class.primary_key
|
6
|
+
|
7
|
+
(attributes.keys.sort - [id_attr]).reduce(
|
8
|
+
{ id_attr.to_sym => id }
|
9
|
+
) { |hash, key| hash.merge(key.to_sym => attributes[key]) }
|
7
10
|
end
|
8
11
|
end
|
9
12
|
# rubocop:enable Style/BracesAroundHashParameters, Style/ClassAndModuleChildren
|
@@ -1,10 +1,22 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
3
|
module ObjectInspection
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
def self.const_missing(missing_const_name)
|
6
|
+
if ActiveRecord::InspectionTreeBuilders.const_defined?(
|
7
|
+
missing_const_name
|
8
|
+
)
|
9
|
+
warn <<~EOT
|
10
|
+
WARNING: SuperDiff::ActiveRecord::ObjectInspection::InspectionTreeBuilders::#{missing_const_name} is deprecated and will be removed in the next major release.
|
11
|
+
Please use SuperDiff::ActiveRecord::InspectionTreeBuilders::#{missing_const_name} instead.
|
12
|
+
#{caller_locations.join("\n")}
|
13
|
+
EOT
|
14
|
+
ActiveRecord::InspectionTreeBuilders.const_get(missing_const_name)
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
end
|
10
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
3
|
module OperationTreeBuilders
|
4
|
-
class ActiveRecordModel <
|
4
|
+
class ActiveRecordModel < Basic::OperationTreeBuilders::CustomObject
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
expected.is_a?(::ActiveRecord::Base) &&
|
7
7
|
actual.is_a?(::ActiveRecord::Base) && expected.class == actual.class
|
@@ -9,8 +9,12 @@ module SuperDiff
|
|
9
9
|
|
10
10
|
protected
|
11
11
|
|
12
|
+
def id
|
13
|
+
expected.class.primary_key
|
14
|
+
end
|
15
|
+
|
12
16
|
def attribute_names
|
13
|
-
[
|
17
|
+
[id] + (expected.attributes.keys.sort - [id])
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
3
|
module OperationTreeBuilders
|
4
|
-
class ActiveRecordRelation <
|
4
|
+
class ActiveRecordRelation < Basic::OperationTreeBuilders::Array
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
expected.is_a?(::Array) && actual.is_a?(::ActiveRecord::Relation)
|
7
7
|
end
|
@@ -1,28 +1,24 @@
|
|
1
1
|
require "super_diff/active_support"
|
2
2
|
|
3
|
+
require "super_diff/active_record/differs"
|
4
|
+
require "super_diff/active_record/inspection_tree_builders"
|
5
|
+
require "super_diff/active_record/operation_trees"
|
6
|
+
require "super_diff/active_record/operation_tree_builders"
|
7
|
+
require "super_diff/active_record/operation_tree_flatteners"
|
8
|
+
|
3
9
|
module SuperDiff
|
4
10
|
module ActiveRecord
|
5
|
-
autoload :
|
6
|
-
autoload(:ObjectInspection, "super_diff/active_record/object_inspection")
|
7
|
-
autoload(:OperationTrees, "super_diff/active_record/operation_trees")
|
8
|
-
autoload(
|
9
|
-
:OperationTreeBuilders,
|
10
|
-
"super_diff/active_record/operation_tree_builders"
|
11
|
-
)
|
12
|
-
autoload(
|
13
|
-
:OperationTreeFlatteners,
|
14
|
-
"super_diff/active_record/operation_tree_flatteners"
|
15
|
-
)
|
11
|
+
autoload :ObjectInspection, "super_diff/active_record/object_inspection"
|
16
12
|
|
17
13
|
SuperDiff.configure do |config|
|
18
|
-
config.
|
19
|
-
config.
|
14
|
+
config.prepend_extra_differ_classes(Differs::ActiveRecordRelation)
|
15
|
+
config.prepend_extra_operation_tree_builder_classes(
|
20
16
|
OperationTreeBuilders::ActiveRecordModel,
|
21
17
|
OperationTreeBuilders::ActiveRecordRelation
|
22
18
|
)
|
23
|
-
config.
|
24
|
-
|
25
|
-
|
19
|
+
config.prepend_extra_inspection_tree_builder_classes(
|
20
|
+
InspectionTreeBuilders::ActiveRecordModel,
|
21
|
+
InspectionTreeBuilders::ActiveRecordRelation
|
26
22
|
)
|
27
23
|
end
|
28
24
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveSupport
|
3
3
|
module Differs
|
4
|
-
class HashWithIndifferentAccess <
|
4
|
+
class HashWithIndifferentAccess < Basic::Differs::Hash
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
(
|
7
7
|
expected.is_a?(::HashWithIndifferentAccess) && actual.is_a?(::Hash)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveSupport
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class HashWithIndifferentAccess < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::HashWithIndifferentAccess)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
|
+
# stree-ignore
|
12
|
+
t1.as_lines_when_rendering_to_lines(
|
13
|
+
collection_bookend: :open
|
14
|
+
) do |t2|
|
15
|
+
t2.add_text "#<HashWithIndifferentAccess {"
|
16
|
+
end
|
17
|
+
|
18
|
+
# stree-ignore
|
19
|
+
t1.when_rendering_to_string do |t2|
|
20
|
+
t2.add_text " "
|
21
|
+
end
|
22
|
+
|
23
|
+
# stree-ignore
|
24
|
+
t1.nested do |t2|
|
25
|
+
t2.insert_hash_inspection_of(object)
|
26
|
+
end
|
27
|
+
|
28
|
+
# stree-ignore
|
29
|
+
t1.when_rendering_to_string do |t2|
|
30
|
+
t2.add_text " "
|
31
|
+
end
|
32
|
+
|
33
|
+
# stree-ignore
|
34
|
+
t1.as_lines_when_rendering_to_lines(
|
35
|
+
collection_bookend: :close
|
36
|
+
) do |t2|
|
37
|
+
t2.add_text "}>"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveSupport
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class OrderedOptions < Basic::InspectionTreeBuilders::Hash
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::ActiveSupport::OrderedOptions)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
|
+
# stree-ignore
|
12
|
+
t1.as_lines_when_rendering_to_lines(
|
13
|
+
collection_bookend: :open
|
14
|
+
) do |t2|
|
15
|
+
t2.add_text "#<OrderedOptions {"
|
16
|
+
end
|
17
|
+
|
18
|
+
# stree-ignore
|
19
|
+
t1.when_rendering_to_string do |t2|
|
20
|
+
t2.add_text " "
|
21
|
+
end
|
22
|
+
|
23
|
+
# stree-ignore
|
24
|
+
t1.nested do |t2|
|
25
|
+
t2.insert_hash_inspection_of(object.to_hash)
|
26
|
+
end
|
27
|
+
|
28
|
+
# stree-ignore
|
29
|
+
t1.when_rendering_to_string do |t2|
|
30
|
+
t2.add_text " "
|
31
|
+
end
|
32
|
+
|
33
|
+
# stree-ignore
|
34
|
+
t1.as_lines_when_rendering_to_lines(
|
35
|
+
collection_bookend: :close
|
36
|
+
) do |t2|
|
37
|
+
t2.add_text "}>"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveSupport
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
autoload(
|
5
|
+
:HashWithIndifferentAccess,
|
6
|
+
"super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access"
|
7
|
+
)
|
8
|
+
autoload(
|
9
|
+
:OrderedOptions,
|
10
|
+
"super_diff/active_support/inspection_tree_builders/ordered_options"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,10 +1,22 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveSupport
|
3
3
|
module ObjectInspection
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
def self.const_missing(missing_const_name)
|
6
|
+
if ActiveSupport::InspectionTreeBuilders.const_defined?(
|
7
|
+
missing_const_name
|
8
|
+
)
|
9
|
+
warn <<~EOT
|
10
|
+
WARNING: SuperDiff::ActiveSupport::ObjectInspection::InspectionTreeBuilders::#{missing_const_name} is deprecated and will be removed in the next major release.
|
11
|
+
Please use SuperDiff::ActiveSupport::InspectionTreeBuilders::#{missing_const_name} instead.
|
12
|
+
#{caller_locations.join("\n")}
|
13
|
+
EOT
|
14
|
+
ActiveSupport::InspectionTreeBuilders.const_get(missing_const_name)
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
end
|
10
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveSupport
|
3
3
|
module OperationTreeBuilders
|
4
|
-
class HashWithIndifferentAccess <
|
4
|
+
class HashWithIndifferentAccess < Basic::OperationTreeBuilders::Hash
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
(
|
7
7
|
expected.is_a?(::HashWithIndifferentAccess) && actual.is_a?(::Hash)
|