minitest 5.23.1 → 5.25.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/minitest/mock.rb CHANGED
@@ -8,7 +8,7 @@ module Minitest # :nodoc:
8
8
  # All mock objects are an instance of Mock
9
9
 
10
10
  class Mock
11
- alias :__respond_to? :respond_to?
11
+ alias __respond_to? respond_to?
12
12
 
13
13
  overridden_methods = %i[
14
14
  ===
@@ -93,7 +93,7 @@ module Minitest # :nodoc:
93
93
  def expect name, retval, args = [], **kwargs, &blk
94
94
  name = name.to_sym
95
95
 
96
- if block_given?
96
+ if blk then
97
97
  raise ArgumentError, "args ignored when block given" unless args.empty?
98
98
  raise ArgumentError, "kwargs ignored when block given" unless kwargs.empty?
99
99
  @expected_calls[name] << { :retval => retval, :block => blk }
@@ -106,7 +106,7 @@ module Minitest # :nodoc:
106
106
  kwargs = args.pop
107
107
  else
108
108
  unless @@KW_WARNED then
109
- from = caller.first
109
+ from = caller(1..1).first
110
110
  warn "Using MT_KWARGS_HAC\K yet passing kwargs. From #{from}"
111
111
  @@KW_WARNED = true
112
112
  end
@@ -141,7 +141,7 @@ module Minitest # :nodoc:
141
141
 
142
142
  def verify
143
143
  @expected_calls.each do |name, expected|
144
- actual = @actual_calls.fetch(name, nil)
144
+ actual = @actual_calls.fetch name, nil # defaults to []
145
145
  raise MockExpectationError, "expected #{__call name, expected[0]}" unless actual
146
146
  raise MockExpectationError, "expected #{__call name, expected[actual.size]}, got [#{__call name, actual}]" if
147
147
  actual.size < expected.size
@@ -150,7 +150,7 @@ module Minitest # :nodoc:
150
150
  end
151
151
 
152
152
  def method_missing sym, *args, **kwargs, &block # :nodoc:
153
- unless @expected_calls.key?(sym) then
153
+ unless @expected_calls.key? sym then
154
154
  if @delegator && @delegator.respond_to?(sym)
155
155
  if kwargs.empty? then # FIX: drop this after 2.7 dead
156
156
  return @delegator.public_send(sym, *args, &block)
@@ -172,9 +172,9 @@ module Minitest # :nodoc:
172
172
  end
173
173
 
174
174
  expected_args, expected_kwargs, retval, val_block =
175
- expected_call.values_at(:args, :kwargs, :retval, :block)
175
+ expected_call.values_at :args, :kwargs, :retval, :block
176
176
 
177
- expected_kwargs = kwargs.map { |ak, av| [ak, Object] }.to_h if
177
+ expected_kwargs = kwargs.to_h { |ak, av| [ak, Object] } if
178
178
  Hash == expected_kwargs
179
179
 
180
180
  if val_block then
@@ -197,7 +197,7 @@ module Minitest # :nodoc:
197
197
  [sym, expected_kwargs.size, kwargs]
198
198
  end
199
199
 
200
- zipped_args = expected_args.zip(args)
200
+ zipped_args = expected_args.zip args
201
201
  fully_matched = zipped_args.all? { |mod, a|
202
202
  mod === a or mod == a
203
203
  }
@@ -212,10 +212,10 @@ module Minitest # :nodoc:
212
212
  raise MockExpectationError, fmt % [sym, expected_kwargs.keys, kwargs.keys]
213
213
  end
214
214
 
215
- zipped_kwargs = expected_kwargs.map { |ek, ev|
215
+ zipped_kwargs = expected_kwargs.to_h { |ek, ev|
216
216
  av = kwargs[ek]
217
217
  [ek, [ev, av]]
218
- }.to_h
218
+ }
219
219
 
220
220
  fully_matched = zipped_kwargs.all? { |ek, (ev, av)|
221
221
  ev === av or ev == av
@@ -228,8 +228,8 @@ module Minitest # :nodoc:
228
228
 
229
229
  @actual_calls[sym] << {
230
230
  :retval => retval,
231
- :args => zipped_args.map { |e, a| e === a ? e : a },
232
- :kwargs => zipped_kwargs.map { |k, (e, a)| [k, e === a ? e : a] }.to_h,
231
+ :args => zipped_args.map { |e, a| e === a ? e : a },
232
+ :kwargs => zipped_kwargs.to_h { |k, (e, a)| [k, e === a ? e : a] },
233
233
  }
234
234
 
235
235
  retval
@@ -238,7 +238,7 @@ module Minitest # :nodoc:
238
238
  def respond_to? sym, include_private = false # :nodoc:
239
239
  return true if @expected_calls.key? sym.to_sym
240
240
  return true if @delegator && @delegator.respond_to?(sym, include_private)
241
- __respond_to?(sym, include_private)
241
+ __respond_to? sym, include_private
242
242
  end
243
243
  end
244
244
  end
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
- module Parallel #:nodoc:
2
+ module Parallel # :nodoc:
3
3
 
4
4
  ##
5
5
  # The engine used to run multiple tests in parallel.
@@ -24,10 +24,10 @@ module Minitest
24
24
  # Start the executor
25
25
 
26
26
  def start
27
- @pool = size.times.map {
28
- Thread.new(@queue) do |queue|
27
+ @pool = Array.new(size) {
28
+ Thread.new @queue do |queue|
29
29
  Thread.current.abort_on_exception = true
30
- while (job = queue.pop)
30
+ while job = queue.pop do
31
31
  klass, method, reporter = job
32
32
  reporter.synchronize { reporter.prerecord klass, method }
33
33
  result = Minitest.run_one_method klass, method
@@ -8,13 +8,13 @@ module Minitest
8
8
  end
9
9
 
10
10
  def self.plugin_pride_init options # :nodoc:
11
- if PrideIO.pride? then
12
- klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
13
- io = klass.new options[:io]
11
+ return unless PrideIO.pride?
14
12
 
15
- self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
16
- rep.io = io if rep.io.tty?
17
- end
13
+ klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
14
+ io = klass.new options[:io]
15
+
16
+ self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
17
+ rep.io = io if rep.io.tty?
18
18
  end
19
19
  end
20
20
 
@@ -59,12 +59,10 @@ module Minitest
59
59
 
60
60
  def print o
61
61
  case o
62
- when "." then
62
+ when ".", "S" then
63
63
  io.print pride o
64
64
  when "E", "F" then
65
65
  io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
66
- when "S" then
67
- io.print pride o
68
66
  else
69
67
  io.print o
70
68
  end
@@ -72,11 +70,9 @@ module Minitest
72
70
 
73
71
  def puts *o # :nodoc:
74
72
  o.map! { |s|
75
- s.to_s.sub(/Finished/) {
73
+ s.to_s.sub("Finished") {
76
74
  @index = 0
77
- "Fabulous run".split(//).map { |c|
78
- pride(c)
79
- }.join
75
+ "Fabulous run".chars.map { |c| pride(c) }.join
80
76
  }
81
77
  }
82
78
 
@@ -113,7 +109,7 @@ module Minitest
113
109
  #
114
110
  # plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
115
111
 
116
- @colors = (6 * 7).times.map { |n|
112
+ @colors = Array.new(6 * 7) { |n|
117
113
  n *= 1.0 / 3
118
114
  r = (3 * Math.sin(n ) + 3).to_i
119
115
  g = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
data/lib/minitest/spec.rb CHANGED
@@ -4,11 +4,11 @@ class Module # :nodoc:
4
4
  def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
5
5
  block = dont_flip == :block
6
6
  dont_flip = false if block
7
- target_obj = block ? '_{obj.method}' : '_(obj)'
7
+ target_obj = block ? "_{obj.method}" : "_(obj)"
8
8
 
9
9
  # https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
10
10
  # Drop this when we can drop ruby 2.6 (aka after rails 6.1 EOL, ~2024-06)
11
- kw_extra = "ruby2_keywords %p" % [new_name] if respond_to?(:ruby2_keywords, true)
11
+ kw_extra = "ruby2_keywords %p" % [new_name] if respond_to? :ruby2_keywords, true
12
12
 
13
13
  # warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
14
14
  self.class_eval <<-EOM, __FILE__, __LINE__ + 1
@@ -249,7 +249,7 @@ class Minitest::Spec < Minitest::Test
249
249
  pre, post = "let '#{name}' cannot ", ". Please use another name."
250
250
  methods = Minitest::Spec.instance_methods.map(&:to_s) - %w[subject]
251
251
  raise ArgumentError, "#{pre}begin with 'test'#{post}" if
252
- name =~ /\Atest/
252
+ name.start_with? "test"
253
253
  raise ArgumentError, "#{pre}override a method in Minitest::Spec#{post}" if
254
254
  methods.include? name
255
255
 
@@ -268,7 +268,7 @@ class Minitest::Spec < Minitest::Test
268
268
  end
269
269
 
270
270
  def create name, desc # :nodoc:
271
- cls = Class.new(self) do
271
+ cls = Class.new self do
272
272
  @name = name
273
273
  @desc = desc
274
274
 
@@ -289,7 +289,7 @@ class Minitest::Spec < Minitest::Test
289
289
  end
290
290
 
291
291
  attr_reader :desc # :nodoc:
292
- alias :specify :it
292
+ alias specify it
293
293
 
294
294
  ##
295
295
  # Rdoc... why are you so dumb?
data/lib/minitest/test.rb CHANGED
@@ -85,20 +85,18 @@ module Minitest
85
85
  # Runs a single test with setup/teardown hooks.
86
86
 
87
87
  def run
88
- with_info_handler do
89
- time_it do
90
- capture_exceptions do
91
- SETUP_METHODS.each do |hook|
92
- self.send hook
93
- end
94
-
95
- self.send self.name
88
+ time_it do
89
+ capture_exceptions do
90
+ SETUP_METHODS.each do |hook|
91
+ self.send hook
96
92
  end
97
93
 
98
- TEARDOWN_METHODS.each do |hook|
99
- capture_exceptions do
100
- self.send hook
101
- end
94
+ self.send self.name
95
+ end
96
+
97
+ TEARDOWN_METHODS.each do |hook|
98
+ capture_exceptions do
99
+ self.send hook
102
100
  end
103
101
  end
104
102
  end
@@ -230,16 +228,6 @@ module Minitest
230
228
  ne
231
229
  end
232
230
 
233
- def with_info_handler &block # :nodoc:
234
- t0 = Minitest.clock_time
235
-
236
- handler = lambda do
237
- warn "\nCurrent: %s#%s %.2fs" % [self.class, self.name, Minitest.clock_time - t0]
238
- end
239
-
240
- self.class.on_signal ::Minitest.info_signal, handler, &block
241
- end
242
-
243
231
  include LifecycleHooks
244
232
  include Guard
245
233
  extend Guard
@@ -1,6 +1,12 @@
1
1
  require "shellwords"
2
2
  require "rbconfig"
3
- require "rake/tasklib"
3
+
4
+ begin
5
+ require "rake/tasklib"
6
+ rescue LoadError => e
7
+ warn e.message
8
+ return
9
+ end
4
10
 
5
11
  module Minitest # :nodoc:
6
12
 
@@ -144,7 +150,7 @@ module Minitest # :nodoc:
144
150
  ENV["N"] && ENV["N"].to_i > 0
145
151
 
146
152
  lib_extras = (ENV["MT_LIB_EXTRAS"] || "").split File::PATH_SEPARATOR
147
- self.libs[0,0] = lib_extras
153
+ self.libs[0, 0] = lib_extras
148
154
 
149
155
  extra_args << "-n" << ENV["N"] if ENV["N"]
150
156
  extra_args << "-e" << ENV["X"] if ENV["X"]
@@ -163,7 +169,7 @@ module Minitest # :nodoc:
163
169
  def define # :nodoc:
164
170
  desc "Run the test suite. Use N, X, A, and TESTOPTS to add flags/args."
165
171
  task name do
166
- ruby make_test_cmd, verbose:verbose
172
+ ruby make_test_cmd, verbose: verbose
167
173
  end
168
174
 
169
175
  desc "Print out the test command. Good for profiling and other tools."
@@ -177,7 +183,7 @@ module Minitest # :nodoc:
177
183
 
178
184
  # 3 seems to be the magic number... (tho not by that much)
179
185
  bad, good, n = {}, [], (ENV.delete("K") || 3).to_i
180
- file = ENV.delete("F")
186
+ file = ENV.delete "F"
181
187
  times = {}
182
188
 
183
189
  tt0 = Time.now
@@ -238,7 +244,7 @@ module Minitest # :nodoc:
238
244
 
239
245
  task "#{name}:deps" => "#{name}:isolated" # now just an alias
240
246
 
241
- desc "Show bottom 25 tests wrt time."
247
+ desc "Run the test suite and report the slowest 25 tests."
242
248
  task "#{name}:slow" do
243
249
  sh ["rake #{name} A=-v",
244
250
  "egrep '#test_.* s = .'",
@@ -262,11 +268,11 @@ module Minitest # :nodoc:
262
268
  runner = runner.join "; "
263
269
 
264
270
  args = []
265
- args << "-I#{libs.join(File::PATH_SEPARATOR)}" unless libs.empty?
271
+ args << "-I#{libs.join File::PATH_SEPARATOR}" unless libs.empty?
266
272
  args << "-w" if warning
267
- args << '-e'
273
+ args << "-e"
268
274
  args << "'#{runner}'"
269
- args << '--'
275
+ args << "--"
270
276
  args << extra_args.map(&:shellescape)
271
277
 
272
278
  args.join " "
@@ -287,10 +293,10 @@ class Work < Queue # :nodoc:
287
293
  end
288
294
 
289
295
  class Integer # :nodoc:
290
- def threads_do(jobs) # :nodoc:
296
+ def threads_do jobs # :nodoc:
291
297
  q = Work.new jobs
292
298
 
293
- self.times.map {
299
+ Array.new(self) {
294
300
  Thread.new do
295
301
  while job = q.pop # go until quit value
296
302
  yield job