minitest-difftastic 0.1.1 → 0.2.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: 692dd87d40229d2fea8ac5e00900e45ae33ec436b33f22d98027037f5448ef22
4
- data.tar.gz: d1f4de4c6be40d5bdcd5efed3907ecfc52725d15f8d7606083c0d34b4904e142
3
+ metadata.gz: ba6f4034a1edfc83d1b99e6640c23ce34a37dfd77a5680c60facbdb67ea06d47
4
+ data.tar.gz: 9e9b7c26ce30d9349dc8f46604ffff52ef08d299a6b59e9e93e4501dcb0df3e4
5
5
  SHA512:
6
- metadata.gz: 16c1ffb8e443e9423074ec083cc94f7c90121c44590ca7559ae6e0ed6ba75e4d7bec2b293f576e22a7dd4d48487a20c63ca6e0c28a94355d1f6972e3917f0afb
7
- data.tar.gz: fb8c0fa64bed4a4d163a295343083b37418cd27ade769f2b8cb71d1dd6f2f8fbd116d0838b5fdd5e19de0411638c8a503ebf9177a25af55ae493c4865914d0f3
6
+ metadata.gz: f524a77c4b54560126dd7badf0ee0bdaac377417027381703ff1bd6c48595153458f1a980996111c5d08693addb7fb376eeac5dedf349ea28e51a48a868c919c
7
+ data.tar.gz: c9162af19d34273740a9c7176e6ce2961713e8610f596aae6be30f2ce98dcdf4784e7506943019706c9655e2df7d94b1475dd59b675a05deea009df0adedc599
data/.rubocop.yml CHANGED
@@ -7,6 +7,9 @@ Style/StringLiterals:
7
7
  Enabled: true
8
8
  EnforcedStyle: double_quotes
9
9
 
10
+ Style/ClassAndModuleChildren:
11
+ Enabled: false
12
+
10
13
  Style/Documentation:
11
14
  Enabled: false
12
15
 
@@ -14,5 +17,19 @@ Style/StringLiteralsInInterpolation:
14
17
  Enabled: true
15
18
  EnforcedStyle: double_quotes
16
19
 
20
+ Style/WordArray:
21
+ Enabled: false
22
+
23
+ Style/BlockDelimiters:
24
+ Enabled: false
25
+
26
+ Metrics/MethodLength:
27
+ Max: 20
28
+
17
29
  Layout/LineLength:
18
30
  Max: 120
31
+
32
+ Metrics/MethodLength:
33
+ Max: 20
34
+ Include:
35
+ - examples/**/*
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ gemspec
6
6
 
7
7
  gem "minitest", "~> 5.0"
8
8
  gem "rake", "~> 13.0"
9
- gem "rubocop", "~> 1.21"
9
+ gem "rubocop", "~> 1.71"
data/Gemfile.lock CHANGED
@@ -1,44 +1,49 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minitest-difftastic (0.1.1)
5
- difftastic (~> 0.0.1)
4
+ minitest-difftastic (0.2.0)
5
+ difftastic (~> 0.6)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.2)
11
- base64 (0.1.1)
12
- difftastic (0.0.1-arm64-darwin)
13
- difftastic (0.0.1-x86_64-linux)
14
- json (2.6.3)
11
+ difftastic (0.6.0-arm64-darwin)
12
+ pretty_please
13
+ difftastic (0.6.0-x86_64-linux)
14
+ pretty_please
15
+ dispersion (0.2.0)
16
+ prism
17
+ json (2.9.1)
15
18
  language_server-protocol (3.17.0.3)
16
19
  minitest (5.25.4)
17
- parallel (1.23.0)
18
- parser (3.2.2.4)
20
+ parallel (1.26.3)
21
+ parser (3.3.7.0)
19
22
  ast (~> 2.4.1)
20
23
  racc
24
+ pretty_please (0.2.0)
25
+ dispersion (~> 0.2)
26
+ prism (1.3.0)
21
27
  racc (1.8.1)
22
28
  rainbow (3.1.1)
23
29
  rake (13.2.1)
24
- regexp_parser (2.9.2)
25
- rexml (3.2.6)
26
- rubocop (1.56.2)
27
- base64 (~> 0.1.1)
30
+ regexp_parser (2.10.0)
31
+ rubocop (1.71.0)
28
32
  json (~> 2.3)
29
33
  language_server-protocol (>= 3.17.0)
30
34
  parallel (~> 1.10)
31
- parser (>= 3.2.2.3)
35
+ parser (>= 3.3.0.2)
32
36
  rainbow (>= 2.2.2, < 4.0)
33
- regexp_parser (>= 1.8, < 3.0)
34
- rexml (>= 3.2.5, < 4.0)
35
- rubocop-ast (>= 1.28.1, < 2.0)
37
+ regexp_parser (>= 2.9.3, < 3.0)
38
+ rubocop-ast (>= 1.36.2, < 2.0)
36
39
  ruby-progressbar (~> 1.7)
37
- unicode-display_width (>= 2.4.0, < 3.0)
38
- rubocop-ast (1.29.0)
39
- parser (>= 3.2.1.0)
40
+ unicode-display_width (>= 2.4.0, < 4.0)
41
+ rubocop-ast (1.37.0)
42
+ parser (>= 3.3.1.0)
40
43
  ruby-progressbar (1.13.0)
41
- unicode-display_width (2.6.0)
44
+ unicode-display_width (3.1.4)
45
+ unicode-emoji (~> 4.0, >= 4.0.4)
46
+ unicode-emoji (4.0.4)
42
47
 
43
48
  PLATFORMS
44
49
  arm64-darwin-24
@@ -48,7 +53,7 @@ DEPENDENCIES
48
53
  minitest (~> 5.0)
49
54
  minitest-difftastic!
50
55
  rake (~> 13.0)
51
- rubocop (~> 1.21)
56
+ rubocop (~> 1.71)
52
57
 
53
58
  BUNDLED WITH
54
59
  2.4.12
data/README.md CHANGED
@@ -4,6 +4,28 @@ A Minitest Plugin which uses [`difftastic`](https://github.com/Wilfred/difftasti
4
4
 
5
5
  Also works for Rails tests using `ActiveSupport::TestCase`.
6
6
 
7
+ ## Try it yourself
8
+
9
+ Clone this repo, run `bundle install` and then `rake examples` in your terminal.
10
+
11
+ ```ruby
12
+ rake examples
13
+ ```
14
+
15
+ You will get a few failing assertions printed to your terminal.
16
+
17
+ ```
18
+ Failure:
19
+ Examples::AssertEqual#test_assert_equal [examples/assert_equal.rb:8]:
20
+
21
+ Expected Actual
22
+ 1 "Hello World" 1 "Hello Difftastic"
23
+ ```
24
+
25
+ You can also look at the source code for the examples in the [`examples/`](https://github.com/marcoroth/minitest-difftastic/tree/main/examples) folder.
26
+
27
+ ## Screenshots
28
+
7
29
  ### Integers
8
30
 
9
31
  ![Integers Comparison](./screenshots/integers.png)
@@ -22,10 +44,10 @@ Also works for Rails tests using `ActiveSupport::TestCase`.
22
44
 
23
45
  ## Installation
24
46
 
25
- Install the gem and add to the application's Gemfile by executing:
47
+ Install the gem and add to the application's Gemfile `test` group by executing:
26
48
 
27
49
  ```shell
28
- bundle add minitest-difftastic
50
+ bundle add minitest-difftastic --group=test
29
51
  ```
30
52
 
31
53
  If bundler is not being used to manage dependencies, install the gem by executing:
data/Rakefile CHANGED
@@ -6,7 +6,13 @@ require "rake/testtask"
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
8
8
  t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ Rake::TestTask.new(:examples) do |t|
13
+ t.libs << "examples"
14
+ t.libs << "lib"
15
+ t.test_files = FileList["examples/**/assert_*.rb"]
10
16
  end
11
17
 
12
18
  require "rubocop/rake_task"
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "example_helper"
4
+
5
+ module Examples
6
+ class AssertEqual < Minitest::Test
7
+ def test_assert_equal_string
8
+ assert_equal "Hello World", "Hello Difftastic"
9
+ end
10
+
11
+ def test_assert_equal_with_nil
12
+ assert_equal nil, "nil"
13
+ end
14
+
15
+ def test_assert_equal_with_integer
16
+ assert_equal 1, "1"
17
+ end
18
+
19
+ def test_assert_equal_with_hash
20
+ assert_equal({ id: 1 }, { id: 2 })
21
+ end
22
+
23
+ def test_assert_equal_with_nested_hash
24
+ expected = {
25
+ id: 1,
26
+ data: {
27
+ name: "John A.",
28
+ tags: ["tag1", "tag2", "tag3"]
29
+ }
30
+ }
31
+
32
+ actual = {
33
+ id: 1,
34
+ data: {
35
+ name: "John B.",
36
+ tags: ["tag1", "tag3", "tag2"]
37
+ }
38
+ }
39
+
40
+ assert_equal expected, actual
41
+ end
42
+
43
+ def test_assert_equal_string_with_newlines
44
+ expected = <<~RUBY
45
+ class User < ApplicationRecord
46
+ has_many :posts
47
+ end
48
+ RUBY
49
+
50
+ actual = <<~RUBY
51
+ class User < ApplicationRecord
52
+ has_many :posts
53
+ ^^^^^^^^^^^^^^^ Rubocop::SomeRule Missing association to `organization`
54
+ end
55
+ RUBY
56
+
57
+ assert_equal expected, actual
58
+ end
59
+
60
+ def test_assert_equal_string_with_newlines_on_one_side
61
+ expected = <<~RUBY
62
+ Hello
63
+
64
+ World
65
+ RUBY
66
+
67
+ actual = "Hello"
68
+
69
+ assert_equal expected, actual
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "example_helper"
4
+
5
+ module Examples
6
+ class AssertNil < Minitest::Test
7
+ def test_assert_nil_with_string
8
+ assert_nil "String"
9
+ end
10
+
11
+ def test_assert_nil_with_nil
12
+ assert_nil nil
13
+ end
14
+
15
+ def test_assert_nil_with_true
16
+ assert_nil true
17
+ end
18
+
19
+ def test_assert_nil_with_false
20
+ assert_nil false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "example_helper"
4
+
5
+ module Examples
6
+ class AssertOperator < Minitest::Test
7
+ def test_operator_case_equality
8
+ assert_operator "Left", :===, "Right"
9
+ end
10
+
11
+ def test_operator_eql
12
+ assert_operator 1, :eql?, 1.0
13
+ end
14
+
15
+ def test_operator_equal
16
+ assert_operator 1, :equal?, 1.0
17
+ end
18
+
19
+ def test_operator_lt
20
+ assert_operator 1, :>, 2
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "example_helper"
4
+
5
+ module Examples
6
+ class AssertPredicate < Minitest::Test
7
+ def test_assert_predicate_array_empty
8
+ assert_predicate [1], :empty?
9
+ end
10
+
11
+ def test_assert_predicate_string_empty
12
+ assert_predicate "1", :empty?
13
+ end
14
+
15
+ def test_assert_predicate_object_empty
16
+ assert_predicate({ id: 1 }, :empty?)
17
+ end
18
+
19
+ def test_assert_predicate_string_frozen
20
+ assert_predicate(+"", :frozen?)
21
+ end
22
+
23
+ def test_assert_predicate_with_custom_method
24
+ return if Gem::Version.new(RUBY_VERSION) < "3.2"
25
+
26
+ test = Data.define(:enabled) do
27
+ def self.name
28
+ "Config"
29
+ end
30
+
31
+ def enabled?
32
+ enabled
33
+ end
34
+ end
35
+
36
+ assert_predicate test.new(enabled: false), :enabled?
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+
5
+ require "minitest/difftastic"
6
+ require "minitest/autorun"
7
+
8
+ require "set"
9
+ require "date"
10
+ require "pathname"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Difftastic
4
+ module Patches
5
+ module AssertNil
6
+ def assert_nil(obj, msg = nil)
7
+ msg ||= message(nil, "") {
8
+ differ = ::Difftastic::Differ.new(
9
+ color: :always,
10
+ tab_width: 2,
11
+ syntax_highlight: :off,
12
+ left_label: "Expected",
13
+ right_label: "Actual"
14
+ )
15
+
16
+ "\n#{differ.diff_objects(nil, obj)}"
17
+ }
18
+ super
19
+ rescue StandardError
20
+ super
21
+ end
22
+
23
+ Minitest::Assertions.prepend(self)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Difftastic
4
+ module Patches
5
+ module AssertOperator
6
+ def assert_operator(object1, operator, object2 = UNDEFINED, msg = nil)
7
+ msg ||= message(nil, "") {
8
+ differ = ::Difftastic::Differ.new(
9
+ color: :always,
10
+ tab_width: 2,
11
+ syntax_highlight: :off,
12
+ left_label: "Expected",
13
+ right_label: "to be #{operator}"
14
+ )
15
+
16
+ "\n#{differ.diff_objects(object1, object2)}"
17
+ }
18
+
19
+ super
20
+ rescue StandardError
21
+ super
22
+ end
23
+
24
+ Minitest::Assertions.prepend(self)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Difftastic
4
+ module Patches
5
+ module AssertPredicate
6
+ def assert_predicate(object, predicate, msg = nil)
7
+ msg ||= message(nil, "") {
8
+ pretty = Difftastic.pretty(object)
9
+
10
+ expected = <<~RUBY
11
+ #{pretty}.#{predicate}
12
+
13
+ # => true
14
+ RUBY
15
+
16
+ actual = <<~RUBY
17
+ #{pretty}.#{predicate}
18
+
19
+ # => false
20
+ RUBY
21
+
22
+ differ = ::Difftastic::Differ.new(
23
+ color: :always,
24
+ tab_width: 2,
25
+ syntax_highlight: :on,
26
+ left_label: "Expected",
27
+ right_label: "Actual",
28
+ context: expected.lines.count
29
+ )
30
+
31
+ "\n#{differ.diff_ruby(expected, actual)}"
32
+ }
33
+
34
+ super
35
+ rescue StandardError
36
+ super
37
+ end
38
+
39
+ Minitest::Assertions.prepend(self)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Difftastic
4
+ module Patches
5
+ module Diff
6
+ def diff(exp, act)
7
+ case [exp, act]
8
+ in [String => exp, String => act] if exp.include?("\n") || act.include?("\n")
9
+ "\n#{::Minitest::Difftastic::STRING_DIFFER.diff_strings(exp, act)}"
10
+ else
11
+ "\n#{::Minitest::Difftastic::DEFAULT_DIFFER.diff_objects(exp, act)}"
12
+ end
13
+ rescue StandardError => e
14
+ puts "Minitest::Difftastic error: #{e.inspect} (#{e.backtrace[0]})"
15
+ super
16
+ end
17
+
18
+ Minitest::Assertions.prepend(self)
19
+ end
20
+ end
21
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minitest
4
4
  module Difftastic
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -1,8 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "difftastic/version"
3
+ require "difftastic"
4
4
 
5
- module Minitest
6
- module Difftastic
7
- end
5
+ require "minitest/difftastic/version"
6
+
7
+ module Minitest::Difftastic
8
+ DEFAULT_DIFFER = ::Difftastic::Differ.new(
9
+ color: :always,
10
+ tab_width: 2,
11
+ syntax_highlight: :off,
12
+ left_label: "Expected",
13
+ right_label: "Actual"
14
+ )
15
+
16
+ STRING_DIFFER = ::Difftastic::Differ.new(
17
+ color: :always,
18
+ tab_width: 2,
19
+ syntax_highlight: :off,
20
+ left_label: "Expected (String)",
21
+ right_label: "Actual (String)"
22
+ )
8
23
  end
@@ -1,48 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "difftastic"
3
+ require "minitest/difftastic"
4
4
 
5
- # TODO: use refinements
6
- module Minitest
7
- module Assertions
8
- MINIMUM_OFFSET = 29
9
- TAB_WIDTH = 2
5
+ require "minitest/difftastic/patches/diff"
10
6
 
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
-
23
- def diff(exp, act)
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
46
- end
47
- end
48
- end
7
+ require "minitest/difftastic/patches/assert_nil"
8
+ require "minitest/difftastic/patches/assert_operator"
9
+ require "minitest/difftastic/patches/assert_predicate"
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.1
4
+ version: 0.2.0
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-22 00:00:00.000000000 Z
11
+ date: 2025-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: difftastic
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.1
19
+ version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.1
26
+ version: '0.6'
27
27
  description: Minitest Plugin to use difftastic for failed assertions
28
28
  email:
29
29
  - marco.roth@intergga.ch
@@ -38,7 +38,16 @@ files:
38
38
  - Gemfile.lock
39
39
  - README.md
40
40
  - Rakefile
41
+ - examples/assert_equal.rb
42
+ - examples/assert_nil.rb
43
+ - examples/assert_operator.rb
44
+ - examples/assert_predicate.rb
45
+ - examples/example_helper.rb
41
46
  - lib/minitest/difftastic.rb
47
+ - lib/minitest/difftastic/patches/assert_nil.rb
48
+ - lib/minitest/difftastic/patches/assert_operator.rb
49
+ - lib/minitest/difftastic/patches/assert_predicate.rb
50
+ - lib/minitest/difftastic/patches/diff.rb
42
51
  - lib/minitest/difftastic/version.rb
43
52
  - lib/minitest/difftastic_plugin.rb
44
53
  - screenshots/integers.png
@@ -68,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
77
  - !ruby/object:Gem::Version
69
78
  version: '0'
70
79
  requirements: []
71
- rubygems_version: 3.5.11
80
+ rubygems_version: 3.3.7
72
81
  signing_key:
73
82
  specification_version: 4
74
83
  summary: Minitest Plugin to use difftastic for failed assertions