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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 573a4d219dcad689aca11cffe1beaa7e3c4974958231b1cacd92c32ef0542d74
4
- data.tar.gz: dfb59c966c00ec59df137eb45289c056f1dd58ec461d36913b49527294c99da9
3
+ metadata.gz: a7da584c29393f807295a740d893c8890b5d33f9507f4c0ddd914b672b5e9b71
4
+ data.tar.gz: 89e8cb0b6bd46b7f109b91421636acb21356e14c1e75e0acbd6a45d22b086172
5
5
  SHA512:
6
- metadata.gz: 333c9c71197fa48a68e0328ae1eed9703e96838e6afcef4bc33dcc68f34761ad8b694a8e768bffe86d11372d14c34704634176d35bab5d6584e042fb3eb99627
7
- data.tar.gz: '09136f70b82bef9591e709fffb12023da3beb59d69a55d52f89171649e7df1e6bf618ba00bf6ad08ad404369da7b505cd5027a18917701e41737e07a48faa0c7'
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/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
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.x,
114
+ Ruby >= 3.1,
115
115
  RSpec 3.x,
116
- and Rails >= 6.x.
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
- [id] + (object.attributes.keys.sort - [id])
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}: "
@@ -7,7 +7,7 @@ class ActiveRecord::Base
7
7
  id_attr = self.class.primary_key
8
8
 
9
9
  (attributes.keys.sort - [id_attr]).reduce(
10
- { id_attr.to_sym => id }
10
+ id_attr.nil? ? {} : { id_attr.to_sym => id }
11
11
  ) { |hash, key| hash.merge(key.to_sym => attributes[key]) }
12
12
  end
13
13
  end
@@ -16,6 +16,8 @@ module SuperDiff
16
16
  end
17
17
 
18
18
  def attribute_names
19
+ return expected.attributes.keys.sort if id.nil?
20
+
19
21
  [id] + (expected.attributes.keys.sort - [id])
20
22
  end
21
23
  end
@@ -309,73 +309,186 @@ module RSpec
309
309
  end
310
310
 
311
311
  module Matchers
312
- class ExpectedsForMultipleDiffs
313
- SuperDiff.insert_singleton_overrides(self) do
314
- # Add a key for different sides
315
- def from(expected)
316
- return expected if self === expected
317
-
318
- text = colorizer.wrap("Diff:", SuperDiff.configuration.header_color)
319
-
320
- if SuperDiff.configuration.key_enabled?
321
- text +=
322
- "\n\n" +
323
- colorizer.wrap(
324
- "┌ (Key) ──────────────────────────┐",
325
- SuperDiff.configuration.border_color
326
- ) + "\n" +
327
- colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
328
- colorizer.wrap(
329
- "‹-› in expected, not in actual",
330
- SuperDiff.configuration.expected_color
331
- ) +
332
- colorizer.wrap(" │", SuperDiff.configuration.border_color) +
333
- "\n" +
334
- colorizer.wrap("", SuperDiff.configuration.border_color) +
335
- colorizer.wrap(
336
- "‹+› in actual, not in expected",
337
- SuperDiff.configuration.actual_color
338
- ) +
339
- colorizer.wrap(" │", SuperDiff.configuration.border_color) +
340
- "\n" +
341
- colorizer.wrap("", SuperDiff.configuration.border_color) +
342
- " in both expected and actual" +
343
- colorizer.wrap(" ", SuperDiff.configuration.border_color) +
344
- "\n" +
345
- colorizer.wrap(
346
- "└─────────────────────────────────┘",
347
- SuperDiff.configuration.border_color
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
- new([[expected, text]])
375
+ def colorizer
376
+ RSpec::Core::Formatters::ConsoleCodes
377
+ end
352
378
  end
353
379
 
354
- def colorizer
355
- RSpec::Core::Formatters::ConsoleCodes
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
- SuperDiff.insert_overrides(self) do
360
- # Add an extra line break
361
- def message_with_diff(message, differ, actual)
362
- diff = diffs(differ, actual)
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
- diff.empty? ? message : "#{message.rstrip}\n\n#{diff}"
466
+ def colorizer
467
+ RSpec::Core::Formatters::ConsoleCodes
468
+ end
365
469
  end
366
470
 
367
- private
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
- # Add extra line breaks in between diffs, and colorize the word "Diff"
370
- def diffs(differ, actual)
371
- @expected_list
372
- .map do |(expected, diff_label)|
373
- diff = differ.diff(actual, expected)
374
- next if diff.strip.empty?
375
- diff_label + diff
376
- end
377
- .compact
378
- .join("\n\n")
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
@@ -81,7 +81,16 @@ module SuperDiff
81
81
  end
82
82
 
83
83
  def self.aliased_matcher?(value)
84
- value.is_a?(::RSpec::Matchers::AliasedMatcher)
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')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SuperDiff
4
- VERSION = '0.14.0'
4
+ VERSION = '0.16.0'
5
5
  end
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.0'
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.14.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: 2024-11-15 00:00:00.000000000 Z
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.0'
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.5.20
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.