minitest-utils 0.5.0 → 0.5.1
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/lib/minitest/utils/extension.rb +16 -10
- data/lib/minitest/utils/reporter.rb +11 -14
- data/lib/minitest/utils/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b70bd66e3c107ed99a78f3521ed7662a105f13109b54ce4d4c23039676ec63d
|
4
|
+
data.tar.gz: 3448ddcfaadfa6c22d61bb2918044b8769aa9c9ca41932caaace1e5d527065dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f2f262a6756480cfbecf5e2facd19edcbbae57a96065043cd5a6a1e30c2b68c073f16b06a1948172fcfcd344200d989d66a538621e28e9f2ed5e9445d08391c
|
7
|
+
data.tar.gz: 3d83de0fcb3dc1e2a3b309fcf1eb4a95067abbd94385399ccb59964b5b7dff8a038a6a408f94c3849b1172e033d297c8355a7b350c77a9835b9c229716b94692
|
@@ -19,27 +19,33 @@ module Minitest
|
|
19
19
|
include ::Minitest::Utils::Assertions
|
20
20
|
|
21
21
|
def self.tests
|
22
|
-
@tests ||=
|
22
|
+
@tests ||= {}
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.test(name, &block)
|
26
26
|
source_location = caller_locations(1..1).first
|
27
|
+
source_location = [
|
28
|
+
Pathname(source_location.path).relative_path_from(Pathname(Dir.pwd)),
|
29
|
+
source_location.lineno
|
30
|
+
]
|
31
|
+
|
32
|
+
klass = self.name
|
27
33
|
method_name = name.downcase
|
28
34
|
.gsub(/[^a-z0-9]+/, "_")
|
29
35
|
.gsub(/^_+/, "")
|
30
36
|
.gsub(/_+$/, "").squeeze("_")
|
31
37
|
test_name = "test_#{method_name}".to_sym
|
32
|
-
defined = method_defined?
|
38
|
+
defined = method_defined?(test_name)
|
39
|
+
|
40
|
+
Test.tests["#{klass}##{test_name}"] = {
|
41
|
+
name: name,
|
42
|
+
source_location:,
|
43
|
+
benchmark: nil
|
44
|
+
}
|
45
|
+
|
33
46
|
testable = proc do
|
34
47
|
benchmark = Benchmark.measure { instance_eval(&block) }
|
35
|
-
|
36
|
-
Test.tests << {
|
37
|
-
class: self.class,
|
38
|
-
name: name,
|
39
|
-
test_name: test_name,
|
40
|
-
benchmark: benchmark,
|
41
|
-
source_location:
|
42
|
-
}
|
48
|
+
Test.tests["#{klass}##{test_name}"][:benchmark] = benchmark
|
43
49
|
end
|
44
50
|
|
45
51
|
raise "#{test_name} is already defined in #{self}" if defined
|
@@ -68,20 +68,22 @@ module Minitest
|
|
68
68
|
failing_results.each {|result| display_replay_command(result) }
|
69
69
|
io.puts "\n\n"
|
70
70
|
else
|
71
|
-
io.puts "\nSlow Tests:\n"
|
72
71
|
threshold = 0.1 # 100ms
|
73
72
|
test_results =
|
74
73
|
Test
|
75
74
|
.tests
|
75
|
+
.values
|
76
|
+
.select { _1[:benchmark] }
|
76
77
|
.sort_by { _1[:benchmark].total }
|
77
78
|
.reverse
|
78
79
|
.take(10).filter { _1[:benchmark].total > threshold }
|
79
|
-
|
80
|
+
|
81
|
+
return unless test_results.any?
|
82
|
+
|
83
|
+
io.puts "\nSlow Tests:\n"
|
80
84
|
|
81
85
|
test_results.each_with_index do |info, index|
|
82
|
-
|
83
|
-
.relative_path_from(pwd)
|
84
|
-
location = "#{relative_path}:#{info[:source_location].lineno}"
|
86
|
+
location = info[:source_location].join(":")
|
85
87
|
duration = humanize_duration(info[:benchmark].total * 1_000_000_000)
|
86
88
|
|
87
89
|
prefix = "#{index + 1}) "
|
@@ -164,15 +166,9 @@ module Minitest
|
|
164
166
|
end
|
165
167
|
|
166
168
|
private def find_test_file(result)
|
167
|
-
|
168
|
-
result.source_location
|
169
|
-
else
|
170
|
-
result.method(result.name).source_location
|
171
|
-
end
|
172
|
-
|
173
|
-
location = location.gsub(%r{^.*?/((?:test|spec)/.*?)$}, "\\1")
|
169
|
+
info = Test.tests.fetch("#{result.klass}##{result.name}")
|
174
170
|
|
175
|
-
[
|
171
|
+
info[:source_location]
|
176
172
|
end
|
177
173
|
|
178
174
|
private def backtrace(backtrace)
|
@@ -199,7 +195,8 @@ module Minitest
|
|
199
195
|
end
|
200
196
|
|
201
197
|
private def filter_backtrace(backtrace)
|
202
|
-
|
198
|
+
# drop the last line, which is from benchmark.
|
199
|
+
Minitest.backtrace_filter.filter(backtrace)[0..-2]
|
203
200
|
end
|
204
201
|
|
205
202
|
private def result_name(name)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02-
|
10
|
+
date: 2025-02-25 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: benchmark
|
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
- !ruby/object:Gem::Version
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
|
-
rubygems_version: 3.6.
|
179
|
+
rubygems_version: 3.6.4
|
180
180
|
specification_version: 4
|
181
181
|
summary: Some utilities for your Minitest day-to-day usage.
|
182
182
|
test_files: []
|