super_diff 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +108 -74
  3. data/lib/super_diff.rb +20 -11
  4. data/lib/super_diff/active_record.rb +21 -23
  5. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
  6. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
  7. data/lib/super_diff/active_record/monkey_patches.rb +9 -0
  8. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
  9. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
  10. data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
  11. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
  12. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
  13. data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
  14. data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
  15. data/lib/super_diff/active_support.rb +16 -19
  16. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
  17. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
  18. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
  19. data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
  20. data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
  21. data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
  22. data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
  23. data/lib/super_diff/configuration.rb +60 -0
  24. data/lib/super_diff/csi.rb +4 -0
  25. data/lib/super_diff/diff_formatters.rb +3 -3
  26. data/lib/super_diff/diff_formatters/array.rb +3 -3
  27. data/lib/super_diff/diff_formatters/base.rb +3 -2
  28. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  29. data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
  30. data/lib/super_diff/diff_formatters/default_object.rb +6 -8
  31. data/lib/super_diff/diff_formatters/defaults.rb +10 -0
  32. data/lib/super_diff/diff_formatters/hash.rb +3 -3
  33. data/lib/super_diff/diff_formatters/main.rb +41 -0
  34. data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
  35. data/lib/super_diff/differs.rb +4 -9
  36. data/lib/super_diff/differs/array.rb +2 -11
  37. data/lib/super_diff/differs/base.rb +20 -3
  38. data/lib/super_diff/differs/custom_object.rb +2 -11
  39. data/lib/super_diff/differs/default_object.rb +2 -8
  40. data/lib/super_diff/differs/defaults.rb +12 -0
  41. data/lib/super_diff/differs/hash.rb +2 -11
  42. data/lib/super_diff/differs/main.rb +48 -0
  43. data/lib/super_diff/differs/multiline_string.rb +2 -14
  44. data/lib/super_diff/differs/time_like.rb +15 -0
  45. data/lib/super_diff/equality_matchers.rb +3 -9
  46. data/lib/super_diff/equality_matchers/array.rb +1 -7
  47. data/lib/super_diff/equality_matchers/base.rb +1 -1
  48. data/lib/super_diff/equality_matchers/default.rb +2 -8
  49. data/lib/super_diff/equality_matchers/defaults.rb +12 -0
  50. data/lib/super_diff/equality_matchers/hash.rb +1 -7
  51. data/lib/super_diff/equality_matchers/main.rb +21 -0
  52. data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
  53. data/lib/super_diff/errors.rb +16 -0
  54. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
  55. data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
  56. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
  57. data/lib/super_diff/implementation_checks.rb +19 -0
  58. data/lib/super_diff/object_inspection.rb +1 -10
  59. data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
  60. data/lib/super_diff/object_inspection/inspectors.rb +5 -0
  61. data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
  62. data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
  63. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
  64. data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
  65. data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
  66. data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
  67. data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
  68. data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
  69. data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
  70. data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
  72. data/lib/super_diff/operation_tree_builders.rb +18 -0
  73. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
  74. data/lib/super_diff/operation_tree_builders/base.rb +98 -0
  75. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
  76. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
  78. data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
  79. data/lib/super_diff/operation_tree_builders/main.rb +42 -0
  80. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
  82. data/lib/super_diff/operation_trees.rb +13 -0
  83. data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
  84. data/lib/super_diff/operation_trees/base.rb +31 -0
  85. data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
  86. data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
  87. data/lib/super_diff/operation_trees/defaults.rb +5 -0
  88. data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
  89. data/lib/super_diff/operation_trees/main.rb +35 -0
  90. data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
  91. data/lib/super_diff/operations/unary_operation.rb +3 -0
  92. data/lib/super_diff/rspec.rb +54 -22
  93. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  94. data/lib/super_diff/rspec/differ.rb +2 -17
  95. data/lib/super_diff/rspec/differs.rb +9 -3
  96. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
  97. data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
  98. data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
  99. data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
  100. data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
  101. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
  102. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
  103. data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
  104. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
  106. data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
  107. data/lib/super_diff/rspec/monkey_patches.rb +226 -115
  108. data/lib/super_diff/rspec/object_inspection.rb +0 -1
  109. data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
  110. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
  111. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
  112. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
  113. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
  114. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
  115. data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
  116. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
  117. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
  118. data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
  119. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
  120. data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
  121. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
  122. data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
  123. data/lib/super_diff/version.rb +1 -1
  124. data/spec/examples.txt +397 -328
  125. data/spec/integration/rails/active_record_spec.rb +1 -1
  126. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
  127. data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
  128. data/spec/integration/rspec/eq_matcher_spec.rb +139 -3
  129. data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  130. data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
  131. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  132. data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
  133. data/spec/integration/rspec/match_matcher_spec.rb +8 -8
  134. data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
  135. data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
  136. data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
  137. data/spec/spec_helper.rb +18 -7
  138. data/spec/support/command_runner.rb +3 -0
  139. data/spec/support/integration/helpers.rb +14 -90
  140. data/spec/support/integration/matchers.rb +143 -0
  141. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
  142. data/spec/support/integration/test_programs/base.rb +120 -0
  143. data/spec/support/integration/test_programs/plain.rb +13 -0
  144. data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
  145. data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
  146. data/spec/support/models/active_record/person.rb +4 -11
  147. data/spec/support/models/active_record/query.rb +15 -0
  148. data/spec/support/models/active_record/shipping_address.rb +10 -14
  149. data/spec/support/object_id.rb +27 -0
  150. data/spec/support/ruby_versions.rb +4 -0
  151. data/spec/support/shared_examples/active_record.rb +71 -0
  152. data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
  153. data/spec/tmp/integration_spec.rb +15 -0
  154. data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
  155. data/spec/unit/object_inspection_spec.rb +94 -18
  156. data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
  157. data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
  158. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  159. data/super_diff.gemspec +3 -6
  160. metadata +99 -91
  161. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  162. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  163. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  164. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  165. data/lib/super_diff/diff_formatter.rb +0 -32
  166. data/lib/super_diff/differ.rb +0 -51
  167. data/lib/super_diff/equality_matcher.rb +0 -32
  168. data/lib/super_diff/no_differ_available_error.rb +0 -22
  169. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  170. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  171. data/lib/super_diff/object_inspection/map.rb +0 -28
  172. data/lib/super_diff/operation_sequences.rb +0 -9
  173. data/lib/super_diff/operation_sequences/base.rb +0 -11
  174. data/lib/super_diff/operational_sequencer.rb +0 -48
  175. data/lib/super_diff/operational_sequencers.rb +0 -16
  176. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  177. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  178. data/lib/super_diff/rspec/configuration.rb +0 -31
  179. data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
  180. data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
  181. data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
  182. data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
  183. data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
  184. data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
  185. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  186. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
  187. data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a490a3241bf9e0d7c6086d13d1b60b02054839edbcf3bd1516db488cafab1449
4
- data.tar.gz: da592d721f010fefa021348aefa832e05c07cecc4fdae7588c6bcb4696e45263
3
+ metadata.gz: 31484b874ef6086f57dd96cf538d32692040bcfe20df0b5a03ffb2d37528e178
4
+ data.tar.gz: ffe9ee2546b907b77018edfc856b207384c111f8d59dcdae54c6148cf1cf6cec
5
5
  SHA512:
6
- metadata.gz: 0df2d46d7863e1cae93aa6f1760b4de7b45d34a333570a82ef39278bfd7b49ea8d2dd4d21e3d19dfdd427ffd42486a32c96400cf3755c196382358ed638d06ec
7
- data.tar.gz: d86b0ac244443fa75f3ab51c6377818dc942bc9fe2b44b14be78a9595da9267e94b20cd0571cde296ef140ad4fd81f915656330e45c3429c256c13e6298ab932
6
+ metadata.gz: 7f3a9f593e712569fac26dfc8ae395be685006d641576e317dfbc4aee773c506c833142b76f430b22e3089aa8ad2c8be3aabecb6d50992834db15e5ad4968fd0
7
+ data.tar.gz: b308ffce611c4bc457115247a9f1a5fb7bf310a78bc9a478fb5c99e6ca2d6fd40070013177d99e372554f0a25615278b094a262226c0460fcc127402aed27f71
data/README.md CHANGED
@@ -1,31 +1,40 @@
1
- # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] ![Downloads][downloads-badge] [![Hound][hound-badge]][hound]
1
+ # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] ![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
  [travis-badge]: http://img.shields.io/travis/mcmire/super_diff/master.svg
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
- SuperDiff is a Ruby gem that intelligently displays the differences between two
11
- data structures of any type.
11
+ SuperDiff is a gem that hooks into RSpec
12
+ to intelligently display the differences between two data structures of any type.
12
13
 
13
- 📢 **[See what's changed in the latest version (0.2.0)][changelog].**
14
+ 📢 **[See what's changed in the latest version (0.4.2)][changelog].**
14
15
 
15
16
  [changelog]: CHANGELOG.md
16
17
 
17
18
  ## Introduction
18
19
 
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.
20
+ The primary motivation behind this gem
21
+ is to vastly improve upon RSpec's built-in diffing capabilities.
27
22
 
28
- For instance, let's say you wanted to compare these two hashes:
23
+ Sometimes, whenever you use a matcher such as `eq`, `match`, `include`, or `have_attributes`,
24
+ you will get a diff of the two data structures you are trying to match against.
25
+ 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,
29
+ then you are out of luck.
30
+ Since [RSpec merely runs your `expected` and `actual` values through Ruby's PrettyPrinter library][rspec-differ-fail]
31
+ and then performs a diff of these strings,
32
+ the output it produces leaves much to be desired.
33
+
34
+ [rspec-differ-fail]: https://github.com/rspec/rspec-support/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
35
+
36
+ For instance,
37
+ let's say you wanted to compare these two hashes:
29
38
 
30
39
  ``` ruby
31
40
  actual = {
@@ -75,44 +84,64 @@ If, somewhere in a test, you were to say:
75
84
  expect(actual).to eq(expected)
76
85
  ```
77
86
 
78
- You would get output that looks like:
79
-
80
- ![Before super_diff](doc/before_super_diff.png)
87
+ You would get output that looks like this:
81
88
 
82
- Not great.
89
+ ![Before super_diff](docs/before.png)
83
90
 
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:
91
+ What this library does
92
+ is to provide a diff engine
93
+ that knows how to figure out the differences between any two data structures
94
+ and display them in a sensible way.
95
+ So, using the example above,
96
+ you'd get this instead:
87
97
 
88
- ![After super_diff](doc/after_super_diff.png)
89
-
90
- [rspec-differ-fail]: https://github.com/rspec/rspec-support/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
98
+ ![After super_diff](docs/after.png)
91
99
 
92
100
  ## Installation
93
101
 
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:
102
+ There are a few different ways to install `super_diff`
103
+ depending on your type of project.
96
104
 
97
105
  ### Rails apps
98
106
 
99
- If you're developing a Rails app, add the following to your Gemfile:
107
+ If you're developing a Rails app,
108
+ add the following to your Gemfile:
100
109
 
101
110
  ``` ruby
102
- gem "super_diff"
111
+ group :test do
112
+ gem "super_diff"
113
+ end
103
114
  ```
104
115
 
105
- After running `bundle install`, add the following to your `rails_helper`:
116
+ After running `bundle install`,
117
+ add the following to your `rails_helper`:
106
118
 
107
119
  ``` ruby
108
120
  require "super_diff/rspec-rails"
109
121
  ```
110
122
 
111
- You're done!
123
+ ### Projects using some part of Rails (e.g. ActiveModel)
112
124
 
113
- ### Libraries
125
+ If you're developing an app using Hanami or Sinatra,
126
+ or merely using a part of Rails such as ActiveModel,
127
+ add the following to your Gemfile where appropriate:
114
128
 
115
- If you're developing a library, add the following to your gemspec:
129
+ ``` ruby
130
+ gem "super_diff"
131
+ ```
132
+
133
+ After running `bundle install`,
134
+ add the following to your `spec_helper`:
135
+
136
+ ``` ruby
137
+ require "super_diff/rspec"
138
+ require "super_diff/active_support"
139
+ ```
140
+
141
+ ### Gems
142
+
143
+ If you're developing a gem,
144
+ add the following to your gemspec:
116
145
 
117
146
  ``` ruby
118
147
  spec.add_development_dependency "super_diff"
@@ -124,72 +153,76 @@ Now add the following to your `spec_helper`:
124
153
  require "super_diff/rspec"
125
154
  ```
126
155
 
127
- You're done!
128
-
129
156
  ## Configuration
130
157
 
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`):
158
+ As capable as this library is,
159
+ it doesn't know how to deal with every kind of object out there.
160
+ If you have a custom class,
161
+ and instances of your class aren't appearing in diffs like you like,
162
+ you might find it necessary to instruct the gem on how to handle them.
163
+ In that case
164
+ you would add something like this to your test helper file
165
+ (`rails_helper` or `spec_helper`):
135
166
 
136
167
  ``` ruby
137
- SuperDiff::RSpec.configure do |config|
168
+ SuperDiff.configure do |config|
138
169
  config.add_extra_differ_class(YourDiffer)
139
- config.add_extra_operational_sequencer_class(YourOperationalSequencer)
170
+ config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
171
+ config.add_extra_operation_tree_class(YourOperationTree)
140
172
  config.add_extra_diff_formatter_class(YourDiffFormatter)
141
173
  end
142
174
  ```
143
175
 
144
- *(More info here in the future on adding a custom differ, operational sequencer,
145
- and diff formatter. Also explanations on what these are.)*
146
-
147
- ## Contributing
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).
176
+ *(More info here in the future on adding a custom differ,
177
+ operation tree builder,
178
+ operation tree,
179
+ and diff formatter.
180
+ Also explanations on what these are.)*
151
181
 
152
- If you'd like to submit a PR instead, here's how to get started. First, fork
153
- this repo. Then, when you've cloned your fork, run:
182
+ ## Support
154
183
 
155
- ```
156
- bundle install
157
- ```
184
+ My goal for this library is to improve your development experience.
185
+ If this is not the case,
186
+ and you encounter a bug or have a suggestion,
187
+ feel free to [create an issue][issues-list].
188
+ I'll try to respond to it as soon as I can!
158
189
 
159
- This will install various dependencies. After this, you can run all of the
160
- tests:
190
+ [issues-list]: https://github.com/mcmire/super_diff/issues
161
191
 
162
- ```
163
- bundle exec rake
164
- ```
192
+ ## Contributing
165
193
 
166
- Or a single test:
194
+ Any code contributions to improve this library are welcome!
195
+ Please see the [contributing](./CONTRIBUTING.md) document for more on how to do that.
167
196
 
168
- ```
169
- bundle exec rspec spec/acceptance/...
170
- bundle exec rspec spec/unit/...
171
- ```
197
+ ## Sponsoring
172
198
 
173
- Finally, submit your PR and I'll take a look at it when I get a chance.
199
+ If there's a change you want implemented, you can choose to sponsor that change!
200
+ `super_diff` is set up on IssueHunt,
201
+ so feel free to search for an existing issue (or make your own)
202
+ and [add a bounty](https://issuehunt.io/r/mcmire/super_diff/issues).
203
+ I'll get notified right away!
174
204
 
175
205
  ## Compatibility
176
206
 
177
- `super_diff` is [tested][travis] to work with Ruby >= 2.4.x, RSpec 3.x, and
178
- Rails >= 5.x.
207
+ `super_diff` is [tested][travis] to work with
208
+ Ruby >= 2.4.x,
209
+ RSpec 3.x,
210
+ and Rails >= 5.x.
179
211
 
180
212
  [travis]: http://travis-ci.org/mcmire/super_diff
181
213
 
182
214
  ## Inspiration/Thanks
183
215
 
184
- In developing this gem I made use of or was heavily inspired by these libraries:
216
+ In developing this gem
217
+ I made use of or was heavily inspired by these libraries:
185
218
 
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].
219
+ * [Diff::LCS][diff-lcs],
220
+ the library I started with in the [original version of this gem][original-version]
221
+ (made in 2011!)
222
+ * The pretty-printing algorithms and API within [PrettyPrinter][pretty-printer] and [AwesomePrint][awesome-print],
223
+ from which I borrowed ideas to develop the [inspectors][inspection-tree].
191
224
 
192
- Thank you so much!
225
+ Thank you to the authors of these libraries!
193
226
 
194
227
  [original-version]: https://github.com/mcmire/super_diff/tree/old-master
195
228
  [diff-lcs]: https://github.com/halostatue/diff-lcs
@@ -197,6 +230,7 @@ Thank you so much!
197
230
  [awesome-print]: https://github.com/awesome-print/awesome_print
198
231
  [inspection-tree]: https://github.com/mcmire/super_diff/blob/master/lib/super_diff/object_inspection/inspection_tree.rb
199
232
 
200
- ## Copyright/License
233
+ ## Author/License
201
234
 
202
- © 2018-2019 Elliot Winkler, released under the [MIT license](LICENSE).
235
+ `super_diff` was created and is maintained by Elliot Winkler.
236
+ It is released under the [MIT license](LICENSE).
@@ -7,23 +7,17 @@ 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"
17
16
  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
- )
17
+ autoload :ImplementationChecks, "super_diff/implementation_checks"
23
18
  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"
19
+ autoload :OperationTrees, "super_diff/operation_trees"
20
+ autoload :OperationTreeBuilders, "super_diff/operation_tree_builders"
27
21
  autoload :Operations, "super_diff/operations"
28
22
  autoload :RecursionGuard, "super_diff/recursion_guard"
29
23
 
@@ -33,4 +27,19 @@ module SuperDiff
33
27
  border: :blue,
34
28
  header: :white,
35
29
  }.freeze
30
+
31
+ def self.configure
32
+ yield configuration
33
+ end
34
+
35
+ def self.configuration
36
+ @_configuration ||= Configuration.new
37
+ end
38
+
39
+ def self.time_like?(value)
40
+ # Check for ActiveSupport's #acts_like_time? for their time-like objects
41
+ # (like ActiveSupport::TimeWithZone).
42
+ (value.respond_to?(:acts_like_time?) && value.acts_like_time?) ||
43
+ value.is_a?(Time)
44
+ end
36
45
  end
@@ -9,33 +9,31 @@ module SuperDiff
9
9
  "super_diff/active_record/object_inspection",
10
10
  )
11
11
  autoload(
12
- :OperationSequences,
13
- "super_diff/active_record/operation_sequences",
12
+ :OperationTrees,
13
+ "super_diff/active_record/operation_trees",
14
14
  )
15
15
  autoload(
16
- :OperationalSequencers,
17
- "super_diff/active_record/operational_sequencers",
16
+ :OperationTreeBuilders,
17
+ "super_diff/active_record/operation_tree_builders",
18
18
  )
19
- end
20
- end
21
19
 
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
- )
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
- SuperDiff::ObjectInspection.map.prepend(
40
- SuperDiff::ActiveRecord::ObjectInspection::MapExtension,
41
- )
39
+ require "super_diff/active_record/monkey_patches"
@@ -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?(operations)
6
- operations.is_a?(OperationSequences::ActiveRecordRelation)
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
- operations: operations,
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
- operations,
12
+ operation_tree,
13
13
  indent_level: indent_level,
14
14
  )
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def operations
20
- OperationalSequencers::ActiveRecordRelation.call(
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
@@ -0,0 +1,9 @@
1
+ # rubocop:disable Style/BracesAroundHashParameters, Style/ClassAndModuleChildren
2
+ class ActiveRecord::Base
3
+ def attributes_for_super_diff
4
+ (attributes.keys.sort - ["id"]).reduce({ id: id }) do |hash, key|
5
+ hash.merge(key.to_sym => attributes[key])
6
+ end
7
+ end
8
+ end
9
+ # rubocop:enable Style/BracesAroundHashParameters, Style/ClassAndModuleChildren
@@ -2,35 +2,45 @@ module SuperDiff
2
2
  module ActiveRecord
3
3
  module ObjectInspection
4
4
  module Inspectors
5
- ActiveRecordModel = SuperDiff::ObjectInspection::InspectionTree.new do
6
- add_text do |object|
7
- "#<#{object.class} "
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
- when_multiline do
11
- add_text "{"
12
- end
10
+ protected
13
11
 
14
- nested do |object|
15
- add_break
12
+ def inspection_tree
13
+ SuperDiff::ObjectInspection::InspectionTree.new do
14
+ add_text do |object|
15
+ "#<#{object.class} "
16
+ end
16
17
 
17
- insert_separated_list(
18
- ["id"] + (object.attributes.keys.sort - ["id"]),
19
- separator: ",",
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
- add_break
22
+ nested do |object|
23
+ add_break
28
24
 
29
- when_multiline do
30
- add_text "}"
31
- end
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
- add_text ">"
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