super_diff 0.5.0 → 0.6.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +49 -22
  3. data/lib/super_diff.rb +1 -7
  4. data/lib/super_diff/colorized_document_extensions.rb +4 -4
  5. data/lib/super_diff/configuration.rb +32 -22
  6. data/lib/super_diff/csi.rb +2 -1
  7. data/lib/super_diff/diff_formatters/collection.rb +1 -1
  8. data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
  9. data/lib/super_diff/equality_matchers/array.rb +2 -2
  10. data/lib/super_diff/equality_matchers/default.rb +2 -2
  11. data/lib/super_diff/equality_matchers/hash.rb +2 -2
  12. data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
  13. data/lib/super_diff/equality_matchers/primitive.rb +2 -2
  14. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  15. data/lib/super_diff/gem_version.rb +45 -0
  16. data/lib/super_diff/operation_trees/base.rb +2 -0
  17. data/lib/super_diff/recursion_guard.rb +2 -0
  18. data/lib/super_diff/rspec.rb +7 -0
  19. data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
  20. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
  21. data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
  22. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
  23. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
  24. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
  25. data/lib/super_diff/rspec/monkey_patches.rb +22 -14
  26. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +12 -1
  27. data/lib/super_diff/version.rb +1 -1
  28. data/spec/examples.txt +390 -397
  29. data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
  30. data/spec/integration/rspec/be_matcher_spec.rb +100 -100
  31. data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
  32. data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
  33. data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
  34. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +107 -107
  35. data/spec/integration/rspec/eq_matcher_spec.rb +230 -230
  36. data/spec/integration/rspec/have_attributes_matcher_spec.rb +129 -129
  37. data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
  38. data/spec/integration/rspec/include_matcher_spec.rb +73 -73
  39. data/spec/integration/rspec/match_array_matcher_spec.rb +149 -107
  40. data/spec/integration/rspec/match_matcher_spec.rb +274 -274
  41. data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
  42. data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
  43. data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
  44. data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
  45. data/spec/spec_helper.rb +22 -13
  46. data/spec/support/integration/helpers.rb +6 -2
  47. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
  48. data/spec/support/integration/test_programs/base.rb +2 -0
  49. data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
  50. data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
  51. data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
  52. data/spec/support/shared_examples/active_record.rb +108 -108
  53. data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
  54. data/spec/unit/equality_matchers/main_spec.rb +403 -403
  55. data/super_diff.gemspec +3 -1
  56. metadata +25 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31484b874ef6086f57dd96cf538d32692040bcfe20df0b5a03ffb2d37528e178
4
- data.tar.gz: ffe9ee2546b907b77018edfc856b207384c111f8d59dcdae54c6148cf1cf6cec
3
+ metadata.gz: 0fc8e5b83b3b02559e96bbd06f8703b688d56b32588639f7d49a4774d6869433
4
+ data.tar.gz: 5f0c9d472aa1170df1a52cc41eab384c4526342cf336e380cdbd01f9e95a3b61
5
5
  SHA512:
6
- metadata.gz: 7f3a9f593e712569fac26dfc8ae395be685006d641576e317dfbc4aee773c506c833142b76f430b22e3089aa8ad2c8be3aabecb6d50992834db15e5ad4968fd0
7
- data.tar.gz: b308ffce611c4bc457115247a9f1a5fb7bf310a78bc9a478fb5c99e6ca2d6fd40070013177d99e372554f0a25615278b094a262226c0460fcc127402aed27f71
6
+ metadata.gz: 24306d1fba59520092a8a446e0a9219a3e9e89813fd3818f2769f737084cc8f6565b12497c86bacb4b9a8f9c5a4b13bafe0479e330cc8169a6c574e11cc74a56
7
+ data.tar.gz: 514af50e6272ae3095b752d778b7f3bc776923bccb87a2ab8a50c2f8019c9aba991e129d2dad88248c621594ab5972029a798ada0e64eb8f8a27acc0e7cde496
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] ![Downloads][downloads-badge] [![IssueHunt][issuehunt-badge]][issuehunt]
1
+ # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][gh-actions-badge]][gh-actions] ![Downloads][downloads-badge] [![IssueHunt][issuehunt-badge]][issuehunt]
2
2
 
3
3
  [version-badge]: http://img.shields.io/gem/v/super_diff.svg
4
4
  [rubygems]: http://rubygems.org/gems/super_diff
5
- [travis-badge]: http://img.shields.io/travis/mcmire/super_diff/master.svg
5
+ [gh-actions-badge]: http://img.shields.io/github/workflow/status/mcmire/super_diff/SuperDiff/master
6
6
  [downloads-badge]: http://img.shields.io/gem/dtv/super_diff.svg
7
7
  [hound]: https://houndci.com
8
8
  [issuehunt-badge]: https://img.shields.io/badge/sponsored_through-IssueHunt-2EC28C
@@ -11,7 +11,7 @@
11
11
  SuperDiff is a gem that hooks into RSpec
12
12
  to intelligently display the differences between two data structures of any type.
13
13
 
14
- 📢 **[See what's changed in the latest version (0.4.2)][changelog].**
14
+ 📢 **[See what's changed in recent versions.][changelog]**
15
15
 
16
16
  [changelog]: CHANGELOG.md
17
17
 
@@ -155,14 +155,47 @@ require "super_diff/rspec"
155
155
 
156
156
  ## Configuration
157
157
 
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`):
158
+ You can customize the behavior of the gem
159
+ by adding a configuration block
160
+ to your test helper file
161
+ (`rails_helper` or `spec_helper`)
162
+ which looks something like this:
163
+
164
+ ``` ruby
165
+ SuperDiff.configure do |config|
166
+ # ...
167
+ end
168
+ ```
169
+
170
+ ### Customizing colors
171
+
172
+ If you don't like the colors that SuperDiff uses,
173
+ you can change them like this:
174
+
175
+ ``` ruby
176
+ SuperDiff.configure do |config|
177
+ config.actual_color = :green
178
+ config.expected_color = :red
179
+ config.border_color = :yellow
180
+ config.header_color = :yellow
181
+ end
182
+ ```
183
+
184
+ See [eight_bit_color.rb](lib/super_diff/csi/eight_bit_color.rb)
185
+ for the list of available colors.
186
+
187
+ ### Diffing custom objects
188
+
189
+ If you are comparing two data structures
190
+ that involve a class that is specific to your project,
191
+ the resulting diff may not look as good as diffs involving native or primitive objects.
192
+ This happens because if SuperDiff doesn't recognize a class,
193
+ it will fall back to a generic representation when diffing instances of that class.
194
+ Fortunately, the gem has a pluggable interface
195
+ that allows you to insert your own implementations
196
+ of key pieces involved in the diffing process.
197
+ I'll have more about how that works soon,
198
+ but here is what such a configuration would look like:
166
199
 
167
200
  ``` ruby
168
201
  SuperDiff.configure do |config|
@@ -173,12 +206,6 @@ SuperDiff.configure do |config|
173
206
  end
174
207
  ```
175
208
 
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.)*
181
-
182
209
  ## Support
183
210
 
184
211
  My goal for this library is to improve your development experience.
@@ -199,17 +226,17 @@ Please see the [contributing](./CONTRIBUTING.md) document for more on how to do
199
226
  If there's a change you want implemented, you can choose to sponsor that change!
200
227
  `super_diff` is set up on IssueHunt,
201
228
  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).
229
+ and [add a bounty](https://issuehunt.io/r/mcmire/super_diff).
203
230
  I'll get notified right away!
204
231
 
205
232
  ## Compatibility
206
233
 
207
- `super_diff` is [tested][travis] to work with
208
- Ruby >= 2.4.x,
234
+ `super_diff` is [tested][gh-actions] to work with
235
+ Ruby >= 2.5.x,
209
236
  RSpec 3.x,
210
237
  and Rails >= 5.x.
211
238
 
212
- [travis]: http://travis-ci.org/mcmire/super_diff
239
+ [gh-actions]: https://github.com/mcmire/super_diff/actions?query=workflow%3ASuperDiff
213
240
 
214
241
  ## Inspiration/Thanks
215
242
 
@@ -232,5 +259,5 @@ Thank you to the authors of these libraries!
232
259
 
233
260
  ## Author/License
234
261
 
235
- `super_diff` was created and is maintained by Elliot Winkler.
262
+ SuperDiff was created and is maintained by Elliot Winkler.
236
263
  It is released under the [MIT license](LICENSE).
data/lib/super_diff.rb CHANGED
@@ -13,6 +13,7 @@ module SuperDiff
13
13
  autoload :Differs, "super_diff/differs"
14
14
  autoload :EqualityMatchers, "super_diff/equality_matchers"
15
15
  autoload :Errors, "super_diff/errors"
16
+ autoload :GemVersion, "super_diff/gem_version"
16
17
  autoload :Helpers, "super_diff/helpers"
17
18
  autoload :ImplementationChecks, "super_diff/implementation_checks"
18
19
  autoload :ObjectInspection, "super_diff/object_inspection"
@@ -21,13 +22,6 @@ module SuperDiff
21
22
  autoload :Operations, "super_diff/operations"
22
23
  autoload :RecursionGuard, "super_diff/recursion_guard"
23
24
 
24
- COLORS = {
25
- alpha: :magenta,
26
- beta: :yellow,
27
- border: :blue,
28
- header: :white,
29
- }.freeze
30
-
31
25
  def self.configure
32
26
  yield configuration
33
27
  end
@@ -6,12 +6,12 @@ module SuperDiff
6
6
  end
7
7
  end
8
8
 
9
- def alpha(*args, **opts, &block)
10
- colorize(*args, **opts, fg: SuperDiff::COLORS.fetch(:alpha), &block)
9
+ def expected(*args, **opts, &block)
10
+ colorize(*args, **opts, fg: SuperDiff.configuration.expected_color, &block)
11
11
  end
12
12
 
13
- def beta(*args, **opts, &block)
14
- colorize(*args, **opts, fg: SuperDiff::COLORS.fetch(:beta), &block)
13
+ def actual(*args, **opts, &block)
14
+ colorize(*args, **opts, fg: SuperDiff.configuration.actual_color, &block)
15
15
  end
16
16
  end
17
17
  end
@@ -1,26 +1,54 @@
1
1
  module SuperDiff
2
2
  class Configuration
3
3
  attr_reader(
4
+ :extra_diff_formatter_classes,
4
5
  :extra_differ_classes,
6
+ :extra_inspector_classes,
5
7
  :extra_operation_tree_builder_classes,
6
8
  :extra_operation_tree_classes,
7
- :extra_diff_formatter_classes,
8
- :extra_inspector_classes,
9
+ )
10
+ attr_accessor(
11
+ :actual_color,
12
+ :border_color,
13
+ :expected_color,
14
+ :header_color,
9
15
  )
10
16
 
11
17
  def initialize
18
+ @actual_color = :yellow
19
+ @border_color = :blue
20
+ @expected_color = :magenta
21
+ @extra_diff_formatter_classes = [].freeze
12
22
  @extra_differ_classes = [].freeze
23
+ @extra_inspector_classes = [].freeze
13
24
  @extra_operation_tree_builder_classes = [].freeze
14
25
  @extra_operation_tree_classes = [].freeze
15
- @extra_diff_formatter_classes = [].freeze
16
- @extra_inspector_classes = [].freeze
26
+ @header_color = :white
17
27
  end
18
28
 
29
+ def add_extra_diff_formatter_classes(*classes)
30
+ @extra_diff_formatter_classes =
31
+ (@extra_diff_formatter_classes + classes).freeze
32
+ end
33
+ alias_method(
34
+ :add_extra_diff_formatter_class,
35
+ :add_extra_diff_formatter_classes,
36
+ )
37
+
19
38
  def add_extra_differ_classes(*classes)
20
39
  @extra_differ_classes = (@extra_differ_classes + classes).freeze
21
40
  end
22
41
  alias_method :add_extra_differ_class, :add_extra_differ_classes
23
42
 
43
+ def add_extra_inspector_classes(*classes)
44
+ @extra_inspector_classes =
45
+ (@extra_inspector_classes + classes).freeze
46
+ end
47
+ alias_method(
48
+ :add_extra_inspector_class,
49
+ :add_extra_inspector_classes,
50
+ )
51
+
24
52
  def add_extra_operation_tree_builder_classes(*classes)
25
53
  @extra_operation_tree_builder_classes =
26
54
  (@extra_operation_tree_builder_classes + classes).freeze
@@ -38,23 +66,5 @@ module SuperDiff
38
66
  :add_extra_operation_tree_class,
39
67
  :add_extra_operation_tree_classes,
40
68
  )
41
-
42
- def add_extra_diff_formatter_classes(*classes)
43
- @extra_diff_formatter_classes =
44
- (@extra_diff_formatter_classes + classes).freeze
45
- end
46
- alias_method(
47
- :add_extra_diff_formatter_class,
48
- :add_extra_diff_formatter_classes,
49
- )
50
-
51
- def add_extra_inspector_classes(*classes)
52
- @extra_inspector_classes =
53
- (@extra_inspector_classes + classes).freeze
54
- end
55
- alias_method(
56
- :add_extra_inspector_class,
57
- :add_extra_inspector_classes,
58
- )
59
69
  end
60
70
  end
@@ -58,6 +58,7 @@ module SuperDiff
58
58
  end
59
59
  end
60
60
 
61
- self.color_enabled = STDOUT.tty?
61
+ self.color_enabled = ENV["CI"] == "true" || STDOUT.tty?
62
+ # puts "(SuperDiff::Csi) Super::Csi.color_enabled: #{color_enabled?}"
62
63
  end
63
64
  end
@@ -4,7 +4,7 @@ module SuperDiff
4
4
  extend AttrExtras.mixin
5
5
 
6
6
  ICONS = { delete: "-", insert: "+" }.freeze
7
- STYLES = { insert: :beta, delete: :alpha, noop: :plain }.freeze
7
+ STYLES = { insert: :actual, delete: :expected, noop: :plain }.freeze
8
8
 
9
9
  method_object(
10
10
  [
@@ -15,12 +15,12 @@ module SuperDiff
15
15
  operation_tree.reduce([]) do |array, operation|
16
16
  case operation.name
17
17
  when :change
18
- array << Helpers.style(:alpha, "- #{operation.left_value}")
19
- array << Helpers.style(:beta, "+ #{operation.right_value}")
18
+ array << Helpers.style(:expected, "- #{operation.left_value}")
19
+ array << Helpers.style(:actual, "+ #{operation.right_value}")
20
20
  when :delete
21
- array << Helpers.style(:alpha, "- #{operation.value}")
21
+ array << Helpers.style(:expected, "- #{operation.value}")
22
22
  when :insert
23
- array << Helpers.style(:beta, "+ #{operation.value}")
23
+ array << Helpers.style(:actual, "+ #{operation.value}")
24
24
  else
25
25
  array << Helpers.style(:plain, " #{operation.value}")
26
26
  end
@@ -11,14 +11,14 @@ module SuperDiff
11
11
 
12
12
  #{
13
13
  Helpers.style(
14
- :alpha,
14
+ :expected,
15
15
  "Expected: " +
16
16
  ObjectInspection.inspect(expected, as_single_line: true),
17
17
  )
18
18
  }
19
19
  #{
20
20
  Helpers.style(
21
- :beta,
21
+ :actual,
22
22
  " Actual: " +
23
23
  ObjectInspection.inspect(actual, as_single_line: true),
24
24
  )
@@ -19,7 +19,7 @@ module SuperDiff
19
19
 
20
20
  def expected_line
21
21
  Helpers.style(
22
- :alpha,
22
+ :expected,
23
23
  "Expected: " +
24
24
  ObjectInspection.inspect(expected, as_single_line: true),
25
25
  )
@@ -27,7 +27,7 @@ module SuperDiff
27
27
 
28
28
  def actual_line
29
29
  Helpers.style(
30
- :beta,
30
+ :actual,
31
31
  " Actual: " +
32
32
  ObjectInspection.inspect(actual, as_single_line: true),
33
33
  )
@@ -11,14 +11,14 @@ module SuperDiff
11
11
 
12
12
  #{
13
13
  Helpers.style(
14
- :alpha,
14
+ :expected,
15
15
  "Expected: " +
16
16
  ObjectInspection.inspect(expected, as_single_line: true),
17
17
  )
18
18
  }
19
19
  #{
20
20
  Helpers.style(
21
- :beta,
21
+ :actual,
22
22
  " Actual: " +
23
23
  ObjectInspection.inspect(actual, as_single_line: true),
24
24
  )
@@ -12,14 +12,14 @@ module SuperDiff
12
12
  #{
13
13
  # TODO: This whole thing should not be red or green, just the values
14
14
  Helpers.style(
15
- :alpha,
15
+ :expected,
16
16
  "Expected: " +
17
17
  ObjectInspection.inspect(expected, as_single_line: true),
18
18
  )
19
19
  }
20
20
  #{
21
21
  Helpers.style(
22
- :beta,
22
+ :actual,
23
23
  " Actual: " +
24
24
  ObjectInspection.inspect(actual, as_single_line: true),
25
25
  )
@@ -15,14 +15,14 @@ module SuperDiff
15
15
 
16
16
  #{
17
17
  Helpers.style(
18
- :alpha,
18
+ :expected,
19
19
  "Expected: " +
20
20
  ObjectInspection.inspect(expected, as_single_line: true),
21
21
  )
22
22
  }
23
23
  #{
24
24
  Helpers.style(
25
- :beta,
25
+ :actual,
26
26
  " Actual: " +
27
27
  ObjectInspection.inspect(actual, as_single_line: true),
28
28
  )
@@ -11,14 +11,14 @@ module SuperDiff
11
11
 
12
12
  #{
13
13
  Helpers.style(
14
- :alpha,
14
+ :expected,
15
15
  "Expected: " +
16
16
  ObjectInspection.inspect(expected, as_single_line: true),
17
17
  )
18
18
  }
19
19
  #{
20
20
  Helpers.style(
21
- :beta,
21
+ :actual,
22
22
  " Actual: " +
23
23
  ObjectInspection.inspect(actual, as_single_line: true),
24
24
  )
@@ -0,0 +1,45 @@
1
+ module SuperDiff
2
+ class GemVersion
3
+ def initialize(version)
4
+ @version = Gem::Version.new(version.to_s)
5
+ end
6
+
7
+ def <(other)
8
+ compare?(:<, other)
9
+ end
10
+
11
+ def <=(other)
12
+ compare?(:<=, other)
13
+ end
14
+
15
+ def ==(other)
16
+ compare?(:==, other)
17
+ end
18
+
19
+ def >=(other)
20
+ compare?(:>=, other)
21
+ end
22
+
23
+ def >(other)
24
+ compare?(:>, other)
25
+ end
26
+
27
+ def =~(other)
28
+ Gem::Requirement.new(other).satisfied_by?(version)
29
+ end
30
+
31
+ def to_s
32
+ version.to_s
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :version
38
+
39
+ def compare?(operator, other_version)
40
+ Gem::Requirement.
41
+ new("#{operator} #{other_version}").
42
+ satisfied_by?(version)
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,5 @@
1
+ require 'delegate'
2
+
1
3
  module SuperDiff
2
4
  module OperationTrees
3
5
  class Base < SimpleDelegator