super_diff 0.14.0 → 0.16.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 +3 -3
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +5 -1
- data/lib/super_diff/active_record/monkey_patches.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +2 -0
- data/lib/super_diff/rspec/monkey_patches.rb +169 -56
- data/lib/super_diff/rspec.rb +12 -1
- data/lib/super_diff/version.rb +1 -1
- data/super_diff.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7da584c29393f807295a740d893c8890b5d33f9507f4c0ddd914b672b5e9b71
|
4
|
+
data.tar.gz: 89e8cb0b6bd46b7f109b91421636acb21356e14c1e75e0acbd6a45d22b086172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573603b3933aa21c388973e295565199e0c15660a28f7204d1a9d281f0ca320cf28e80bbaf0b9074df13c1e0ea324a5654844985a3f0db9011eb2bb5ff3b7c6c
|
7
|
+
data.tar.gz: 8daa4e73a589b67ac571ea101d7080a1487daf13dc42ce0ce7ee224b9801fd8ed3399e8380c9611cec4d2e93dc5611af3c9bbd5da02c434245d9fda5f127de19
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Since [RSpec merely runs your `expected` and `actual` values through Ruby's Pret
|
|
28
28
|
and then performs a diff of these strings,
|
29
29
|
the output it produces leaves much to be desired.
|
30
30
|
|
31
|
-
[rspec-differ-fail]: https://github.com/rspec/rspec-support/
|
31
|
+
[rspec-differ-fail]: https://github.com/rspec/rspec/blob/rspec-support-v3.13.2/rspec-support/lib/rspec/support/differ.rb#L180-L192
|
32
32
|
|
33
33
|
For instance, let's say you wanted to compare these two hashes:
|
34
34
|
|
@@ -111,9 +111,9 @@ for more on how to do that.
|
|
111
111
|
## Compatibility
|
112
112
|
|
113
113
|
`super_diff` is [tested][gh-actions] to work with
|
114
|
-
Ruby >= 3.
|
114
|
+
Ruby >= 3.1,
|
115
115
|
RSpec 3.x,
|
116
|
-
and Rails >= 6.
|
116
|
+
and Rails >= 6.1.
|
117
117
|
|
118
118
|
[gh-actions]: https://github.com/splitwise/super_diff/actions?query=workflow%3ASuperDiff
|
119
119
|
|
@@ -27,7 +27,11 @@ module SuperDiff
|
|
27
27
|
|
28
28
|
t1.nested do |t2|
|
29
29
|
t2.insert_separated_list(
|
30
|
-
|
30
|
+
if id.nil?
|
31
|
+
object.attributes.keys.sort
|
32
|
+
else
|
33
|
+
[id] + (object.attributes.keys.sort - [id])
|
34
|
+
end
|
31
35
|
) do |t3, name|
|
32
36
|
t3.as_prefix_when_rendering_to_lines do |t4|
|
33
37
|
t4.add_text "#{name}: "
|
@@ -309,73 +309,186 @@ module RSpec
|
|
309
309
|
end
|
310
310
|
|
311
311
|
module Matchers
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
312
|
+
if SuperDiff::RSpec.rspec_version < "3.13.0"
|
313
|
+
class ExpectedsForMultipleDiffs
|
314
|
+
SuperDiff.insert_singleton_overrides(self) do
|
315
|
+
# Add a key for different sides
|
316
|
+
def from(expected)
|
317
|
+
return expected if self === expected
|
318
|
+
|
319
|
+
text = colorizer.wrap("Diff:", SuperDiff.configuration.header_color)
|
320
|
+
|
321
|
+
if SuperDiff.configuration.key_enabled?
|
322
|
+
text +=
|
323
|
+
"\n\n" +
|
324
|
+
colorizer.wrap(
|
325
|
+
"┌ (Key) ──────────────────────────┐",
|
326
|
+
SuperDiff.configuration.border_color
|
327
|
+
) + "\n" +
|
328
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
329
|
+
colorizer.wrap(
|
330
|
+
"‹-› in expected, not in actual",
|
331
|
+
SuperDiff.configuration.expected_color
|
332
|
+
) +
|
333
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
334
|
+
"\n" +
|
335
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
336
|
+
colorizer.wrap(
|
337
|
+
"‹+› in actual, not in expected",
|
338
|
+
SuperDiff.configuration.actual_color
|
339
|
+
) +
|
340
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
341
|
+
"\n" +
|
342
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
343
|
+
"‹ › in both expected and actual" +
|
344
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
345
|
+
"\n" +
|
346
|
+
colorizer.wrap(
|
347
|
+
"└─────────────────────────────────┘",
|
348
|
+
SuperDiff.configuration.border_color
|
349
|
+
)
|
350
|
+
end
|
351
|
+
|
352
|
+
new([[expected, text]])
|
353
|
+
end
|
354
|
+
|
355
|
+
def for_many_matchers(matchers)
|
356
|
+
# Look for expected_for_diff and actual_for_diff if possible
|
357
|
+
diff_tuples = matchers.map do |m|
|
358
|
+
expected = if m.respond_to?(:expected_for_diff)
|
359
|
+
m.expected_for_diff
|
360
|
+
else
|
361
|
+
m.expected
|
362
|
+
end
|
363
|
+
|
364
|
+
actual = if m.respond_to?(:actual_for_diff)
|
365
|
+
m.actual_for_diff
|
366
|
+
else
|
367
|
+
m.actual
|
368
|
+
end
|
369
|
+
[expected, diff_label_for(m), actual]
|
370
|
+
end
|
371
|
+
|
372
|
+
new(diff_tuples)
|
349
373
|
end
|
350
374
|
|
351
|
-
|
375
|
+
def colorizer
|
376
|
+
RSpec::Core::Formatters::ConsoleCodes
|
377
|
+
end
|
352
378
|
end
|
353
379
|
|
354
|
-
|
355
|
-
|
380
|
+
SuperDiff.insert_overrides(self) do
|
381
|
+
# Add an extra line break
|
382
|
+
def message_with_diff(message, differ, actual)
|
383
|
+
diff = diffs(differ, actual)
|
384
|
+
|
385
|
+
diff.empty? ? message : "#{message.rstrip}\n\n#{diff}"
|
386
|
+
end
|
387
|
+
|
388
|
+
private
|
389
|
+
|
390
|
+
# Add extra line breaks in between diffs, and colorize the word "Diff"
|
391
|
+
def diffs(differ, actual)
|
392
|
+
@expected_list
|
393
|
+
.map do |(expected, diff_label)|
|
394
|
+
diff = differ.diff(actual, expected)
|
395
|
+
next if diff.strip.empty?
|
396
|
+
diff_label + diff
|
397
|
+
end
|
398
|
+
.compact
|
399
|
+
.join("\n\n")
|
400
|
+
end
|
356
401
|
end
|
357
402
|
end
|
403
|
+
else
|
404
|
+
class MultiMatcherDiff
|
405
|
+
SuperDiff.insert_singleton_overrides(self) do
|
406
|
+
# Add a key for different sides
|
407
|
+
def from(expected, actual)
|
408
|
+
return expected if self === expected
|
409
|
+
|
410
|
+
text = colorizer.wrap("Diff:", SuperDiff.configuration.header_color)
|
411
|
+
|
412
|
+
if SuperDiff.configuration.key_enabled?
|
413
|
+
text +=
|
414
|
+
"\n\n" +
|
415
|
+
colorizer.wrap(
|
416
|
+
"┌ (Key) ──────────────────────────┐",
|
417
|
+
SuperDiff.configuration.border_color
|
418
|
+
) + "\n" +
|
419
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
420
|
+
colorizer.wrap(
|
421
|
+
"‹-› in expected, not in actual",
|
422
|
+
SuperDiff.configuration.expected_color
|
423
|
+
) +
|
424
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
425
|
+
"\n" +
|
426
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
427
|
+
colorizer.wrap(
|
428
|
+
"‹+› in actual, not in expected",
|
429
|
+
SuperDiff.configuration.actual_color
|
430
|
+
) +
|
431
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
432
|
+
"\n" +
|
433
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
434
|
+
"‹ › in both expected and actual" +
|
435
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
436
|
+
"\n" +
|
437
|
+
colorizer.wrap(
|
438
|
+
"└─────────────────────────────────┘",
|
439
|
+
SuperDiff.configuration.border_color
|
440
|
+
)
|
441
|
+
end
|
358
442
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
443
|
+
new([[expected, text, actual]])
|
444
|
+
end
|
445
|
+
|
446
|
+
def for_many_matchers(matchers)
|
447
|
+
# Look for expected_for_diff and actual_for_diff if possible
|
448
|
+
diff_tuples = matchers.map do |m|
|
449
|
+
expected = if m.respond_to?(:expected_for_diff)
|
450
|
+
m.expected_for_diff
|
451
|
+
else
|
452
|
+
m.expected
|
453
|
+
end
|
454
|
+
|
455
|
+
actual = if m.respond_to?(:actual_for_diff)
|
456
|
+
m.actual_for_diff
|
457
|
+
else
|
458
|
+
m.actual
|
459
|
+
end
|
460
|
+
[expected, diff_label_for(m), actual]
|
461
|
+
end
|
462
|
+
|
463
|
+
new(diff_tuples)
|
464
|
+
end
|
363
465
|
|
364
|
-
|
466
|
+
def colorizer
|
467
|
+
RSpec::Core::Formatters::ConsoleCodes
|
468
|
+
end
|
365
469
|
end
|
366
470
|
|
367
|
-
|
471
|
+
SuperDiff.insert_overrides(self) do
|
472
|
+
# Add an extra line break
|
473
|
+
def message_with_diff(message, differ)
|
474
|
+
diff = diffs(differ)
|
368
475
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
476
|
+
diff.empty? ? message : "#{message.rstrip}\n\n#{diff}"
|
477
|
+
end
|
478
|
+
|
479
|
+
private
|
480
|
+
|
481
|
+
# Add extra line breaks in between diffs, and colorize the word "Diff"
|
482
|
+
def diffs(differ)
|
483
|
+
@expected_list
|
484
|
+
.map do |(expected, diff_label, actual)|
|
485
|
+
diff = differ.diff(actual, expected)
|
486
|
+
next if diff.strip.empty?
|
487
|
+
diff_label + diff
|
488
|
+
end
|
489
|
+
.compact
|
490
|
+
.join("\n\n")
|
491
|
+
end
|
379
492
|
end
|
380
493
|
end
|
381
494
|
end
|
data/lib/super_diff/rspec.rb
CHANGED
@@ -81,7 +81,16 @@ module SuperDiff
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.aliased_matcher?(value)
|
84
|
-
|
84
|
+
if SuperDiff::RSpec.rspec_version < '3.13.0'
|
85
|
+
value.is_a?(::RSpec::Matchers::AliasedMatcher)
|
86
|
+
else # See Github issue #250.
|
87
|
+
!ordered_options?(value) && value.respond_to?(:base_matcher)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.ordered_options?(value)
|
92
|
+
defined?(::ActiveSupport::OrderedOptions) &&
|
93
|
+
value.is_a?(::ActiveSupport::OrderedOptions)
|
85
94
|
end
|
86
95
|
|
87
96
|
def self.rspec_version
|
@@ -124,3 +133,5 @@ module SuperDiff
|
|
124
133
|
end
|
125
134
|
|
126
135
|
require_relative 'rspec/monkey_patches'
|
136
|
+
|
137
|
+
RSpec.configuration.filter_gems_from_backtrace('super_diff')
|
data/lib/super_diff/version.rb
CHANGED
data/super_diff.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
'rubygems_mfa_required' => 'true',
|
23
23
|
'source_code_uri' => 'https://github.com/splitwise/super_diff'
|
24
24
|
}
|
25
|
-
s.required_ruby_version = '>= 3.
|
25
|
+
s.required_ruby_version = '>= 3.1'
|
26
26
|
|
27
27
|
s.files = %w[README.md super_diff.gemspec] + Dir['lib/**/*']
|
28
28
|
s.executables = Dir['exe/**/*'].map { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Winkler
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: attr_extras
|
@@ -262,14 +262,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
262
262
|
requirements:
|
263
263
|
- - ">="
|
264
264
|
- !ruby/object:Gem::Version
|
265
|
-
version: '3.
|
265
|
+
version: '3.1'
|
266
266
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
267
267
|
requirements:
|
268
268
|
- - ">="
|
269
269
|
- !ruby/object:Gem::Version
|
270
270
|
version: '0'
|
271
271
|
requirements: []
|
272
|
-
rubygems_version: 3.
|
272
|
+
rubygems_version: 3.4.19
|
273
273
|
signing_key:
|
274
274
|
specification_version: 4
|
275
275
|
summary: A better way to view differences between complex data structures in RSpec.
|