super_diff 0.10.0 → 0.11.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +24 -12
  3. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +15 -6
  4. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +23 -8
  5. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  6. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +4 -0
  7. data/lib/super_diff/active_support.rb +2 -1
  8. data/lib/super_diff/differs/date_like.rb +15 -0
  9. data/lib/super_diff/differs/defaults.rb +1 -0
  10. data/lib/super_diff/differs.rb +1 -0
  11. data/lib/super_diff/errors.rb +0 -4
  12. data/lib/super_diff/object_inspection/inspection_tree.rb +25 -20
  13. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +31 -12
  14. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +19 -9
  15. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  16. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +46 -21
  17. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -0
  18. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +39 -14
  19. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  20. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +31 -20
  21. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +4 -0
  22. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +3 -2
  23. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  24. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  25. data/lib/super_diff/operation_tree_builders.rb +1 -0
  26. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +3 -7
  27. data/lib/super_diff/rspec/monkey_patches.rb +59 -8
  28. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  29. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +19 -13
  30. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +30 -26
  31. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  32. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +19 -14
  33. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +9 -10
  34. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +9 -10
  35. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  36. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  37. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +4 -0
  38. data/lib/super_diff/rspec.rb +10 -9
  39. data/lib/super_diff/version.rb +1 -1
  40. data/lib/super_diff.rb +9 -0
  41. data/spec/examples.txt +543 -493
  42. data/spec/integration/rails/engines_spec.rb +8 -3
  43. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
  44. data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
  45. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  46. data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
  47. data/spec/integration/rspec/include_matcher_spec.rb +23 -23
  48. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  49. data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
  50. data/spec/integration/rspec/match_matcher_spec.rb +93 -93
  51. data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
  52. data/spec/internal/log/test.log +0 -0
  53. data/spec/spec_helper.rb +3 -0
  54. data/spec/support/integration/helpers.rb +15 -10
  55. data/spec/support/integration/matchers.rb +34 -0
  56. data/spec/support/integration/test_programs/base.rb +6 -6
  57. data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
  58. data/spec/support/shared_examples/active_record.rb +33 -33
  59. data/spec/support/shared_examples/active_support.rb +125 -4
  60. data/spec/support/shared_examples/elided_diffs.rb +48 -48
  61. data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
  62. data/spec/support/shared_examples/key.rb +10 -10
  63. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  64. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  65. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  66. data/spec/unit/rspec/object_inspection_spec.rb +2 -2
  67. data/spec/unit/super_diff_spec.rb +64 -0
  68. metadata +17 -4
  69. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  70. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
@@ -0,0 +1,91 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe SuperDiff, type: :unit do
4
+ describe ".inspect_object", "for RSpec matchers" do
5
+ context "given a custom matcher" do
6
+ let(:custom_matcher) do
7
+ proc do |expected, &block_arg|
8
+ declarations =
9
+ proc do
10
+ match do |actual|
11
+ actual.is_a?(Integer) && actual >= 0 &&
12
+ (Math.sqrt(actual) % 1).zero?
13
+ end
14
+ description { "be a perfect square" }
15
+ end
16
+ RSpec::Matchers::DSL::Matcher.new(
17
+ :be_a_square,
18
+ declarations,
19
+ RSpec::Matchers::DSL,
20
+ *expected,
21
+ &block_arg
22
+ )
23
+ end
24
+ end
25
+
26
+ context "given as_lines: false" do
27
+ it "returns the matcher's description string" do
28
+ string =
29
+ described_class.inspect_object(
30
+ custom_matcher.call(4),
31
+ as_lines: false
32
+ )
33
+ expect(string).to eq("#<be a perfect square>")
34
+ end
35
+ end
36
+
37
+ context "given as_lines: true" do
38
+ it "returns an inspected version of the matcher as multiple lines" do
39
+ tiered_lines =
40
+ described_class.inspect_object(
41
+ custom_matcher.call(4),
42
+ as_lines: true,
43
+ type: :delete,
44
+ indentation_level: 1
45
+ )
46
+ expect(tiered_lines).to match(
47
+ [
48
+ an_object_having_attributes(
49
+ type: :delete,
50
+ indentation_level: 1,
51
+ value: "#<be a perfect square>"
52
+ )
53
+ ]
54
+ )
55
+ end
56
+ end
57
+ end
58
+
59
+ context "given a built-in matcher" do
60
+ let(:matcher) { be_a(Numeric) }
61
+
62
+ context "given as_lines: false" do
63
+ it "returns the matcher's description string" do
64
+ string = described_class.inspect_object(matcher, as_lines: false)
65
+ expect(string).to eq("#<be a kind of Numeric>")
66
+ end
67
+ end
68
+
69
+ context "given as_lines: true" do
70
+ it "returns an inspected version of the matcher as multiple lines" do
71
+ tiered_lines =
72
+ described_class.inspect_object(
73
+ matcher,
74
+ as_lines: true,
75
+ type: :delete,
76
+ indentation_level: 1
77
+ )
78
+ expect(tiered_lines).to match(
79
+ [
80
+ an_object_having_attributes(
81
+ type: :delete,
82
+ indentation_level: 1,
83
+ value: "#<be a kind of Numeric>"
84
+ )
85
+ ]
86
+ )
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe SuperDiff, type: :unit do
4
- describe ".inspect_object", "for RSpec objects" do
4
+ describe ".inspect_object", "for RSpec aliased matchers" do
5
5
  context "given a hash-including-<something>" do
6
6
  context "given as_lines: false" do
7
7
  it "returns an inspected version of the object" do
@@ -116,7 +116,7 @@ RSpec.describe SuperDiff, type: :unit do
116
116
  end
117
117
  end
118
118
 
119
- context "given a fuzzy object" do
119
+ context "given an object-having-<something>" do
120
120
  context "given as_lines: false" do
121
121
  it "returns an inspected version of the object" do
122
122
  string =
@@ -1026,6 +1026,70 @@ RSpec.describe SuperDiff, type: :unit do
1026
1026
  end
1027
1027
  end
1028
1028
 
1029
+ context "given a Date object" do
1030
+ context "given as_lines: false" do
1031
+ it "returns a representation of the date on a single line" do
1032
+ inspection =
1033
+ described_class.inspect_object(
1034
+ Date.new(2023, 10, 14),
1035
+ as_lines: false
1036
+ )
1037
+ expect(inspection).to eq("#<Date 2023-10-14>")
1038
+ end
1039
+ end
1040
+
1041
+ context "given as_lines: true" do
1042
+ it "returns a representation of the date across multiple lines" do
1043
+ inspection =
1044
+ described_class.inspect_object(
1045
+ Date.new(2023, 10, 14),
1046
+ as_lines: true,
1047
+ type: :delete,
1048
+ indentation_level: 1
1049
+ )
1050
+ expect(inspection).to match(
1051
+ [
1052
+ an_object_having_attributes(
1053
+ type: :delete,
1054
+ indentation_level: 1,
1055
+ value: "#<Date {",
1056
+ add_comma: false,
1057
+ collection_bookend: :open
1058
+ ),
1059
+ an_object_having_attributes(
1060
+ type: :delete,
1061
+ indentation_level: 2,
1062
+ value: "year: 2023",
1063
+ add_comma: true,
1064
+ collection_bookend: nil
1065
+ ),
1066
+ an_object_having_attributes(
1067
+ type: :delete,
1068
+ indentation_level: 2,
1069
+ value: "month: 10",
1070
+ add_comma: true,
1071
+ collection_bookend: nil
1072
+ ),
1073
+ an_object_having_attributes(
1074
+ type: :delete,
1075
+ indentation_level: 2,
1076
+ value: "day: 14",
1077
+ add_comma: false,
1078
+ collection_bookend: nil
1079
+ ),
1080
+ an_object_having_attributes(
1081
+ type: :delete,
1082
+ indentation_level: 1,
1083
+ value: "}>",
1084
+ add_comma: false,
1085
+ collection_bookend: :close
1086
+ )
1087
+ ]
1088
+ )
1089
+ end
1090
+ end
1091
+ end
1092
+
1029
1093
  context "given a class" do
1030
1094
  context "given as_lines: false" do
1031
1095
  it "returns an inspected version of the object" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Winkler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-26 00:00:00.000000000 Z
11
+ date: 2024-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attr_extras
@@ -84,6 +84,7 @@ files:
84
84
  - lib/super_diff/active_support/object_inspection.rb
85
85
  - lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb
86
86
  - lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb
87
+ - lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb
87
88
  - lib/super_diff/active_support/operation_tree_builders.rb
88
89
  - lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb
89
90
  - lib/super_diff/active_support/operation_tree_flatteners.rb
@@ -109,6 +110,7 @@ files:
109
110
  - lib/super_diff/differs/array.rb
110
111
  - lib/super_diff/differs/base.rb
111
112
  - lib/super_diff/differs/custom_object.rb
113
+ - lib/super_diff/differs/date_like.rb
112
114
  - lib/super_diff/differs/default_object.rb
113
115
  - lib/super_diff/differs/defaults.rb
114
116
  - lib/super_diff/differs/empty.rb
@@ -127,9 +129,7 @@ files:
127
129
  - lib/super_diff/equality_matchers/primitive.rb
128
130
  - lib/super_diff/equality_matchers/singleline_string.rb
129
131
  - lib/super_diff/errors.rb
130
- - lib/super_diff/errors/no_diff_formatter_available_error.rb
131
132
  - lib/super_diff/errors/no_differ_available_error.rb
132
- - lib/super_diff/errors/no_operational_sequencer_available_error.rb
133
133
  - lib/super_diff/gem_version.rb
134
134
  - lib/super_diff/helpers.rb
135
135
  - lib/super_diff/implementation_checks.rb
@@ -140,6 +140,7 @@ files:
140
140
  - lib/super_diff/object_inspection/inspection_tree_builders/array.rb
141
141
  - lib/super_diff/object_inspection/inspection_tree_builders/base.rb
142
142
  - lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb
143
+ - lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb
143
144
  - lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb
144
145
  - lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb
145
146
  - lib/super_diff/object_inspection/inspection_tree_builders/hash.rb
@@ -166,6 +167,7 @@ files:
166
167
  - lib/super_diff/operation_tree_builders/array.rb
167
168
  - lib/super_diff/operation_tree_builders/base.rb
168
169
  - lib/super_diff/operation_tree_builders/custom_object.rb
170
+ - lib/super_diff/operation_tree_builders/date_like.rb
169
171
  - lib/super_diff/operation_tree_builders/default_object.rb
170
172
  - lib/super_diff/operation_tree_builders/defaults.rb
171
173
  - lib/super_diff/operation_tree_builders/hash.rb
@@ -218,6 +220,7 @@ files:
218
220
  - lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb
219
221
  - lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb
220
222
  - lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb
223
+ - lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb
221
224
  - lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb
222
225
  - lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb
223
226
  - lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb
@@ -245,15 +248,18 @@ files:
245
248
  - spec/integration/rspec/be_truthy_matcher_spec.rb
246
249
  - spec/integration/rspec/contain_exactly_matcher_spec.rb
247
250
  - spec/integration/rspec/eq_matcher_spec.rb
251
+ - spec/integration/rspec/generic_describable_matchers_spec.rb
248
252
  - spec/integration/rspec/have_attributes_matcher_spec.rb
249
253
  - spec/integration/rspec/have_predicate_matcher_spec.rb
250
254
  - spec/integration/rspec/include_matcher_spec.rb
255
+ - spec/integration/rspec/magic_metadata_spec.rb
251
256
  - spec/integration/rspec/match_array_matcher_spec.rb
252
257
  - spec/integration/rspec/match_matcher_spec.rb
253
258
  - spec/integration/rspec/raise_error_matcher_spec.rb
254
259
  - spec/integration/rspec/respond_to_matcher_spec.rb
255
260
  - spec/integration/rspec/third_party_matcher_spec.rb
256
261
  - spec/integration/rspec/unhandled_errors_spec.rb
262
+ - spec/internal/log/test.log
257
263
  - spec/spec_helper.rb
258
264
  - spec/support/colorizer.rb
259
265
  - spec/support/command_runner.rb
@@ -286,6 +292,7 @@ files:
286
292
  - spec/support/unit/helpers.rb
287
293
  - spec/support/unit/matchers/match_output.rb
288
294
  - spec/unit/active_record/object_inspection_spec.rb
295
+ - spec/unit/active_support/object_inspection_spec.rb
289
296
  - spec/unit/equality_matchers/main_spec.rb
290
297
  - spec/unit/helpers_spec.rb
291
298
  - spec/unit/operation_tree_flatteners/array_spec.rb
@@ -308,6 +315,7 @@ files:
308
315
  - spec/unit/rspec/matchers/match_spec.rb
309
316
  - spec/unit/rspec/matchers/raise_error_spec.rb
310
317
  - spec/unit/rspec/matchers/respond_to_spec.rb
318
+ - spec/unit/rspec/object_inspection/rspec_matcher_spec.rb
311
319
  - spec/unit/rspec/object_inspection_spec.rb
312
320
  - spec/unit/super_diff_spec.rb
313
321
  - spec/unit/tiered_lines_elider_spec.rb
@@ -349,15 +357,18 @@ test_files:
349
357
  - spec/integration/rspec/be_truthy_matcher_spec.rb
350
358
  - spec/integration/rspec/contain_exactly_matcher_spec.rb
351
359
  - spec/integration/rspec/eq_matcher_spec.rb
360
+ - spec/integration/rspec/generic_describable_matchers_spec.rb
352
361
  - spec/integration/rspec/have_attributes_matcher_spec.rb
353
362
  - spec/integration/rspec/have_predicate_matcher_spec.rb
354
363
  - spec/integration/rspec/include_matcher_spec.rb
364
+ - spec/integration/rspec/magic_metadata_spec.rb
355
365
  - spec/integration/rspec/match_array_matcher_spec.rb
356
366
  - spec/integration/rspec/match_matcher_spec.rb
357
367
  - spec/integration/rspec/raise_error_matcher_spec.rb
358
368
  - spec/integration/rspec/respond_to_matcher_spec.rb
359
369
  - spec/integration/rspec/third_party_matcher_spec.rb
360
370
  - spec/integration/rspec/unhandled_errors_spec.rb
371
+ - spec/internal/log/test.log
361
372
  - spec/spec_helper.rb
362
373
  - spec/support/colorizer.rb
363
374
  - spec/support/command_runner.rb
@@ -390,6 +401,7 @@ test_files:
390
401
  - spec/support/unit/helpers.rb
391
402
  - spec/support/unit/matchers/match_output.rb
392
403
  - spec/unit/active_record/object_inspection_spec.rb
404
+ - spec/unit/active_support/object_inspection_spec.rb
393
405
  - spec/unit/equality_matchers/main_spec.rb
394
406
  - spec/unit/helpers_spec.rb
395
407
  - spec/unit/operation_tree_flatteners/array_spec.rb
@@ -412,6 +424,7 @@ test_files:
412
424
  - spec/unit/rspec/matchers/match_spec.rb
413
425
  - spec/unit/rspec/matchers/raise_error_spec.rb
414
426
  - spec/unit/rspec/matchers/respond_to_spec.rb
427
+ - spec/unit/rspec/object_inspection/rspec_matcher_spec.rb
415
428
  - spec/unit/rspec/object_inspection_spec.rb
416
429
  - spec/unit/super_diff_spec.rb
417
430
  - spec/unit/tiered_lines_elider_spec.rb
@@ -1,21 +0,0 @@
1
- module SuperDiff
2
- module Errors
3
- class NoDiffFormatterAvailableError < StandardError
4
- def self.create(operation_tree)
5
- allocate.tap do |error|
6
- error.operation_tree = operation_tree
7
- error.__send__(:initialize)
8
- end
9
- end
10
-
11
- attr_accessor :operation_tree
12
-
13
- def initialize
14
- super(<<-MESSAGE)
15
- There is no diff formatter available to handle an operation tree object of
16
- #{operation_tree.class}.
17
- MESSAGE
18
- end
19
- end
20
- end
21
- end
@@ -1,22 +0,0 @@
1
- module SuperDiff
2
- module Errors
3
- class NoOperationalSequencerAvailableError < StandardError
4
- def self.create(expected, actual)
5
- allocate.tap do |error|
6
- error.expected = expected
7
- error.actual = actual
8
- error.__send__(:initialize)
9
- end
10
- end
11
-
12
- attr_accessor :expected, :actual
13
-
14
- def initialize
15
- super(<<-MESSAGE)
16
- There is no operational sequencer available to handle an "expected" value of
17
- type #{expected.class} and an "actual" value of type #{actual.class}.
18
- MESSAGE
19
- end
20
- end
21
- end
22
- end