super_diff 0.1.0 → 0.2.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 +117 -89
- data/lib/super_diff.rb +33 -47
- data/lib/super_diff/active_record.rb +41 -0
- data/lib/super_diff/active_record/diff_formatters.rb +10 -0
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +23 -0
- data/lib/super_diff/active_record/differs.rb +10 -0
- data/lib/super_diff/active_record/differs/active_record_relation.rb +30 -0
- data/lib/super_diff/active_record/object_inspection.rb +14 -0
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +16 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +38 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +18 -0
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +18 -0
- data/lib/super_diff/active_record/operation_sequences.rb +10 -0
- data/lib/super_diff/active_record/operation_sequences/active_record_relation.rb +16 -0
- data/lib/super_diff/active_record/operational_sequencers.rb +14 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_model.rb +19 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_relation.rb +24 -0
- data/lib/super_diff/active_support.rb +33 -0
- data/lib/super_diff/active_support/diff_formatters.rb +10 -0
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/differs.rb +10 -0
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/object_inspection.rb +14 -0
- data/lib/super_diff/active_support/object_inspection/inspectors.rb +12 -0
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +18 -0
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +15 -0
- data/lib/super_diff/active_support/operation_sequences.rb +10 -0
- data/lib/super_diff/active_support/operation_sequences/hash_with_indifferent_access.rb +16 -0
- data/lib/super_diff/active_support/operational_sequencers.rb +10 -0
- data/lib/super_diff/active_support/operational_sequencers/hash_with_indifferent_access.rb +21 -0
- data/lib/super_diff/colorized_document_extensions.rb +17 -0
- data/lib/super_diff/csi.rb +45 -15
- data/lib/super_diff/csi/bold_sequence.rb +9 -0
- data/lib/super_diff/csi/color.rb +62 -0
- data/lib/super_diff/csi/color_sequence_block.rb +28 -0
- data/lib/super_diff/csi/colorized_document.rb +72 -0
- data/lib/super_diff/csi/document.rb +183 -0
- data/lib/super_diff/csi/eight_bit_color.rb +72 -26
- data/lib/super_diff/csi/four_bit_color.rb +63 -29
- data/lib/super_diff/csi/twenty_four_bit_color.rb +79 -18
- data/lib/super_diff/csi/uncolorized_document.rb +29 -0
- data/lib/super_diff/diff_formatter.rb +10 -15
- data/lib/super_diff/diff_formatters.rb +10 -1
- data/lib/super_diff/diff_formatters/base.rb +12 -17
- data/lib/super_diff/diff_formatters/collection.rb +81 -50
- data/lib/super_diff/diff_formatters/{object.rb → custom_object.rb} +12 -9
- data/lib/super_diff/diff_formatters/default_object.rb +48 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +31 -0
- data/lib/super_diff/differ.rb +35 -32
- data/lib/super_diff/differs.rb +16 -1
- data/lib/super_diff/differs/array.rb +2 -2
- data/lib/super_diff/differs/base.rb +11 -21
- data/lib/super_diff/differs/custom_object.rb +26 -0
- data/lib/super_diff/differs/default_object.rb +25 -0
- data/lib/super_diff/differs/empty.rb +1 -1
- data/lib/super_diff/differs/hash.rb +2 -2
- data/lib/super_diff/differs/{multi_line_string.rb → multiline_string.rb} +6 -5
- data/lib/super_diff/equality_matcher.rb +9 -22
- data/lib/super_diff/equality_matchers.rb +19 -1
- data/lib/super_diff/equality_matchers/array.rb +6 -4
- data/lib/super_diff/equality_matchers/base.rb +8 -16
- data/lib/super_diff/equality_matchers/default.rb +60 -0
- data/lib/super_diff/equality_matchers/hash.rb +6 -4
- data/lib/super_diff/equality_matchers/{multi_line_string.rb → multiline_string.rb} +9 -6
- data/lib/super_diff/equality_matchers/primitive.rb +34 -0
- data/lib/super_diff/equality_matchers/{single_line_string.rb → singleline_string.rb} +7 -5
- data/lib/super_diff/helpers.rb +17 -81
- data/lib/super_diff/no_differ_available_error.rb +22 -0
- data/lib/super_diff/{errors.rb → no_operational_sequencer_available_error.rb} +0 -0
- data/lib/super_diff/object_inspection.rb +24 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +144 -0
- data/lib/super_diff/object_inspection/inspector.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors.rb +18 -0
- data/lib/super_diff/object_inspection/inspectors/array.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +47 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/object_inspection/inspectors/string.rb +13 -0
- data/lib/super_diff/object_inspection/map.rb +28 -0
- data/lib/super_diff/object_inspection/nodes.rb +49 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +86 -0
- data/lib/super_diff/object_inspection/nodes/break.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +22 -0
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +24 -0
- data/lib/super_diff/operation_sequences.rb +9 -0
- data/lib/super_diff/operation_sequences/base.rb +1 -1
- data/lib/super_diff/operation_sequences/{object.rb → custom_object.rb} +4 -3
- data/lib/super_diff/operation_sequences/default_object.rb +25 -0
- data/lib/super_diff/operational_sequencer.rb +23 -18
- data/lib/super_diff/operational_sequencers.rb +12 -1
- data/lib/super_diff/operational_sequencers/array.rb +65 -62
- data/lib/super_diff/operational_sequencers/base.rb +18 -26
- data/lib/super_diff/operational_sequencers/custom_object.rb +35 -0
- data/lib/super_diff/operational_sequencers/{object.rb → default_object.rb} +21 -11
- data/lib/super_diff/operational_sequencers/hash.rb +8 -5
- data/lib/super_diff/operational_sequencers/{multi_line_string.rb → multiline_string.rb} +11 -6
- data/lib/super_diff/operations.rb +6 -0
- data/lib/super_diff/operations/binary_operation.rb +14 -34
- data/lib/super_diff/operations/unary_operation.rb +11 -2
- data/lib/super_diff/rails.rb +1 -0
- data/lib/super_diff/recursion_guard.rb +47 -0
- data/lib/super_diff/rspec-rails.rb +2 -0
- data/lib/super_diff/rspec.rb +52 -8
- data/lib/super_diff/rspec/augmented_matcher.rb +98 -0
- data/lib/super_diff/rspec/configuration.rb +31 -0
- data/lib/super_diff/rspec/differ.rb +60 -16
- data/lib/super_diff/rspec/differs.rb +13 -0
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +23 -0
- data/lib/super_diff/rspec/differs/partial_array.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_hash.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_object.rb +22 -0
- data/lib/super_diff/rspec/matcher_text_builders.rb +24 -0
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +155 -0
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +78 -0
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +14 -0
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +23 -0
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -0
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +99 -0
- data/lib/super_diff/rspec/matcher_text_template.rb +240 -0
- data/lib/super_diff/rspec/monkey_patches.rb +601 -98
- data/lib/super_diff/rspec/object_inspection.rb +8 -0
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +24 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +22 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers.rb +22 -0
- data/lib/super_diff/rspec/operational_sequencers/collection_containing_exactly.rb +97 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_array.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +32 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_object.rb +64 -0
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +328 -46
- data/spec/integration/rails/active_record_spec.rb +19 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_matcher_spec.rb +565 -0
- data/spec/integration/rspec/be_nil_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +546 -0
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +57 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +368 -0
- data/spec/integration/rspec/eq_matcher_spec.rb +874 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +299 -0
- data/spec/integration/rspec/include_matcher_spec.rb +350 -0
- data/spec/integration/rspec/match_matcher_spec.rb +1258 -0
- data/spec/integration/rspec/raise_error_matcher_spec.rb +350 -0
- data/spec/integration/rspec/respond_to_matcher_spec.rb +994 -0
- data/spec/integration/rspec/unhandled_errors_spec.rb +94 -0
- data/spec/spec_helper.rb +19 -4
- data/spec/support/colorizer.rb +9 -0
- data/spec/support/command_runner.rb +4 -0
- data/spec/support/integration/helpers.rb +179 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +79 -41
- data/spec/support/models/a.rb +11 -0
- data/spec/support/models/active_record/person.rb +26 -0
- data/spec/support/models/active_record/shipping_address.rb +29 -0
- data/spec/support/models/customer.rb +24 -0
- data/spec/support/models/empty_class.rb +6 -0
- data/spec/support/models/item.rb +10 -0
- data/spec/support/models/order.rb +9 -0
- data/spec/support/models/person.rb +20 -0
- data/spec/support/models/player.rb +33 -0
- data/spec/support/models/shipping_address.rb +34 -0
- data/spec/support/ruby_versions.rb +7 -0
- data/spec/support/shared_examples/active_record.rb +338 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +233 -0
- data/spec/unit/equality_matcher_spec.rb +579 -171
- data/spec/unit/object_inspection_spec.rb +1092 -0
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +23 -0
- data/spec/unit/rspec/matchers/be_falsey_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_nil_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +31 -0
- data/spec/unit/rspec/matchers/be_spec.rb +17 -0
- data/spec/unit/rspec/matchers/be_truthy_spec.rb +9 -0
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +11 -0
- data/spec/unit/rspec/matchers/eq_spec.rb +9 -0
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +11 -0
- data/spec/unit/rspec/matchers/include_spec.rb +21 -0
- data/spec/unit/rspec/matchers/match_spec.rb +9 -0
- data/spec/unit/rspec/matchers/raise_error_spec.rb +29 -0
- data/spec/unit/rspec/matchers/respond_to_spec.rb +78 -0
- data/super_diff.gemspec +4 -2
- metadata +231 -34
- data/lib/super_diff/csi/color_helper.rb +0 -52
- data/lib/super_diff/csi/eight_bit_sequence.rb +0 -27
- data/lib/super_diff/csi/four_bit_sequence.rb +0 -24
- data/lib/super_diff/csi/sequence.rb +0 -22
- data/lib/super_diff/csi/twenty_four_bit_sequence.rb +0 -27
- data/lib/super_diff/diff_formatters/multi_line_string.rb +0 -31
- data/lib/super_diff/differs/object.rb +0 -68
- data/lib/super_diff/equality_matchers/object.rb +0 -18
- data/lib/super_diff/value_inspection.rb +0 -11
- data/spec/integration/rspec_spec.rb +0 -261
- data/spec/support/color_helper.rb +0 -49
- data/spec/support/person.rb +0 -23
- data/spec/support/person_diff_formatter.rb +0 -15
- data/spec/support/person_operation_sequence.rb +0 -14
- data/spec/support/person_operational_sequencer.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a490a3241bf9e0d7c6086d13d1b60b02054839edbcf3bd1516db488cafab1449
|
4
|
+
data.tar.gz: da592d721f010fefa021348aefa832e05c07cecc4fdae7588c6bcb4696e45263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0df2d46d7863e1cae93aa6f1760b4de7b45d34a333570a82ef39278bfd7b49ea8d2dd4d21e3d19dfdd427ffd42486a32c96400cf3755c196382358ed638d06ec
|
7
|
+
data.tar.gz: d86b0ac244443fa75f3ab51c6377818dc942bc9fe2b44b14be78a9595da9267e94b20cd0571cde296ef140ad4fd81f915656330e45c3429c256c13e6298ab932
|
data/README.md
CHANGED
@@ -3,158 +3,161 @@
|
|
3
3
|
[version-badge]: http://img.shields.io/gem/v/super_diff.svg
|
4
4
|
[rubygems]: http://rubygems.org/gems/super_diff
|
5
5
|
[travis-badge]: http://img.shields.io/travis/mcmire/super_diff/master.svg
|
6
|
-
[travis]: http://travis-ci.org/mcmire/super_diff
|
7
6
|
[downloads-badge]: http://img.shields.io/gem/dtv/super_diff.svg
|
8
7
|
[hound-badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
|
9
8
|
[hound]: https://houndci.com
|
10
9
|
|
11
|
-
|
10
|
+
SuperDiff is a Ruby gem that intelligently displays the differences between two
|
11
|
+
data structures of any type.
|
12
|
+
|
13
|
+
📢 **[See what's changed in the latest version (0.2.0)][changelog].**
|
14
|
+
|
15
|
+
[changelog]: CHANGELOG.md
|
12
16
|
|
13
|
-
|
14
|
-
and gives you helpful output to show you exactly how the two data structures
|
15
|
-
differ.
|
17
|
+
## Introduction
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
The primary motivation behind this gem is to replace RSpec's built-in diffing
|
20
|
+
capabilities. Sometimes, whenever you use a matcher such as `eq`, `match`,
|
21
|
+
`include`, or `have_attributes`, you will get a diff of the two data structures
|
22
|
+
you are trying to match against. This is really helpful for strings, but not so
|
23
|
+
helpful for other, more "real world" kinds of values, such as arrays, hashes,
|
24
|
+
and full-scale objects. The reason this doesn't work is because [all RSpec does
|
25
|
+
is run your `expected` and `actual` values through Ruby's PrettyPrinter
|
26
|
+
library][rspec-differ-fail] and then perform a diff of these strings.
|
27
|
+
|
28
|
+
For instance, let's say you wanted to compare these two hashes:
|
19
29
|
|
20
30
|
``` ruby
|
21
|
-
|
31
|
+
actual = {
|
22
32
|
customer: {
|
23
|
-
name: "Marty McFly",
|
33
|
+
person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
|
24
34
|
shipping_address: {
|
25
|
-
line_1: "
|
35
|
+
line_1: "456 Ponderosa Ct.",
|
26
36
|
city: "Hill Valley",
|
27
37
|
state: "CA",
|
28
|
-
zip: "90382"
|
29
|
-
}
|
38
|
+
zip: "90382"
|
39
|
+
}
|
30
40
|
},
|
31
41
|
items: [
|
32
42
|
{
|
33
43
|
name: "Fender Stratocaster",
|
34
44
|
cost: 100_000,
|
35
|
-
options: ["red", "blue", "green"]
|
45
|
+
options: ["red", "blue", "green"]
|
36
46
|
},
|
37
|
-
{ name: "
|
38
|
-
]
|
47
|
+
{ name: "Mattel Hoverboard" }
|
48
|
+
]
|
39
49
|
}
|
40
|
-
```
|
41
|
-
|
42
|
-
and your second hash looks like this:
|
43
50
|
|
44
|
-
|
45
|
-
actual = {
|
51
|
+
expected = {
|
46
52
|
customer: {
|
47
|
-
name: "Marty McFly,
|
53
|
+
person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
|
48
54
|
shipping_address: {
|
49
|
-
line_1: "
|
55
|
+
line_1: "123 Main St.",
|
50
56
|
city: "Hill Valley",
|
51
57
|
state: "CA",
|
52
|
-
zip: "90382"
|
53
|
-
}
|
58
|
+
zip: "90382"
|
59
|
+
}
|
54
60
|
},
|
55
61
|
items: [
|
56
62
|
{
|
57
63
|
name: "Fender Stratocaster",
|
58
64
|
cost: 100_000,
|
59
|
-
options: ["red", "blue", "green"]
|
65
|
+
options: ["red", "blue", "green"]
|
60
66
|
},
|
61
|
-
{ name: "
|
62
|
-
]
|
67
|
+
{ name: "Chevy 4x4" }
|
68
|
+
]
|
63
69
|
}
|
64
70
|
```
|
65
71
|
|
66
|
-
If
|
72
|
+
If, somewhere in a test, you were to say:
|
67
73
|
|
68
74
|
``` ruby
|
69
|
-
|
75
|
+
expect(actual).to eq(expected)
|
70
76
|
```
|
71
77
|
|
72
|
-
|
78
|
+
You would get output that looks like:
|
73
79
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
Expected: { customer: { name: "Marty McFly", shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }
|
78
|
-
Got: { customer: { name: "Marty McFly, Jr.", shipping_address: { line_1: "456 Ponderosa Ct.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Mattel Hoverboard" }] }
|
79
|
-
|
80
|
-
Diff:
|
81
|
-
|
82
|
-
{
|
83
|
-
customer: {
|
84
|
-
- name: "Marty McFly",
|
85
|
-
+ name: "Marty McFly, Jr.",
|
86
|
-
shipping_address: {
|
87
|
-
- line_1: "123 Main St.",
|
88
|
-
+ line_1: "456 Ponderosa Ct.",
|
89
|
-
city: "Hill Valley",
|
90
|
-
state: "CA",
|
91
|
-
zip: "90382"
|
92
|
-
}
|
93
|
-
},
|
94
|
-
items: [
|
95
|
-
{
|
96
|
-
name: "Fender Stratocaster",
|
97
|
-
cost: 100000,
|
98
|
-
options: ["red", "blue", "green"]
|
99
|
-
},
|
100
|
-
{
|
101
|
-
- name: "Chevy 4x4"
|
102
|
-
+ name: "Mattel Hoverboard"
|
103
|
-
}
|
104
|
-
]
|
105
|
-
}
|
106
|
-
```
|
80
|
+

|
81
|
+
|
82
|
+
Not great.
|
107
83
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
green.
|
84
|
+
This library provides a diff engine that knows how to figure out the differences
|
85
|
+
between any two data structures and display them in a sensible way. Using the
|
86
|
+
example above, you'd get this instead:
|
112
87
|
|
113
|
-
|
114
|
-
objects, too!
|
88
|
+

|
115
89
|
|
116
|
-
|
90
|
+
[rspec-differ-fail]: https://github.com/rspec/rspec-support/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
|
117
91
|
|
118
|
-
|
119
|
-
gem provides, such as the method presented above.
|
92
|
+
## Installation
|
120
93
|
|
121
|
-
|
122
|
-
|
123
|
-
and your test fails, you will see a diff between those objects (provided the
|
124
|
-
objects are large enough). However, this diff is not always the most helpful.
|
125
|
-
It's very common when writing tests for API endpoints to work with giant JSON
|
126
|
-
hashes, and RSpec's diffs are not sufficient in highlighting changes between
|
127
|
-
such structures. Therefore, this gem provides an integration layer where you can
|
128
|
-
replace RSpec's differ with SuperDiff.
|
94
|
+
Want to try out this gem for yourself? As with most development-related gems,
|
95
|
+
there are a couple ways depending on your type of project:
|
129
96
|
|
130
|
-
|
97
|
+
### Rails apps
|
98
|
+
|
99
|
+
If you're developing a Rails app, add the following to your Gemfile:
|
131
100
|
|
132
101
|
``` ruby
|
133
102
|
gem "super_diff"
|
134
103
|
```
|
135
104
|
|
136
|
-
|
105
|
+
After running `bundle install`, add the following to your `rails_helper`:
|
106
|
+
|
107
|
+
``` ruby
|
108
|
+
require "super_diff/rspec-rails"
|
109
|
+
```
|
110
|
+
|
111
|
+
You're done!
|
112
|
+
|
113
|
+
### Libraries
|
114
|
+
|
115
|
+
If you're developing a library, add the following to your gemspec:
|
116
|
+
|
117
|
+
``` ruby
|
118
|
+
spec.add_development_dependency "super_diff"
|
119
|
+
```
|
120
|
+
|
121
|
+
Now add the following to your `spec_helper`:
|
137
122
|
|
138
123
|
``` ruby
|
139
124
|
require "super_diff/rspec"
|
140
125
|
```
|
141
126
|
|
142
|
-
|
143
|
-
|
127
|
+
You're done!
|
128
|
+
|
129
|
+
## Configuration
|
130
|
+
|
131
|
+
As capable as this library is, it doesn't know how to deal with every kind of
|
132
|
+
object out there. You might find it necessary to instruct the gem on how to diff
|
133
|
+
your object. To do this, you can use a configuration block. Simply add this to
|
134
|
+
your test helper file (either `rails_helper` or `spec_helper`):
|
135
|
+
|
136
|
+
``` ruby
|
137
|
+
SuperDiff::RSpec.configure do |config|
|
138
|
+
config.add_extra_differ_class(YourDiffer)
|
139
|
+
config.add_extra_operational_sequencer_class(YourOperationalSequencer)
|
140
|
+
config.add_extra_diff_formatter_class(YourDiffFormatter)
|
141
|
+
end
|
142
|
+
```
|
143
|
+
|
144
|
+
*(More info here in the future on adding a custom differ, operational sequencer,
|
145
|
+
and diff formatter. Also explanations on what these are.)*
|
144
146
|
|
145
147
|
## Contributing
|
146
148
|
|
147
|
-
If you encounter a bug or have an idea for how this could be better,
|
148
|
-
|
149
|
+
If you encounter a bug or have an idea for how this could be better, feel free
|
150
|
+
to [create an issue](https://github.com/mcmire/super_diff/issues).
|
149
151
|
|
150
152
|
If you'd like to submit a PR instead, here's how to get started. First, fork
|
151
|
-
this repo
|
153
|
+
this repo. Then, when you've cloned your fork, run:
|
152
154
|
|
153
155
|
```
|
154
156
|
bundle install
|
155
157
|
```
|
156
158
|
|
157
|
-
This will install dependencies.
|
159
|
+
This will install various dependencies. After this, you can run all of the
|
160
|
+
tests:
|
158
161
|
|
159
162
|
```
|
160
163
|
bundle exec rake
|
@@ -169,6 +172,31 @@ bundle exec rspec spec/unit/...
|
|
169
172
|
|
170
173
|
Finally, submit your PR and I'll take a look at it when I get a chance.
|
171
174
|
|
175
|
+
## Compatibility
|
176
|
+
|
177
|
+
`super_diff` is [tested][travis] to work with Ruby >= 2.4.x, RSpec 3.x, and
|
178
|
+
Rails >= 5.x.
|
179
|
+
|
180
|
+
[travis]: http://travis-ci.org/mcmire/super_diff
|
181
|
+
|
182
|
+
## Inspiration/Thanks
|
183
|
+
|
184
|
+
In developing this gem I made use of or was heavily inspired by these libraries:
|
185
|
+
|
186
|
+
* [Diff::LCS][diff-lcs], the library I started with in the [original version of
|
187
|
+
this gem][original-version] (made in 2011!)
|
188
|
+
* The pretty-printing algorithms and API within [PrettyPrinter][pretty-printer]
|
189
|
+
and [AwesomePrint][awesome-print], from which I borrowed ideas to develop
|
190
|
+
the [inspectors][inspection-tree].
|
191
|
+
|
192
|
+
Thank you so much!
|
193
|
+
|
194
|
+
[original-version]: https://github.com/mcmire/super_diff/tree/old-master
|
195
|
+
[diff-lcs]: https://github.com/halostatue/diff-lcs
|
196
|
+
[pretty-printer]: https://github.com/ruby/ruby/tree/master/lib/prettyprint.rb
|
197
|
+
[awesome-print]: https://github.com/awesome-print/awesome_print
|
198
|
+
[inspection-tree]: https://github.com/mcmire/super_diff/blob/master/lib/super_diff/object_inspection/inspection_tree.rb
|
199
|
+
|
172
200
|
## Copyright/License
|
173
201
|
|
174
|
-
© 2018 Elliot Winkler, released under the [MIT license](LICENSE).
|
202
|
+
© 2018-2019 Elliot Winkler, released under the [MIT license](LICENSE).
|
data/lib/super_diff.rb
CHANGED
@@ -1,50 +1,36 @@
|
|
1
|
-
require "
|
1
|
+
require "attr_extras/explicit"
|
2
2
|
require "diff-lcs"
|
3
|
+
require "patience_diff"
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
require_relative "super_diff/operational_sequencers/hash"
|
29
|
-
require_relative "super_diff/operational_sequencers/multi_line_string"
|
30
|
-
require_relative "super_diff/operational_sequencers/object"
|
31
|
-
require_relative "super_diff/operational_sequencers"
|
32
|
-
require_relative "super_diff/operational_sequencer"
|
33
|
-
|
34
|
-
require_relative "super_diff/diff_formatters/collection"
|
35
|
-
require_relative "super_diff/diff_formatters/base"
|
36
|
-
require_relative "super_diff/diff_formatters/array"
|
37
|
-
require_relative "super_diff/diff_formatters/hash"
|
38
|
-
require_relative "super_diff/diff_formatters/multi_line_string"
|
39
|
-
require_relative "super_diff/diff_formatters/object"
|
40
|
-
require_relative "super_diff/diff_formatters"
|
41
|
-
require_relative "super_diff/diff_formatter"
|
5
|
+
module SuperDiff
|
6
|
+
autoload(
|
7
|
+
:ColorizedDocumentExtensions,
|
8
|
+
"super_diff/colorized_document_extensions",
|
9
|
+
)
|
10
|
+
autoload :Csi, "super_diff/csi"
|
11
|
+
autoload :DiffFormatter, "super_diff/diff_formatter"
|
12
|
+
autoload :DiffFormatters, "super_diff/diff_formatters"
|
13
|
+
autoload :Differ, "super_diff/differ"
|
14
|
+
autoload :Differs, "super_diff/differs"
|
15
|
+
autoload :EqualityMatcher, "super_diff/equality_matcher"
|
16
|
+
autoload :EqualityMatchers, "super_diff/equality_matchers"
|
17
|
+
autoload :Helpers, "super_diff/helpers"
|
18
|
+
autoload :NoDifferAvailableError, "super_diff/no_differ_available_error"
|
19
|
+
autoload(
|
20
|
+
:NoOperationalSequencerAvailableError,
|
21
|
+
"super_diff/no_operational_sequencer_available_error",
|
22
|
+
)
|
23
|
+
autoload :ObjectInspection, "super_diff/object_inspection"
|
24
|
+
autoload :OperationalSequencer, "super_diff/operational_sequencer"
|
25
|
+
autoload :OperationalSequencers, "super_diff/operational_sequencers"
|
26
|
+
autoload :OperationSequences, "super_diff/operation_sequences"
|
27
|
+
autoload :Operations, "super_diff/operations"
|
28
|
+
autoload :RecursionGuard, "super_diff/recursion_guard"
|
42
29
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
require_relative "super_diff/differ"
|
30
|
+
COLORS = {
|
31
|
+
alpha: :magenta,
|
32
|
+
beta: :yellow,
|
33
|
+
border: :blue,
|
34
|
+
header: :white,
|
35
|
+
}.freeze
|
36
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "super_diff/active_support"
|
2
|
+
|
3
|
+
module SuperDiff
|
4
|
+
module ActiveRecord
|
5
|
+
autoload :DiffFormatters, "super_diff/active_record/diff_formatters"
|
6
|
+
autoload :Differs, "super_diff/active_record/differs"
|
7
|
+
autoload(
|
8
|
+
:ObjectInspection,
|
9
|
+
"super_diff/active_record/object_inspection",
|
10
|
+
)
|
11
|
+
autoload(
|
12
|
+
:OperationSequences,
|
13
|
+
"super_diff/active_record/operation_sequences",
|
14
|
+
)
|
15
|
+
autoload(
|
16
|
+
:OperationalSequencers,
|
17
|
+
"super_diff/active_record/operational_sequencers",
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if defined?(SuperDiff::RSpec)
|
23
|
+
SuperDiff::RSpec.configure do |config|
|
24
|
+
config.add_extra_differ_class(
|
25
|
+
SuperDiff::ActiveRecord::Differs::ActiveRecordRelation,
|
26
|
+
)
|
27
|
+
config.add_extra_operational_sequencer_class(
|
28
|
+
SuperDiff::ActiveRecord::OperationalSequencers::ActiveRecordModel,
|
29
|
+
)
|
30
|
+
config.add_extra_operational_sequencer_class(
|
31
|
+
SuperDiff::ActiveRecord::OperationalSequencers::ActiveRecordRelation,
|
32
|
+
)
|
33
|
+
config.add_extra_diff_formatter_class(
|
34
|
+
SuperDiff::ActiveRecord::DiffFormatters::ActiveRecordRelation,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
SuperDiff::ObjectInspection.map.prepend(
|
40
|
+
SuperDiff::ActiveRecord::ObjectInspection::MapExtension,
|
41
|
+
)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveRecord
|
3
|
+
module DiffFormatters
|
4
|
+
class ActiveRecordRelation < SuperDiff::DiffFormatters::Base
|
5
|
+
def self.applies_to?(operations)
|
6
|
+
operations.is_a?(OperationSequences::ActiveRecordRelation)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
SuperDiff::DiffFormatters::Collection.call(
|
11
|
+
open_token: "#<ActiveRecord::Relation [",
|
12
|
+
close_token: "]>",
|
13
|
+
collection_prefix: collection_prefix,
|
14
|
+
build_item_prefix: proc { "" },
|
15
|
+
operations: operations,
|
16
|
+
indent_level: indent_level,
|
17
|
+
add_comma: add_comma?,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|