minitest-difftastic 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d603a327fc8fce58c1ef00a079628ac03ceef45e5dccb959111f19be4fb0391b
4
- data.tar.gz: 4639b7123d9158ffb7629c8e07e0b90b5c8f3606718e8588fc61b61b504835c3
3
+ metadata.gz: 692dd87d40229d2fea8ac5e00900e45ae33ec436b33f22d98027037f5448ef22
4
+ data.tar.gz: d1f4de4c6be40d5bdcd5efed3907ecfc52725d15f8d7606083c0d34b4904e142
5
5
  SHA512:
6
- metadata.gz: 9417837255131ee678670cda378c42e9afcfe8a07975647307b16f70b9139965f92c6f998f8ef0e6f68a4e7837117f44349d6f928259126d748e5c0efa1b8559
7
- data.tar.gz: 8c019e2e12b9506a66bd5c766a7b4cbe85d744610a190fafeec35f5593d7ffccc43b0ac016a6ba7a05f459854a59204a75b019dd75d4a2303c8de1b64021c655
6
+ metadata.gz: 16c1ffb8e443e9423074ec083cc94f7c90121c44590ca7559ae6e0ed6ba75e4d7bec2b293f576e22a7dd4d48487a20c63ca6e0c28a94355d1f6972e3917f0afb
7
+ data.tar.gz: fb8c0fa64bed4a4d163a295343083b37418cd27ade769f2b8cb71d1dd6f2f8fbd116d0838b5fdd5e19de0411638c8a503ebf9177a25af55ae493c4865914d0f3
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
  SuggestExtensions: false
4
- TargetRubyVersion: 3.0
4
+ TargetRubyVersion: 3.1
5
5
 
6
6
  Style/StringLiterals:
7
7
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minitest-difftastic (0.1.0)
4
+ minitest-difftastic (0.1.1)
5
5
  difftastic (~> 0.0.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,9 +1,25 @@
1
1
  # Minitest::Difftastic
2
2
 
3
- A Minitest Plugin which uses [`difftastic`](https://github.com/Wilfred/difftastic) (via [`difftastic-ruby`](https://github.com/joeldrapper/difftastic-ruby)) to show the diffs for failing assertions.
3
+ A Minitest Plugin which uses [`difftastic`](https://github.com/Wilfred/difftastic) (via [`difftastic-ruby`](https://github.com/joeldrapper/difftastic-ruby)) to show the diffs for failing assertions.
4
4
 
5
5
  Also works for Rails tests using `ActiveSupport::TestCase`.
6
6
 
7
+ ### Integers
8
+
9
+ ![Integers Comparison](./screenshots/integers.png)
10
+
11
+ ### Strings
12
+
13
+ ![Strings Comparison](./screenshots/strings.png)
14
+
15
+ ### Objects
16
+
17
+ ![Objects Comparison](./screenshots/objects.png)
18
+
19
+ ### Nested Objects
20
+
21
+ ![Nested Objects Comparison](./screenshots/nested_objects.png)
22
+
7
23
  ## Installation
8
24
 
9
25
  Install the gem and add to the application's Gemfile by executing:
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minitest
4
4
  module Difftastic
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -5,10 +5,44 @@ require "difftastic"
5
5
  # TODO: use refinements
6
6
  module Minitest
7
7
  module Assertions
8
+ MINIMUM_OFFSET = 29
9
+ TAB_WIDTH = 2
10
+
11
+ RED = "\e[91;1m"
12
+ GREEN = "\e[92;1m"
13
+ RESET = "\e[0m"
14
+
15
+ DIFFER = ::Difftastic::Differ.new(
16
+ color: :always,
17
+ tab_width: TAB_WIDTH,
18
+ syntax_highlight: :off
19
+ )
20
+
21
+ alias diff_original diff
22
+
8
23
  def diff(exp, act)
9
- ::Difftastic::Differ.new(color: :always, tab_width: 2, syntax_highlight: :off).diff_objects(exp, act)
10
- rescue StandardError
11
- super
24
+ diff = DIFFER.diff_objects(exp, act)
25
+ offset = actual_text_offset(diff.split("\n").first)
26
+
27
+ "\n#{RED}#{"Expected".ljust(offset)} #{GREEN}Actual#{RESET}\n#{diff}"
28
+ rescue StandardError => e
29
+ puts "Minitest::DiffTastic error: #{e.inspect} (#{e.backtrace[0]})"
30
+ diff_original(exp, act)
31
+ end
32
+
33
+ private
34
+
35
+ def strip_ansi_formatting(string)
36
+ string.to_s.gsub(/\e\[[0-9;]*m/, "")
37
+ end
38
+
39
+ def actual_text_offset(line)
40
+ stripped_line = strip_ansi_formatting(line)
41
+ _lhs, rhs = stripped_line.split(/\s{#{TAB_WIDTH},}/, 2)
42
+
43
+ offset = stripped_line.index("#{" " * TAB_WIDTH}#{rhs}") + TAB_WIDTH - 1
44
+
45
+ [MINIMUM_OFFSET, offset].max
12
46
  end
13
47
  end
14
48
  end
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-difftastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-21 00:00:00.000000000 Z
11
+ date: 2025-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: difftastic
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.1
27
- description: Minitest Plugin to use difftastic for diffing
27
+ description: Minitest Plugin to use difftastic for failed assertions
28
28
  email:
29
29
  - marco.roth@intergga.ch
30
30
  executables: []
@@ -41,6 +41,10 @@ files:
41
41
  - lib/minitest/difftastic.rb
42
42
  - lib/minitest/difftastic/version.rb
43
43
  - lib/minitest/difftastic_plugin.rb
44
+ - screenshots/integers.png
45
+ - screenshots/nested_objects.png
46
+ - screenshots/objects.png
47
+ - screenshots/strings.png
44
48
  - sig/minitest/difftastic.rbs
45
49
  homepage: https://github.com/marcoroth/minitest-difftastic
46
50
  licenses: []
@@ -57,15 +61,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
61
  requirements:
58
62
  - - ">="
59
63
  - !ruby/object:Gem::Version
60
- version: 3.0.0
64
+ version: 3.1.0
61
65
  required_rubygems_version: !ruby/object:Gem::Requirement
62
66
  requirements:
63
67
  - - ">="
64
68
  - !ruby/object:Gem::Version
65
69
  version: '0'
66
70
  requirements: []
67
- rubygems_version: 3.4.10
71
+ rubygems_version: 3.5.11
68
72
  signing_key:
69
73
  specification_version: 4
70
- summary: Minitest Plugin to use difftastic for diffing
74
+ summary: Minitest Plugin to use difftastic for failed assertions
71
75
  test_files: []