minitest 5.20.0 → 5.27.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.
@@ -125,7 +125,7 @@ module Minitest::Expectations
125
125
  infect_an_assertion :assert_output, :must_output, :block
126
126
 
127
127
  ##
128
- # See Minitest::Assertions#assert_pattern_match
128
+ # See Minitest::Assertions#assert_pattern
129
129
  #
130
130
  # _ { ... }.must_pattern_match [...]
131
131
  #
@@ -293,7 +293,7 @@ module Minitest::Expectations
293
293
  infect_an_assertion :refute_operator, :wont_be, :reverse
294
294
 
295
295
  ##
296
- # See Minitest::Assertions#refute_pattern_match
296
+ # See Minitest::Assertions#refute_pattern
297
297
  #
298
298
  # _ { ... }.wont_pattern_match [...]
299
299
  #
data/lib/minitest/hell.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "minitest/parallel"
1
+ require_relative "parallel"
2
2
 
3
3
  class Minitest::Test
4
4
  parallelize_me!
@@ -0,0 +1,16 @@
1
+ require_relative "../minitest"
2
+
3
+ ARGV << "--no-plugins"
4
+
5
+ module Minitest
6
+ ##
7
+ # Manually load plugins by name.
8
+
9
+ def self.load *names
10
+ names.each do |name|
11
+ require "minitest/#{name}_plugin"
12
+
13
+ self.extensions << name.to_s
14
+ end
15
+ end
16
+ end
data/lib/minitest/mock.rb CHANGED
@@ -8,9 +8,9 @@ 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
- overridden_methods = %w[
13
+ overridden_methods = %i[
14
14
  ===
15
15
  class
16
16
  inspect
@@ -23,26 +23,23 @@ module Minitest # :nodoc:
23
23
  to_s
24
24
  ]
25
25
 
26
+ overridden_methods << :singleton_method_added if defined?(::DEBUGGER__)
27
+
26
28
  instance_methods.each do |m|
27
- undef_method m unless overridden_methods.include?(m.to_s) || m =~ /^__/
29
+ undef_method m unless overridden_methods.include?(m) || m =~ /^__/
28
30
  end
29
31
 
30
32
  overridden_methods.map(&:to_sym).each do |method_id|
33
+ old_w, $-w = $-w, nil
31
34
  define_method method_id do |*args, **kwargs, &b|
32
35
  if @expected_calls.key? method_id then
33
- if kwargs.empty? then # FIX: drop this after 2.7 dead
34
- method_missing(method_id, *args, &b)
35
- else
36
- method_missing(method_id, *args, **kwargs, &b)
37
- end
36
+ method_missing(method_id, *args, **kwargs, &b)
38
37
  else
39
- if kwargs.empty? then # FIX: drop this after 2.7 dead
40
- super(*args, &b)
41
- else
42
- super(*args, **kwargs, &b)
43
- end
38
+ super(*args, **kwargs, &b)
44
39
  end
45
40
  end
41
+ ensure
42
+ $-w = old_w
46
43
  end
47
44
 
48
45
  def initialize delegator = nil # :nodoc:
@@ -91,7 +88,7 @@ module Minitest # :nodoc:
91
88
  def expect name, retval, args = [], **kwargs, &blk
92
89
  name = name.to_sym
93
90
 
94
- if block_given?
91
+ if blk then
95
92
  raise ArgumentError, "args ignored when block given" unless args.empty?
96
93
  raise ArgumentError, "kwargs ignored when block given" unless kwargs.empty?
97
94
  @expected_calls[name] << { :retval => retval, :block => blk }
@@ -104,7 +101,7 @@ module Minitest # :nodoc:
104
101
  kwargs = args.pop
105
102
  else
106
103
  unless @@KW_WARNED then
107
- from = caller.first
104
+ from = caller(1..1).first
108
105
  warn "Using MT_KWARGS_HAC\K yet passing kwargs. From #{from}"
109
106
  @@KW_WARNED = true
110
107
  end
@@ -139,22 +136,18 @@ module Minitest # :nodoc:
139
136
 
140
137
  def verify
141
138
  @expected_calls.each do |name, expected|
142
- actual = @actual_calls.fetch(name, nil)
143
- raise MockExpectationError, "expected #{__call name, expected[0]}" unless actual
144
- raise MockExpectationError, "expected #{__call name, expected[actual.size]}, got [#{__call name, actual}]" if
139
+ actual = @actual_calls.fetch name, nil # defaults to []
140
+ raise MockExpectationError, "Expected #{__call name, expected[0]}" unless actual
141
+ raise MockExpectationError, "Expected #{__call name, expected[actual.size]}, got [#{__call name, actual}]" if
145
142
  actual.size < expected.size
146
143
  end
147
144
  true
148
145
  end
149
146
 
150
147
  def method_missing sym, *args, **kwargs, &block # :nodoc:
151
- unless @expected_calls.key?(sym) then
148
+ unless @expected_calls.key? sym then
152
149
  if @delegator && @delegator.respond_to?(sym)
153
- if kwargs.empty? then # FIX: drop this after 2.7 dead
154
- return @delegator.public_send(sym, *args, &block)
155
- else
156
- return @delegator.public_send(sym, *args, **kwargs, &block)
157
- end
150
+ return @delegator.public_send(sym, *args, **kwargs, &block)
158
151
  else
159
152
  raise NoMethodError, "unmocked method %p, expected one of %p" %
160
153
  [sym, @expected_calls.keys.sort_by(&:to_s)]
@@ -170,9 +163,9 @@ module Minitest # :nodoc:
170
163
  end
171
164
 
172
165
  expected_args, expected_kwargs, retval, val_block =
173
- expected_call.values_at(:args, :kwargs, :retval, :block)
166
+ expected_call.values_at :args, :kwargs, :retval, :block
174
167
 
175
- expected_kwargs = kwargs.map { |ak, av| [ak, Object] }.to_h if
168
+ expected_kwargs = kwargs.to_h { |ak, av| [ak, Object] } if
176
169
  Hash == expected_kwargs
177
170
 
178
171
  if val_block then
@@ -195,7 +188,7 @@ module Minitest # :nodoc:
195
188
  [sym, expected_kwargs.size, kwargs]
196
189
  end
197
190
 
198
- zipped_args = expected_args.zip(args)
191
+ zipped_args = expected_args.zip args
199
192
  fully_matched = zipped_args.all? { |mod, a|
200
193
  mod === a or mod == a
201
194
  }
@@ -210,10 +203,10 @@ module Minitest # :nodoc:
210
203
  raise MockExpectationError, fmt % [sym, expected_kwargs.keys, kwargs.keys]
211
204
  end
212
205
 
213
- zipped_kwargs = expected_kwargs.map { |ek, ev|
206
+ zipped_kwargs = expected_kwargs.to_h { |ek, ev|
214
207
  av = kwargs[ek]
215
208
  [ek, [ev, av]]
216
- }.to_h
209
+ }
217
210
 
218
211
  fully_matched = zipped_kwargs.all? { |ek, (ev, av)|
219
212
  ev === av or ev == av
@@ -226,8 +219,8 @@ module Minitest # :nodoc:
226
219
 
227
220
  @actual_calls[sym] << {
228
221
  :retval => retval,
229
- :args => zipped_args.map { |e, a| e === a ? e : a },
230
- :kwargs => zipped_kwargs.map { |k, (e, a)| [k, e === a ? e : a] }.to_h,
222
+ :args => zipped_args.map { |e, a| e === a ? e : a },
223
+ :kwargs => zipped_kwargs.to_h { |k, (e, a)| [k, e === a ? e : a] },
231
224
  }
232
225
 
233
226
  retval
@@ -236,20 +229,35 @@ module Minitest # :nodoc:
236
229
  def respond_to? sym, include_private = false # :nodoc:
237
230
  return true if @expected_calls.key? sym.to_sym
238
231
  return true if @delegator && @delegator.respond_to?(sym, include_private)
239
- __respond_to?(sym, include_private)
232
+ __respond_to? sym, include_private
240
233
  end
241
234
  end
242
235
  end
243
236
 
244
237
  module Minitest::Assertions
245
238
  ##
246
- # Assert that the mock verifies correctly.
239
+ # Assert that the mock verifies correctly and fail if not.
247
240
 
248
- def assert_mock mock
241
+ def assert_mock mock, msg = nil
249
242
  assert mock.verify
243
+ rescue MockExpectationError => e
244
+ msg = message(msg) { e.message }
245
+ flunk msg
250
246
  end
251
247
  end
252
248
 
249
+ module Minitest::Expectations
250
+ ##
251
+ # See Minitest::Assertions#assert_mock.
252
+ #
253
+ # _(collection).must_verify
254
+ #
255
+ # :method: must_verify
256
+
257
+ infect_an_assertion :assert_mock, :must_verify, :unary if
258
+ defined?(infect_an_assertion)
259
+ end
260
+
253
261
  ##
254
262
  # Object extensions for Minitest::Mock.
255
263
 
@@ -300,18 +308,10 @@ class Object
300
308
  else
301
309
  metaclass.send :define_method, name do |*args, **kwargs, &blk|
302
310
  if val_or_callable.respond_to? :call then
303
- if kwargs.empty? then # FIX: drop this after 2.7 dead
304
- val_or_callable.call(*args, &blk)
305
- else
306
- val_or_callable.call(*args, **kwargs, &blk)
307
- end
311
+ val_or_callable.call(*args, **kwargs, &blk)
308
312
  else
309
313
  if blk then
310
- if block_kwargs.empty? then # FIX: drop this after 2.7 dead
311
- blk.call(*block_args)
312
- else
313
- blk.call(*block_args, **block_kwargs)
314
- end
314
+ blk.call(*block_args, **block_kwargs)
315
315
  end
316
316
  val_or_callable
317
317
  end
@@ -1,5 +1,7 @@
1
+ require "thread"
2
+
1
3
  module Minitest
2
- module Parallel #:nodoc:
4
+ module Parallel # :nodoc:
3
5
 
4
6
  ##
5
7
  # The engine used to run multiple tests in parallel.
@@ -16,7 +18,7 @@ module Minitest
16
18
 
17
19
  def initialize size
18
20
  @size = size
19
- @queue = Queue.new
21
+ @queue = Thread::Queue.new
20
22
  @pool = nil
21
23
  end
22
24
 
@@ -24,10 +26,10 @@ module Minitest
24
26
  # Start the executor
25
27
 
26
28
  def start
27
- @pool = size.times.map {
28
- Thread.new(@queue) do |queue|
29
+ @pool = Array.new(size) {
30
+ Thread.new @queue do |queue|
29
31
  Thread.current.abort_on_exception = true
30
- while (job = queue.pop)
32
+ while job = queue.pop do
31
33
  klass, method, reporter = job
32
34
  reporter.synchronize { reporter.prerecord klass, method }
33
35
  result = Minitest.run_one_method klass, method
@@ -1,4 +1,4 @@
1
- require "minitest"
1
+ require_relative "../minitest"
2
2
 
3
3
  Minitest.load_plugins
4
4
  Minitest::PrideIO.pride!
@@ -1,4 +1,4 @@
1
- require "minitest"
1
+ require_relative "../minitest"
2
2
 
3
3
  module Minitest
4
4
  def self.plugin_pride_options opts, _options # :nodoc:
@@ -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|direct)$/ ? 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,19 +109,16 @@ 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
- # 6 has wide pretty gradients. 3 == lolcat, about half the width
117
- @colors = (0...(6 * 7)).map { |n|
118
- n *= 1.0 / 6
112
+ @colors = Array.new(6 * 7) { |n|
113
+ n *= 1.0 / 3
119
114
  r = (3 * Math.sin(n ) + 3).to_i
120
- g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
121
- b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
122
-
123
- # Then we take rgb and encode them in a single number using base 6.
124
- # For some mysterious reason, we add 16... to clear the bottom 4 bits?
125
- # Yes... they're ugly.
115
+ g = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
116
+ b = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
126
117
 
118
+ # Then we take rgb and encode them in a single number using
119
+ # base 6, shifted by 16 for the base 16 ansi colors.
127
120
  36 * r + 6 * g + b + 16
128
- }
121
+ }.rotate(4) # puts "red" first
129
122
 
130
123
  super
131
124
  end
data/lib/minitest/spec.rb CHANGED
@@ -1,14 +1,14 @@
1
- require "minitest/test"
1
+ require_relative "test"
2
2
 
3
3
  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
@@ -38,7 +38,11 @@ class Module # :nodoc:
38
38
  end
39
39
  end
40
40
 
41
- Minitest::Expectation = Struct.new :target, :ctx # :nodoc:
41
+ # :stopdoc:
42
+ module Minitest # fucking hell rdoc...
43
+ Expectation = Struct.new :target, :ctx
44
+ end
45
+ # :startdoc:
42
46
 
43
47
  ##
44
48
  # Kernel extensions for minitest
@@ -81,14 +85,15 @@ module Kernel
81
85
 
82
86
  def describe desc, *additional_desc, &block # :doc:
83
87
  stack = Minitest::Spec.describe_stack
84
- name = [stack.last, desc, *additional_desc].compact.join("::")
85
- sclas = stack.last || if Class === self && kind_of?(Minitest::Spec::DSL) then
86
- self
87
- else
88
- Minitest::Spec.spec_type desc, *additional_desc
89
- end
88
+ is_spec_class = Class === self && kind_of?(Minitest::Spec::DSL)
89
+ name = [stack.last, desc, *additional_desc]
90
+ name.prepend self if stack.empty? && is_spec_class
91
+ sclas =
92
+ stack.last \
93
+ || (is_spec_class && self) \
94
+ || Minitest::Spec.spec_type(desc, *additional_desc)
90
95
 
91
- cls = sclas.create name, desc
96
+ cls = sclas.create name.compact.join("::"), desc
92
97
 
93
98
  stack.push cls
94
99
  cls.class_eval(&block)
@@ -249,7 +254,7 @@ class Minitest::Spec < Minitest::Test
249
254
  pre, post = "let '#{name}' cannot ", ". Please use another name."
250
255
  methods = Minitest::Spec.instance_methods.map(&:to_s) - %w[subject]
251
256
  raise ArgumentError, "#{pre}begin with 'test'#{post}" if
252
- name =~ /\Atest/
257
+ name.start_with? "test"
253
258
  raise ArgumentError, "#{pre}override a method in Minitest::Spec#{post}" if
254
259
  methods.include? name
255
260
 
@@ -268,7 +273,7 @@ class Minitest::Spec < Minitest::Test
268
273
  end
269
274
 
270
275
  def create name, desc # :nodoc:
271
- cls = Class.new(self) do
276
+ cls = Class.new self do
272
277
  @name = name
273
278
  @desc = desc
274
279
 
@@ -284,12 +289,11 @@ class Minitest::Spec < Minitest::Test
284
289
  defined?(@name) ? @name : super
285
290
  end
286
291
 
287
- def to_s # :nodoc:
288
- name # Can't alias due to 1.8.7, not sure why
289
- end
292
+ alias to_s name
293
+ alias inspect name
290
294
 
291
295
  attr_reader :desc # :nodoc:
292
- alias :specify :it
296
+ alias specify it
293
297
 
294
298
  ##
295
299
  # Rdoc... why are you so dumb?
@@ -342,7 +346,7 @@ class Minitest::Spec < Minitest::Test
342
346
  TYPES = DSL::TYPES # :nodoc:
343
347
  end
344
348
 
345
- require "minitest/expectations"
349
+ require_relative "expectations"
346
350
 
347
351
  class Object # :nodoc:
348
352
  include Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
data/lib/minitest/test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "minitest" unless defined? Minitest::Runnable
1
+ require_relative "../minitest" unless defined? Minitest::Runnable
2
2
 
3
3
  module Minitest
4
4
  ##
@@ -8,9 +8,9 @@ module Minitest
8
8
  # See Minitest::Assertions
9
9
 
10
10
  class Test < Runnable
11
- require "minitest/assertions"
12
- include Minitest::Assertions
11
+ require_relative "assertions"
13
12
  include Minitest::Reportable
13
+ include Minitest::Assertions
14
14
 
15
15
  def class_name # :nodoc:
16
16
  self.class.name # for Minitest::Reportable
@@ -52,11 +52,13 @@ module Minitest
52
52
  end
53
53
 
54
54
  ##
55
- # Call this at the top of your tests when you want to run your
56
- # tests in parallel. In doing so, you're admitting that you rule
57
- # and your tests are awesome.
55
+ # Call this at the top of your tests (inside the +Minitest::Test+
56
+ # subclass or +describe+ block) when you want to run your tests in
57
+ # parallel. In doing so, you're admitting that you rule and your
58
+ # tests are awesome.
58
59
 
59
60
  def self.parallelize_me!
61
+ return unless Minitest.parallel_executor
60
62
  include Minitest::Parallel::Test
61
63
  extend Minitest::Parallel::Test::ClassMethods
62
64
  end
@@ -84,20 +86,18 @@ module Minitest
84
86
  # Runs a single test with setup/teardown hooks.
85
87
 
86
88
  def run
87
- with_info_handler do
88
- time_it do
89
- capture_exceptions do
90
- SETUP_METHODS.each do |hook|
91
- self.send hook
92
- end
93
-
94
- self.send self.name
89
+ time_it do
90
+ capture_exceptions do
91
+ SETUP_METHODS.each do |hook|
92
+ self.send hook
95
93
  end
96
94
 
97
- TEARDOWN_METHODS.each do |hook|
98
- capture_exceptions do
99
- self.send hook
100
- end
95
+ self.send self.name
96
+ end
97
+
98
+ TEARDOWN_METHODS.each do |hook|
99
+ capture_exceptions do
100
+ self.send hook
101
101
  end
102
102
  end
103
103
  end
@@ -229,20 +229,10 @@ module Minitest
229
229
  ne
230
230
  end
231
231
 
232
- def with_info_handler &block # :nodoc:
233
- t0 = Minitest.clock_time
234
-
235
- handler = lambda do
236
- warn "\nCurrent: %s#%s %.2fs" % [self.class, self.name, Minitest.clock_time - t0]
237
- end
238
-
239
- self.class.on_signal ::Minitest.info_signal, handler, &block
240
- end
241
-
242
232
  include LifecycleHooks
243
233
  include Guard
244
234
  extend Guard
245
235
  end # Test
246
236
  end
247
237
 
248
- require "minitest/unit" if ENV["MT_COMPAT"] # compatibility layer only
238
+ require_relative "unit" if ENV["MT_COMPAT"] # compatibility layer only