minitest-utils 0.6.5 → 0.7.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: 44367be1237b4e5f4e5b0230f5650b646a9edffe0fcbdaca4a422104543a33c0
4
- data.tar.gz: 3a77f6fcc7b2000742483260695ef3ca19902f9222360ffbb1bab1b3cd96d1b9
3
+ metadata.gz: e8a6552a933ed30c1aa6bc204b5202e7a4e97b6ee131ec1beca251df903c86ff
4
+ data.tar.gz: dd6d52f1f5dfb48b999c351439cb3ea399d19fbd0fae0215778987207914cd1f
5
5
  SHA512:
6
- metadata.gz: 4d26c13ae7ddab46cccee79bb38fcd47f198e380e090bb29d1a332b3cc2363a93206a6c31963853b3bb4d23711e47ad2d75087bc9c5723829f82eb2853e32996
7
- data.tar.gz: ada644bc3f3609b8bc60ff02961b205b592ff63f211bbf3356e7a8b79b2aef8c92dba167fb7d54acca4f47357c495c9a193012673279118c75ea8e6c5c51477d
6
+ metadata.gz: 419d5dcc979dced369d4608d8320e596290645bc62914ed1e28df19999c560146dfbaf720fed8d4efeb9cc0a85b2db93b3bb23ae494ddf426899ab1c7898c5f6
7
+ data.tar.gz: beda5a34b0123a798ac3fb3ac625b9e88b008e4aba0e2bfea773fb0902f7b8412bf81d543fe45a446cd4b7280e47393fb9ce50bbce2a5b15f806eb6d7f6857ce
@@ -12,6 +12,42 @@ module Minitest
12
12
  message ||= "expected: falsy value\ngot: #{mu_pp(test)}"
13
13
  super
14
14
  end
15
+
16
+ def diff(expected, actual)
17
+ expected = mu_pp_for_diff(expected)
18
+ actual = mu_pp_for_diff(actual)
19
+
20
+ a = expected.scan(/\w+|\W+/)
21
+ b = actual.scan(/\w+|\W+/)
22
+
23
+ exp_out = +""
24
+ act_out = +""
25
+
26
+ Diff::LCS
27
+ .sdiff(a, b)
28
+ .chunk_while {|a, b| a.action == b.action }
29
+ .each do |group|
30
+ action = group.first.action
31
+ old_str = group.filter_map(&:old_element).join
32
+ new_str = group.filter_map(&:new_element).join
33
+
34
+ case action
35
+ when "="
36
+ exp_out << old_str
37
+ act_out << new_str
38
+ when "-"
39
+ exp_out << Utils.color(old_str, :red, bgcolor: :red)
40
+ when "+"
41
+ act_out << Utils.color(new_str, :green, bgcolor: :green)
42
+ when "!"
43
+ exp_out << Utils.color(old_str, :red, bgcolor: :red)
44
+ act_out << Utils.color(new_str, :green, bgcolor: :green)
45
+ end
46
+ end
47
+
48
+ "#{Utils.color('expected: ', :red)} #{exp_out}\n" \
49
+ "#{Utils.color(' actual: ', :red)} #{act_out}"
50
+ end
15
51
  end
16
52
  end
17
53
 
@@ -37,6 +73,37 @@ module Minitest
37
73
  :"test_#{method_name}"
38
74
  end
39
75
 
76
+ # This hook handles methods defined directly with `def test_`.
77
+ def self.method_added(method_name)
78
+ super
79
+
80
+ test_name = method_name.to_s
81
+
82
+ return unless test_name.start_with?("test_")
83
+
84
+ klass = name
85
+ id = "#{klass}##{method_name}"
86
+ description = method_name.to_s.delete_prefix("test_").tr("_", " ")
87
+
88
+ return if Test.tests[id]
89
+
90
+ file_path, lineno = instance_method(method_name).source_location
91
+
92
+ source_location = [
93
+ Pathname(file_path).relative_path_from(Pathname(Dir.pwd)),
94
+ lineno
95
+ ]
96
+
97
+ Test.tests[id] = {
98
+ id:,
99
+ description:,
100
+ name: test_name,
101
+ source_location:,
102
+ time: nil,
103
+ slow_threshold:
104
+ }
105
+ end
106
+
40
107
  def self.test(description, &block)
41
108
  source_location = caller_locations(1..1).first
42
109
  source_location = [
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minitest
4
4
  module Utils
5
- VERSION = "0.6.5"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
@@ -10,25 +10,22 @@ module Minitest
10
10
  module Utils
11
11
  require "minitest"
12
12
  require "pathname"
13
+ require "diff/lcs"
13
14
  require_relative "utils/version"
14
15
  require_relative "utils/reporter"
15
16
  require_relative "utils/extension"
16
17
 
17
- COLOR = {
18
- red: 31,
19
- green: 32,
20
- yellow: 33,
21
- blue: 34,
22
- gray: 37
23
- }.freeze
24
-
25
- def self.color(string, color = :default)
26
- if color_enabled?
27
- color = COLOR.fetch(color, 0)
28
- "\e[#{color}m#{string}\e[0m"
29
- else
30
- string
31
- end
18
+ COLOR = {red: 31, green: 32, yellow: 33, blue: 34, gray: 37}.freeze
19
+ BGCOLOR = {red: 41, green: 42, yellow: 43, blue: 44, gray: 47}.freeze
20
+
21
+ def self.color(string, color = :default, bgcolor: nil)
22
+ return string unless color_enabled?
23
+
24
+ fg = COLOR.fetch(color, 0)
25
+ bg = BGCOLOR.fetch(bgcolor, nil)
26
+
27
+ code = [fg, bg].compact.join(";")
28
+ "\e[#{code}m#{string}\e[0m"
32
29
  end
33
30
 
34
31
  def self.color_enabled?
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_dependency "diff-lcs"
22
23
  spec.add_dependency "listen"
23
24
  spec.add_dependency "minitest"
24
25
  spec.add_development_dependency "bundler"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -9,6 +9,20 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: diff-lcs
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: listen
14
28
  requirement: !ruby/object:Gem::Requirement