minitest-utils 0.4.10 → 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/.rubocop.yml +4 -1
- data/lib/minitest/utils/extension.rb +30 -9
- data/lib/minitest/utils/rails/capybara.rb +1 -1
- data/lib/minitest/utils/reporter.rb +48 -14
- data/lib/minitest/utils/version.rb +1 -1
- data/lib/minitest/utils.rb +2 -0
- data/minitest-utils.gemspec +2 -1
- metadata +18 -4
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
|
data/.rubocop.yml
CHANGED
@@ -18,19 +18,40 @@ module Minitest
|
|
18
18
|
class Test
|
19
19
|
include ::Minitest::Utils::Assertions
|
20
20
|
|
21
|
+
def self.tests
|
22
|
+
@tests ||= {}
|
23
|
+
end
|
24
|
+
|
21
25
|
def self.test(name, &block)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
33
|
+
method_name = name.downcase
|
34
|
+
.gsub(/[^a-z0-9]+/, "_")
|
35
|
+
.gsub(/^_+/, "")
|
36
|
+
.gsub(/_+$/, "").squeeze("_")
|
37
|
+
test_name = "test_#{method_name}".to_sym
|
38
|
+
defined = method_defined?(test_name)
|
39
|
+
|
40
|
+
Test.tests["#{klass}##{test_name}"] = {
|
41
|
+
name: name,
|
42
|
+
source_location:,
|
43
|
+
benchmark: nil
|
44
|
+
}
|
45
|
+
|
46
|
+
testable = proc do
|
47
|
+
benchmark = Benchmark.measure { instance_eval(&block) }
|
48
|
+
Test.tests["#{klass}##{test_name}"][:benchmark] = benchmark
|
49
|
+
end
|
29
50
|
|
30
51
|
raise "#{test_name} is already defined in #{self}" if defined
|
31
52
|
|
32
|
-
if
|
33
|
-
define_method(test_name, &
|
53
|
+
if block
|
54
|
+
define_method(test_name, &testable)
|
34
55
|
else
|
35
56
|
define_method(test_name) do
|
36
57
|
flunk "No implementation provided for #{name}"
|
@@ -14,7 +14,8 @@ module Minitest
|
|
14
14
|
red: 31,
|
15
15
|
green: 32,
|
16
16
|
yellow: 33,
|
17
|
-
blue: 34
|
17
|
+
blue: 34,
|
18
|
+
gray: 37
|
18
19
|
}.freeze
|
19
20
|
|
20
21
|
def initialize(*)
|
@@ -62,11 +63,49 @@ module Minitest
|
|
62
63
|
io.puts statistics
|
63
64
|
io.puts color(summary, color)
|
64
65
|
|
65
|
-
|
66
|
+
if failing_results.any?
|
67
|
+
io.puts "\nFailed Tests:\n"
|
68
|
+
failing_results.each {|result| display_replay_command(result) }
|
69
|
+
io.puts "\n\n"
|
70
|
+
else
|
71
|
+
threshold = 0.1 # 100ms
|
72
|
+
test_results =
|
73
|
+
Test
|
74
|
+
.tests
|
75
|
+
.values
|
76
|
+
.select { _1[:benchmark] }
|
77
|
+
.sort_by { _1[:benchmark].total }
|
78
|
+
.reverse
|
79
|
+
.take(10).filter { _1[:benchmark].total > threshold }
|
80
|
+
|
81
|
+
return unless test_results.any?
|
82
|
+
|
83
|
+
io.puts "\nSlow Tests:\n"
|
84
|
+
|
85
|
+
test_results.each_with_index do |info, index|
|
86
|
+
location = info[:source_location].join(":")
|
87
|
+
duration = humanize_duration(info[:benchmark].total * 1_000_000_000)
|
88
|
+
|
89
|
+
prefix = "#{index + 1}) "
|
90
|
+
padding = " " * prefix.size
|
91
|
+
|
92
|
+
io.puts color("#{prefix}#{info[:name]} (#{duration})", :red)
|
93
|
+
io.puts color("#{padding}#{location}", :gray)
|
94
|
+
io.puts
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
66
98
|
|
67
|
-
|
68
|
-
|
69
|
-
|
99
|
+
private def humanize_duration(duration_ns)
|
100
|
+
if duration_ns < 1000
|
101
|
+
format("%.2f ns", duration_ns)
|
102
|
+
elsif duration_ns < 1_000_000
|
103
|
+
format("%.2f μs", (duration_ns / 1000))
|
104
|
+
elsif duration_ns < 1_000_000_000
|
105
|
+
format("%.2f ms", (duration_ns / 1_000_000))
|
106
|
+
else
|
107
|
+
format("%.2f s", (duration_ns / 1_000_000_000))
|
108
|
+
end
|
70
109
|
end
|
71
110
|
|
72
111
|
private def statistics
|
@@ -127,15 +166,9 @@ module Minitest
|
|
127
166
|
end
|
128
167
|
|
129
168
|
private def find_test_file(result)
|
130
|
-
|
131
|
-
result.source_location
|
132
|
-
else
|
133
|
-
result.method(result.name).source_location
|
134
|
-
end
|
135
|
-
|
136
|
-
location = location.gsub(%r{^.*?/((?:test|spec)/.*?)$}, "\\1")
|
169
|
+
info = Test.tests.fetch("#{result.klass}##{result.name}")
|
137
170
|
|
138
|
-
[
|
171
|
+
info[:source_location]
|
139
172
|
end
|
140
173
|
|
141
174
|
private def backtrace(backtrace)
|
@@ -162,7 +195,8 @@ module Minitest
|
|
162
195
|
end
|
163
196
|
|
164
197
|
private def filter_backtrace(backtrace)
|
165
|
-
|
198
|
+
# drop the last line, which is from benchmark.
|
199
|
+
Minitest.backtrace_filter.filter(backtrace)[0..-2]
|
166
200
|
end
|
167
201
|
|
168
202
|
private def result_name(name)
|
data/lib/minitest/utils.rb
CHANGED
data/minitest-utils.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.summary = "Some utilities for your Minitest day-to-day usage."
|
11
11
|
spec.description = spec.summary
|
12
12
|
spec.homepage = "http://github.com/fnando/minitest-utils"
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`
|
16
16
|
.split("\x0")
|
@@ -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 "benchmark"
|
22
23
|
spec.add_dependency "minitest"
|
23
24
|
spec.add_development_dependency "bundler"
|
24
25
|
spec.add_development_dependency "pry-meta"
|
metadata
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
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
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: benchmark
|
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: minitest
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,14 +169,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
169
|
requirements:
|
156
170
|
- - ">="
|
157
171
|
- !ruby/object:Gem::Version
|
158
|
-
version: 2.
|
172
|
+
version: 3.2.0
|
159
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
174
|
requirements:
|
161
175
|
- - ">="
|
162
176
|
- !ruby/object:Gem::Version
|
163
177
|
version: '0'
|
164
178
|
requirements: []
|
165
|
-
rubygems_version: 3.6.
|
179
|
+
rubygems_version: 3.6.4
|
166
180
|
specification_version: 4
|
167
181
|
summary: Some utilities for your Minitest day-to-day usage.
|
168
182
|
test_files: []
|