minitest-utils 0.5.4 → 0.5.6

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: 765e579ace2e449f2027460fa1cd9e1ac4b9afe3df956e3eedfddc7da3dd618b
4
- data.tar.gz: f5ebfd7e4ef738f9d9c011f7b75d12e9bff2b4cfab8b1efa34c32fdfc1f49fac
3
+ metadata.gz: 2dd3332349124b344a5c54b49a5a68b625a5866438350ecb8753d196748bf979
4
+ data.tar.gz: 99785612b3df911aa58f0975740001532cb11be661266a4d90b8d936a9243c4e
5
5
  SHA512:
6
- metadata.gz: ec2a28516db56dcd7ea16b2146233bbf3a68b37d3a8cf228b7c434d740e215a80ed5c97caffbdda5f199dd9574470484e2624791aed7a5e4e7f728bad9a8d305
7
- data.tar.gz: a60f6a8c68fdea440a4ecd41b3d343c0210dc891010ee1ecf50fcb783ef970742fee507bf67f610bdcd30b4495b8e6d75d77c5b81d2794abbf6b9f42352b2497
6
+ metadata.gz: a22c26e74ffca9d640b87610400d1d5898cec8aa00d969ce7ac6f97c75562a4f5e189f3a74faafc12fe1214b7115e81f160190e3480a4faed2e04128f1e18345
7
+ data.tar.gz: 70c5322c8d76806706e0721360785d983ffb5697e09bafcd97fa4e89557dee62cfc5e99888a92d9ee58db5ba4800e02ebfd92b57c5f7f68e4ab4dc678ac73001
@@ -22,7 +22,16 @@ module Minitest
22
22
  @tests ||= {}
23
23
  end
24
24
 
25
- def self.test(name, &block)
25
+ def self.test_method_name(description)
26
+ method_name = description.downcase
27
+ .gsub(/[^a-z0-9]+/, "_")
28
+ .gsub(/^_+/, "")
29
+ .gsub(/_+$/, "")
30
+ .squeeze("_")
31
+ "test_#{method_name}".to_sym
32
+ end
33
+
34
+ def self.test(description, &block)
26
35
  source_location = caller_locations(1..1).first
27
36
  source_location = [
28
37
  Pathname(source_location.path).relative_path_from(Pathname(Dir.pwd)),
@@ -30,14 +39,11 @@ module Minitest
30
39
  ]
31
40
 
32
41
  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
42
+ test_name = test_method_name(description)
38
43
  defined = method_defined?(test_name)
39
44
 
40
45
  Test.tests["#{klass}##{test_name}"] = {
46
+ description:,
41
47
  name: name,
42
48
  source_location:,
43
49
  benchmark: nil
@@ -3,6 +3,10 @@
3
3
  module Minitest
4
4
  module Utils
5
5
  class Reporter < Minitest::StatisticsReporter
6
+ def self.filters
7
+ @filters ||= [/'Benchmark.measure'/]
8
+ end
9
+
6
10
  COLOR_FOR_RESULT_CODE = {
7
11
  "." => :green,
8
12
  "E" => :red,
@@ -154,10 +158,10 @@ module Minitest
154
158
  end
155
159
 
156
160
  private def display_replay_command(result)
157
- location, line = find_test_file(result)
158
- return if location.empty?
161
+ test = find_test_file(result)
162
+ return if test[:source_location].empty?
159
163
 
160
- command = build_test_command(location, line, result)
164
+ command = build_test_command(test, result)
161
165
 
162
166
  output = ["\n"]
163
167
  output << color(command, :red)
@@ -166,9 +170,7 @@ module Minitest
166
170
  end
167
171
 
168
172
  private def find_test_file(result)
169
- info = Test.tests.fetch("#{result.klass}##{result.name}")
170
-
171
- info[:source_location]
173
+ Test.tests.fetch("#{result.klass}##{result.name}")
172
174
  end
173
175
 
174
176
  private def backtrace(backtrace)
@@ -195,11 +197,14 @@ module Minitest
195
197
 
196
198
  return location unless location.start_with?(Dir.pwd)
197
199
 
198
- location.gsub(%r{^#{Regexp.escape(Dir.pwd)}/}, "")
200
+ location.delete_prefix("#{Dir.pwd}/")
199
201
  end
200
202
 
201
203
  private def filter_backtrace(backtrace)
202
- Minitest.backtrace_filter.filter(backtrace)
204
+ Minitest.backtrace_filter
205
+ .filter(backtrace)
206
+ .reject {|line| Reporter.filters.any? { line.match?(_1) } }
207
+ .reject {|line| !line.start_with?(Dir.pwd) }
203
208
  end
204
209
 
205
210
  private def result_name(name)
@@ -243,12 +248,15 @@ module Minitest
243
248
  Rails.version >= "5.0.0"
244
249
  end
245
250
 
246
- private def build_test_command(location, line, result)
251
+ private def build_test_command(test, result)
252
+ location, line = test[:source_location]
253
+
247
254
  if ENV["MINITEST_TEST_COMMAND"]
248
255
  return format(
249
256
  ENV["MINITEST_TEST_COMMAND"],
250
257
  location: location,
251
258
  line: line,
259
+ description: test[:description],
252
260
  name: result.name
253
261
  )
254
262
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minitest
4
4
  module Utils
5
- VERSION = "0.5.4"
5
+ VERSION = "0.5.6"
6
6
  end
7
7
  end
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
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-01 00:00:00.000000000 Z
10
+ date: 2025-03-11 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.2
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: []