minitest 5.25.1 → 5.25.4

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: 791576b6d19fd427617c1e5c02a7ddf55f3d214e75bdeeda4ec5ccb49bbad5d2
4
- data.tar.gz: 95a6dccbd1cc86bf047b82e88725d50d0dd03dab9f1f6db0a02aad13f1398f10
3
+ metadata.gz: 7ea765a693b5e0ff21498e24a2880144f5e407283d225a6052dde11fbe6165a5
4
+ data.tar.gz: 73f500c0dd7bbd0cbedcfa7c68d72da8f089f9397cd17d4a03e8f5bad0b40537
5
5
  SHA512:
6
- metadata.gz: acde5c1dc093da1b6749b4e328fe5e0b86ba34c081b3d6e667165f8811ea3565774570e73216d67f8c337b5e3999193b2709a50bd69e0dc62ed211b86d087cb9
7
- data.tar.gz: ee2390a10ef3ce15c17fef8d8387ff38509ac7c5bf9fd0bcbb1b6c160592821b268d713c0dc8c7357ddeaefb8ca08d0a04d96501c064e0c4f4781f7b3612bbb8
6
+ metadata.gz: 1028ca9777f3dc15155dbe813565e886df7c6d1b69d3074fdae470784c4bd8f96ee49602d2ea048832a71647b84b2d42ab9dcba0c2d948b8ec1cfb40c0e304b3
7
+ data.tar.gz: 05fb281d6ba736c47ade5c871472ab339ef8a7f14d68c88f9fbb7190d3f2e9c7d387f571e6d45fa9d25076b0794e6eb16cc993b79637b67e55996954e51678d8
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,28 @@
1
+ === 5.25.4 / 2024-12-03
2
+
3
+ * 1 bug fix:
4
+
5
+ * Fix for must_verify definition if only requiring minitest/mock (but why?).
6
+
7
+ === 5.25.3 / 2024-12-03
8
+
9
+ * 5 bug fixes:
10
+
11
+ * Fixed assert_mock to fail instead of raise on unmet mock expectations.
12
+ * Fixed assert_mock to take an optional message argument.
13
+ * Fixed formatting of unmet mock expectation messages.
14
+ * Fixed missing must_verify expectation to match assert_mock.
15
+ * minitest/pride: Fixed to use true colors with *-direct terminals (bk2204)
16
+
17
+ === 5.25.2 / 2024-11-21
18
+
19
+ * 4 bug fixes:
20
+
21
+ * Include class name in spec name. (thomasmarshall)
22
+ * Fixed 'redefining object_id' warning from ruby 3.4. (mattbrictson)
23
+ * Minitest top-level namespace no longer includes entire contents of README.rdoc. Too much!
24
+ * Refactored spec's describe to more cleanly determine the superclass and name
25
+
1
26
  === 5.25.1 / 2024-08-16
2
27
 
3
28
  * 2 bug fixes:
data/lib/minitest/mock.rb CHANGED
@@ -30,6 +30,7 @@ module Minitest # :nodoc:
30
30
  end
31
31
 
32
32
  overridden_methods.map(&:to_sym).each do |method_id|
33
+ old_w, $-w = $-w, nil
33
34
  define_method method_id do |*args, **kwargs, &b|
34
35
  if @expected_calls.key? method_id then
35
36
  if kwargs.empty? then # FIX: drop this after 2.7 dead
@@ -45,6 +46,8 @@ module Minitest # :nodoc:
45
46
  end
46
47
  end
47
48
  end
49
+ ensure
50
+ $-w = old_w
48
51
  end
49
52
 
50
53
  def initialize delegator = nil # :nodoc:
@@ -142,8 +145,8 @@ module Minitest # :nodoc:
142
145
  def verify
143
146
  @expected_calls.each do |name, expected|
144
147
  actual = @actual_calls.fetch name, nil # defaults to []
145
- raise MockExpectationError, "expected #{__call name, expected[0]}" unless actual
146
- raise MockExpectationError, "expected #{__call name, expected[actual.size]}, got [#{__call name, actual}]" if
148
+ raise MockExpectationError, "Expected #{__call name, expected[0]}" unless actual
149
+ raise MockExpectationError, "Expected #{__call name, expected[actual.size]}, got [#{__call name, actual}]" if
147
150
  actual.size < expected.size
148
151
  end
149
152
  true
@@ -245,13 +248,28 @@ end
245
248
 
246
249
  module Minitest::Assertions
247
250
  ##
248
- # Assert that the mock verifies correctly.
251
+ # Assert that the mock verifies correctly and fail if not.
249
252
 
250
- def assert_mock mock
253
+ def assert_mock mock, msg = nil
251
254
  assert mock.verify
255
+ rescue MockExpectationError => e
256
+ msg = message(msg) { e.message }
257
+ flunk msg
252
258
  end
253
259
  end
254
260
 
261
+ module Minitest::Expectations
262
+ ##
263
+ # See Minitest::Assertions#assert_mock.
264
+ #
265
+ # _(collection).must_verify
266
+ #
267
+ # :method: must_verify
268
+
269
+ infect_an_assertion :assert_mock, :must_verify, :unary if
270
+ defined?(infect_an_assertion)
271
+ end
272
+
255
273
  ##
256
274
  # Object extensions for Minitest::Mock.
257
275
 
@@ -10,7 +10,7 @@ module Minitest
10
10
  def self.plugin_pride_init options # :nodoc:
11
11
  return unless PrideIO.pride?
12
12
 
13
- klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
13
+ klass = ENV["TERM"] =~ /^xterm|-(?:256color|direct)$/ ? PrideLOL : PrideIO
14
14
  io = klass.new options[:io]
15
15
 
16
16
  self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
data/lib/minitest/spec.rb CHANGED
@@ -81,14 +81,15 @@ module Kernel
81
81
 
82
82
  def describe desc, *additional_desc, &block # :doc:
83
83
  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
90
-
91
- cls = sclas.create name, desc
84
+ is_spec_class = Class === self && kind_of?(Minitest::Spec::DSL)
85
+ name = [stack.last, desc, *additional_desc]
86
+ name.prepend self if stack.empty? && is_spec_class
87
+ sclas =
88
+ stack.last \
89
+ || (is_spec_class && self) \
90
+ || Minitest::Spec.spec_type(desc, *additional_desc)
91
+
92
+ cls = sclas.create name.compact.join("::"), desc
92
93
 
93
94
  stack.push cls
94
95
  cls.class_eval(&block)
data/lib/minitest.rb CHANGED
@@ -6,10 +6,11 @@ require_relative "minitest/parallel"
6
6
  require_relative "minitest/compress"
7
7
 
8
8
  ##
9
- # :include: README.rdoc
9
+ # The top-level namespace for Minitest. Also the location of the main
10
+ # runtime. See +Minitest.run+ for more information.
10
11
 
11
12
  module Minitest
12
- VERSION = "5.25.1" # :nodoc:
13
+ VERSION = "5.25.4" # :nodoc:
13
14
 
14
15
  @@installed_at_exit ||= false
15
16
  @@after_run = []
@@ -26,7 +26,7 @@ class TestMinitestMock < Minitest::Test
26
26
  def test_blow_up_if_not_called
27
27
  @mock.foo
28
28
 
29
- util_verify_bad "expected meaning_of_life() => 42"
29
+ util_verify_bad "Expected meaning_of_life() => 42"
30
30
  end
31
31
 
32
32
  def test_not_blow_up_if_everything_called
@@ -46,7 +46,7 @@ class TestMinitestMock < Minitest::Test
46
46
  @mock.meaning_of_life
47
47
  @mock.expect :bar, true
48
48
 
49
- util_verify_bad "expected bar() => true"
49
+ util_verify_bad "Expected bar() => true"
50
50
  end
51
51
 
52
52
  def test_blow_up_on_wrong_number_of_arguments
@@ -184,6 +184,73 @@ class TestMinitestMock < Minitest::Test
184
184
  assert @mock == 1, "didn't mock :=="
185
185
  end
186
186
 
187
+ def test_assert_mock__pass
188
+ mock = Minitest::Mock.new
189
+ mock.expect :loose_expectation, true, [Integer]
190
+ mock.loose_expectation 1
191
+
192
+ result = assert_mock mock
193
+
194
+ assert_equal true, result
195
+ end
196
+
197
+ def assert_bad_mock klass, msg
198
+ mock = Minitest::Mock.new
199
+ mock.expect :foo, nil, [:bar]
200
+ mock.expect :foo, nil, [:baz]
201
+
202
+ mock.foo :bar
203
+
204
+ e = assert_raises klass do
205
+ yield mock
206
+ end
207
+
208
+ assert_equal msg, e.message
209
+ end
210
+
211
+ def test_verify__error
212
+ exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]"
213
+ assert_bad_mock MockExpectationError, exp do |mock|
214
+ mock.verify
215
+ end
216
+ end
217
+
218
+ def test_assert_mock__fail
219
+ exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]."
220
+ assert_bad_mock Minitest::Assertion, exp do |mock|
221
+ assert_mock mock
222
+ end
223
+ end
224
+
225
+ def test_assert_mock__fail_msg
226
+ exp = "BLAH.\nExpected foo(:baz) => nil, got [foo(:bar) => nil]."
227
+ assert_bad_mock Minitest::Assertion, exp do |mock|
228
+ assert_mock mock, "BLAH"
229
+ end
230
+ end
231
+
232
+ def test_assert_mock__fail_exp
233
+ exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]."
234
+ assert_bad_mock Minitest::Assertion, exp do |mock|
235
+ describe "X" do
236
+ it "y" do
237
+ _(mock).must_verify
238
+ end
239
+ end.new(:blah).send(:test_0001_y)
240
+ end
241
+ end
242
+
243
+ def test_assert_mock__fail_exp_msg
244
+ exp = "BLAH.\nExpected foo(:baz) => nil, got [foo(:bar) => nil]."
245
+ assert_bad_mock Minitest::Assertion, exp do |mock|
246
+ describe "X" do
247
+ it "y" do
248
+ _(mock).must_verify "BLAH"
249
+ end
250
+ end.new(:blah).send(:test_0001_y)
251
+ end
252
+ end
253
+
187
254
  def test_verify_allows_called_args_to_be_loosely_specified
188
255
  mock = Minitest::Mock.new
189
256
  mock.expect :loose_expectation, true, [Integer]
@@ -238,7 +305,7 @@ class TestMinitestMock < Minitest::Test
238
305
 
239
306
  e = assert_raises(MockExpectationError) { mock.verify }
240
307
 
241
- exp = "expected foo(:baz) => nil, got [foo(:bar) => nil]"
308
+ exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]"
242
309
 
243
310
  assert_equal exp, e.message
244
311
  end
@@ -252,7 +319,7 @@ class TestMinitestMock < Minitest::Test
252
319
 
253
320
  e = assert_raises(MockExpectationError) { mock.verify }
254
321
 
255
- exp = "expected foo(:bar) => nil, got [foo(:bar) => nil]"
322
+ exp = "Expected foo(:bar) => nil, got [foo(:bar) => nil]"
256
323
 
257
324
  assert_equal exp, e.message
258
325
  end
@@ -276,7 +343,7 @@ class TestMinitestMock < Minitest::Test
276
343
 
277
344
  e = assert_raises(MockExpectationError) { mock.verify }
278
345
 
279
- exp = "expected foo(%p) => nil, got [foo(%p) => nil]" \
346
+ exp = "Expected foo(%p) => nil, got [foo(%p) => nil]" \
280
347
  % [{ :kw => false }, { :kw => true }]
281
348
 
282
349
  assert_equal exp.delete("{}"), e.message
@@ -2,7 +2,7 @@ require "minitest/autorun"
2
2
  require "minitest/metametameta"
3
3
  require "forwardable"
4
4
 
5
- class Runnable
5
+ class FakeTest < Minitest::Test
6
6
  def woot
7
7
  assert true
8
8
  end
@@ -33,7 +33,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
33
33
 
34
34
  def error_test
35
35
  unless defined? @et then
36
- @et = Minitest::Test.new :woot
36
+ @et = FakeTest.new :woot
37
37
  @et.failures << Minitest::UnexpectedError.new(begin
38
38
  raise "no"
39
39
  rescue => e
@@ -56,7 +56,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
56
56
 
57
57
  ex.set_backtrace ary
58
58
 
59
- @sse = Minitest::Test.new :woot
59
+ @sse = FakeTest.new :woot
60
60
  @sse.failures << Minitest::UnexpectedError.new(ex)
61
61
  @sse = Minitest::Result.from @sse
62
62
  end
@@ -65,7 +65,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
65
65
 
66
66
  def fail_test
67
67
  unless defined? @ft then
68
- @ft = Minitest::Test.new :woot
68
+ @ft = FakeTest.new :woot
69
69
  @ft.failures << begin
70
70
  raise Minitest::Assertion, "boo"
71
71
  rescue Minitest::Assertion => e
@@ -77,18 +77,18 @@ class TestMinitestReporter < MetaMetaMetaTestCase
77
77
  end
78
78
 
79
79
  def passing_test
80
- @pt ||= Minitest::Result.from Minitest::Test.new(:woot)
80
+ @pt ||= Minitest::Result.from FakeTest.new(:woot)
81
81
  end
82
82
 
83
83
  def passing_test_with_metadata
84
- test = Minitest::Test.new :woot
84
+ test = FakeTest.new :woot
85
85
  test.metadata[:meta] = :data
86
86
  @pt ||= Minitest::Result.from test
87
87
  end
88
88
 
89
89
  def skip_test
90
90
  unless defined? @st then
91
- @st = Minitest::Test.new :woot
91
+ @st = FakeTest.new :woot
92
92
  @st.failures << begin
93
93
  raise Minitest::Skip
94
94
  rescue Minitest::Assertion => e
@@ -294,7 +294,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
294
294
  Finished in 0.00
295
295
 
296
296
  1) Failure:
297
- Minitest::Test#woot [FILE:LINE]:
297
+ FakeTest#woot [FILE:LINE]:
298
298
  boo
299
299
 
300
300
  1 runs, 0 assertions, 1 failures, 0 errors, 0 skips
@@ -318,7 +318,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
318
318
  Finished in 0.00
319
319
 
320
320
  1) Error:
321
- Minitest::Test#woot:
321
+ FakeTest#woot:
322
322
  RuntimeError: no
323
323
  FILE:LINE:in 'error_test'
324
324
  FILE:LINE:in 'test_report_error'
@@ -344,7 +344,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
344
344
  Finished in 0.00
345
345
 
346
346
  1) Error:
347
- Minitest::Test#woot:
347
+ FakeTest#woot:
348
348
  SystemStackError: 274 -> 12
349
349
  a
350
350
  b
@@ -402,7 +402,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
402
402
  r.report
403
403
  end
404
404
 
405
- exp = "Minitest::Test#woot [foo.rb:123]"
405
+ exp = "FakeTest#woot [foo.rb:123]"
406
406
 
407
407
  assert_includes io.string, exp
408
408
  end
@@ -212,9 +212,10 @@ describe Minitest::Spec do
212
212
  must_raise
213
213
  must_respond_to
214
214
  must_throw
215
+ must_verify
215
216
  path_must_exist]
216
217
 
217
- bad = %w[not raise throw send output be_silent]
218
+ bad = %w[not raise throw send output be_silent verify]
218
219
 
219
220
  expected_wonts = expected_musts.map { |m| m.sub("must", "wont") }.sort
220
221
  expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
@@ -952,6 +953,23 @@ class TestMeta < MetaMetaMetaTestCase
952
953
  assert_equal "ExampleB::random_method", spec_b.name
953
954
  end
954
955
 
956
+ def test_name_inside_class
957
+ spec_a = nil
958
+ spec_b = nil
959
+ inside_class_example = Class.new Minitest::Spec
960
+ Object.const_set :InsideClassExample, inside_class_example
961
+ inside_class_example.class_eval do
962
+ spec_a = describe "a" do
963
+ spec_b = describe "b" do; end
964
+ end
965
+ end
966
+
967
+ assert_equal "InsideClassExample::a", spec_a.name
968
+ assert_equal "InsideClassExample::a::b", spec_b.name
969
+ ensure
970
+ Object.send :remove_const, :InsideClassExample
971
+ end
972
+
955
973
  def test_structure
956
974
  x, y, z, * = util_structure
957
975
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.25.1
4
+ version: 5.25.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  S7043fq9EbQdBr2AXdj92+CDwuTfHI6/Hj5FVBDULufrJaan4xUgL70Hvc6pTTeW
30
30
  deKfBjgVAq7EYHu1AczzlUly
31
31
  -----END CERTIFICATE-----
32
- date: 2024-08-16 00:00:00.000000000 Z
32
+ date: 2024-12-04 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdoc
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
189
  requirements: []
190
- rubygems_version: 3.5.15
190
+ rubygems_version: 3.5.23
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: minitest provides a complete suite of testing facilities supporting TDD,
metadata.gz.sig CHANGED
Binary file