minitest 5.17.0 → 5.18.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76379897c6c77174044638d17a95f50b1b2fddbfde053759d864d8b9b419984b
4
- data.tar.gz: 7cdedb3e76825894a5577f2c639c541402e1955b1166221530e2937b6c605b81
3
+ metadata.gz: 27d1d24e16ba576cc5a425d6e09e3de81465d10104a647c21ad9a5df36be1551
4
+ data.tar.gz: c3ca5dd490b7d08ee3254c7c8a680af0675f72e5356ad97b55dd1ec67e27251d
5
5
  SHA512:
6
- metadata.gz: 5bc0b4b036c2e07d3db6ace79c1d0e51d2aa5cac74a26174ec822f1f987882bffc0165650c86f168ee38b31e9f07d825730b20a1f13b704fc395a9a88a4d9060
7
- data.tar.gz: e9bdf26bc5a327b72b7a1dbdf701f6cef70561b634a258f932c511f26e7f2886597a05cc4a964749ef16e32529ab6a0cb6d11601f2954c3830444d34c3fcb23b
6
+ metadata.gz: f545c292aabb802ae8e03cea73bf2334a8ac6dea7da411b8e6ad48e036b00eabac550e5405c11aea175b30a9d65aced4e3601258081e845299ff6e1dbffd353d
7
+ data.tar.gz: ae62ac5c0f4218b66fe0206eb0205828c872531d6b68a4b0537fbe4b0a8753ccf604b4d11a11322dc329b275a1428683125c061e6e255f90ff5a076e4afb02ad
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,14 @@
1
+ === 5.18.0 / 2023-03-04
2
+
3
+ * 2 major enhancements:
4
+
5
+ * Added assert_pattern & refute_pattern for pattern matching. (flavorjones)
6
+ * Added matching must_pattern_match & wont_pattern_match to minitest/spec.
7
+
8
+ * 1 bug fix:
9
+
10
+ * Support the new message format of NameError in Ruby 3.3 (mame)
11
+
1
12
  === 5.17.0 / 2022-12-31
2
13
 
3
14
  * 1 minor enhancement:
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rubygems"
4
4
  require "hoe"
5
+ $:.unshift "lib" # to pick up lib/minitest/test_task.rb when minitest not installed
5
6
 
6
7
  Hoe.plugin :seattlerb
7
8
  Hoe.plugin :rdoc
@@ -357,6 +357,32 @@ module Minitest
357
357
  assert File.exist?(path), msg
358
358
  end
359
359
 
360
+ ##
361
+ # For testing with pattern matching (only supported with Ruby 3.0 and later)
362
+ #
363
+ # # pass
364
+ # assert_pattern { [1,2,3] => [Integer, Integer, Integer] }
365
+ #
366
+ # # fail "length mismatch (given 3, expected 1)"
367
+ # assert_pattern { [1,2,3] => [Integer] }
368
+ #
369
+ # The bare <tt>=></tt> pattern will raise a NoMatchingPatternError on failure, which would
370
+ # normally be counted as a test error. This assertion rescues NoMatchingPatternError and
371
+ # generates a test failure. Any other exception will be raised as normal and generate a test
372
+ # error.
373
+
374
+ def assert_pattern
375
+ raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
376
+ flunk "assert_pattern requires a block to capture errors." unless block_given?
377
+
378
+ begin # TODO: remove after ruby 2.6 dropped
379
+ yield
380
+ pass
381
+ rescue NoMatchingPatternError => e
382
+ flunk e.message
383
+ end
384
+ end
385
+
360
386
  ##
361
387
  # For testing with predicates. Eg:
362
388
  #
@@ -721,6 +747,30 @@ module Minitest
721
747
  refute obj.nil?, msg
722
748
  end
723
749
 
750
+ ##
751
+ # For testing with pattern matching (only supported with Ruby 3.0 and later)
752
+ #
753
+ # # pass
754
+ # refute_pattern { [1,2,3] => [String] }
755
+ #
756
+ # # fail "NoMatchingPatternError expected, but nothing was raised."
757
+ # refute_pattern { [1,2,3] => [Integer, Integer, Integer] }
758
+ #
759
+ # This assertion expects a NoMatchingPatternError exception, and will fail if none is raised. Any
760
+ # other exceptions will be raised as normal and generate a test error.
761
+
762
+ def refute_pattern
763
+ raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
764
+ flunk "refute_pattern requires a block to capture errors." unless block_given?
765
+
766
+ begin
767
+ yield
768
+ flunk("NoMatchingPatternError expected, but nothing was raised.")
769
+ rescue NoMatchingPatternError
770
+ pass
771
+ end
772
+ end
773
+
724
774
  ##
725
775
  # Fails if +o1+ is not +op+ +o2+. Eg:
726
776
  #
@@ -124,6 +124,15 @@ module Minitest::Expectations
124
124
 
125
125
  infect_an_assertion :assert_output, :must_output, :block
126
126
 
127
+ ##
128
+ # See Minitest::Assertions#assert_pattern_match
129
+ #
130
+ # _ { ... }.must_pattern_match [...]
131
+ #
132
+ # :method: must_pattern_match
133
+
134
+ infect_an_assertion :assert_pattern, :must_pattern_match, :block
135
+
127
136
  ##
128
137
  # See Minitest::Assertions#assert_raises
129
138
  #
@@ -283,6 +292,15 @@ module Minitest::Expectations
283
292
 
284
293
  infect_an_assertion :refute_operator, :wont_be, :reverse
285
294
 
295
+ ##
296
+ # See Minitest::Assertions#refute_pattern_match
297
+ #
298
+ # _ { ... }.wont_pattern_match [...]
299
+ #
300
+ # :method: wont_pattern_match
301
+
302
+ infect_an_assertion :refute_pattern, :wont_pattern_match, :block
303
+
286
304
  ##
287
305
  # See Minitest::Assertions#refute_respond_to
288
306
  #
data/lib/minitest/mock.rb CHANGED
@@ -55,7 +55,7 @@ module Minitest # :nodoc:
55
55
 
56
56
  ##
57
57
  # Expect that method +name+ is called, optionally with +args+ (and
58
- # +kwargs+ or a +blk+, and returns +retval+.
58
+ # +kwargs+ or a +blk+), and returns +retval+.
59
59
  #
60
60
  # @mock.expect(:meaning_of_life, 42)
61
61
  # @mock.meaning_of_life # => 42
data/lib/minitest.rb CHANGED
@@ -9,7 +9,7 @@ require "etc"
9
9
  # :include: README.rdoc
10
10
 
11
11
  module Minitest
12
- VERSION = "5.17.0" # :nodoc:
12
+ VERSION = "5.18.0" # :nodoc:
13
13
 
14
14
  @@installed_at_exit ||= false
15
15
  @@after_run = []
@@ -1062,6 +1062,66 @@ class TestMinitestAssertions < Minitest::Test
1062
1062
  end
1063
1063
  end
1064
1064
 
1065
+ def test_assert_pattern
1066
+ if RUBY_VERSION > "3" then
1067
+ @tc.assert_pattern do
1068
+ exp = if RUBY_VERSION.start_with? "3.0"
1069
+ "(eval):1: warning: One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!\n"
1070
+ else
1071
+ ""
1072
+ end
1073
+ assert_output nil, exp do
1074
+ eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
1075
+ end
1076
+ end
1077
+ else
1078
+ @assertion_count = 0
1079
+
1080
+ assert_raises NotImplementedError do
1081
+ @tc.assert_pattern do
1082
+ # do nothing
1083
+ end
1084
+ end
1085
+ end
1086
+ end
1087
+
1088
+ def test_assert_pattern_traps_nomatchingpatternerror
1089
+ skip unless RUBY_VERSION > "3"
1090
+ exp = if RUBY_VERSION.start_with? "3.0" then
1091
+ "[1, 2, 3]" # terrible error message!
1092
+ else
1093
+ /length mismatch/
1094
+ end
1095
+
1096
+ assert_triggered exp do
1097
+ @tc.assert_pattern do
1098
+ capture_io do # 3.0 is noisy
1099
+ eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
1100
+ end
1101
+ end
1102
+ end
1103
+ end
1104
+
1105
+ def test_assert_pattern_raises_other_exceptions
1106
+ skip unless RUBY_VERSION >= "3.0"
1107
+
1108
+ @assertion_count = 0
1109
+
1110
+ assert_raises RuntimeError do
1111
+ @tc.assert_pattern do
1112
+ raise "boom"
1113
+ end
1114
+ end
1115
+ end
1116
+
1117
+ def test_assert_pattern_with_no_block
1118
+ skip unless RUBY_VERSION >= "3.0"
1119
+
1120
+ assert_triggered "assert_pattern requires a block to capture errors." do
1121
+ @tc.assert_pattern
1122
+ end
1123
+ end
1124
+
1065
1125
  def test_capture_io
1066
1126
  @assertion_count = 0
1067
1127
 
@@ -1314,6 +1374,56 @@ class TestMinitestAssertions < Minitest::Test
1314
1374
  end
1315
1375
  end
1316
1376
 
1377
+ def test_refute_pattern
1378
+ if RUBY_VERSION >= "3.0"
1379
+ @tc.refute_pattern do
1380
+ capture_io do # 3.0 is noisy
1381
+ eval "[1,2,3] => [Integer, Integer, String]"
1382
+ end
1383
+ end
1384
+ else
1385
+ @assertion_count = 0
1386
+
1387
+ assert_raises NotImplementedError do
1388
+ @tc.refute_pattern do
1389
+ eval "[1,2,3] => [Integer, Integer, String]"
1390
+ end
1391
+ end
1392
+ end
1393
+ end
1394
+
1395
+ def test_refute_pattern_expects_nomatchingpatternerror
1396
+ skip unless RUBY_VERSION > "3"
1397
+
1398
+ assert_triggered(/NoMatchingPatternError expected, but nothing was raised./) do
1399
+ @tc.refute_pattern do
1400
+ capture_io do # 3.0 is noisy
1401
+ eval "[1,2,3] => [Integer, Integer, Integer]"
1402
+ end
1403
+ end
1404
+ end
1405
+ end
1406
+
1407
+ def test_refute_pattern_raises_other_exceptions
1408
+ skip unless RUBY_VERSION >= "3.0"
1409
+
1410
+ @assertion_count = 0
1411
+
1412
+ assert_raises RuntimeError do
1413
+ @tc.refute_pattern do
1414
+ raise "boom"
1415
+ end
1416
+ end
1417
+ end
1418
+
1419
+ def test_refute_pattern_with_no_block
1420
+ skip unless RUBY_VERSION >= "3.0"
1421
+
1422
+ assert_triggered "refute_pattern requires a block to capture errors." do
1423
+ @tc.refute_pattern
1424
+ end
1425
+ end
1426
+
1317
1427
  def test_refute_predicate
1318
1428
  @tc.refute_predicate "42", :empty?
1319
1429
  end
@@ -1083,7 +1083,7 @@ class TestMinitestStub < Minitest::Test
1083
1083
  end
1084
1084
  end
1085
1085
  end
1086
- exp = "undefined method `write' for nil:NilClass"
1086
+ exp = /undefined method `write' for nil/
1087
1087
  assert_match exp, e.message
1088
1088
  end
1089
1089
 
@@ -137,6 +137,46 @@ describe Minitest::Spec do
137
137
  end
138
138
  end
139
139
 
140
+ def good_pattern
141
+ capture_io do # 3.0 is noisy
142
+ eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
143
+ end
144
+ end
145
+
146
+ def bad_pattern
147
+ capture_io do # 3.0 is noisy
148
+ eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
149
+ end
150
+ end
151
+
152
+ it "needs to pattern match" do
153
+ @assertion_count = 1
154
+
155
+ if RUBY_VERSION > "3" then
156
+ expect { good_pattern }.must_pattern_match
157
+ else
158
+ assert_raises NotImplementedError do
159
+ expect {}.must_pattern_match
160
+ end
161
+ end
162
+ end
163
+
164
+ it "needs to error on bad pattern match" do
165
+ skip unless RUBY_VERSION > "3"
166
+
167
+ @assertion_count = 1
168
+
169
+ exp = if RUBY_VERSION.start_with? "3.0"
170
+ "[1, 2, 3]" # terrible error message!
171
+ else
172
+ /length mismatch/
173
+ end
174
+
175
+ assert_triggered exp do
176
+ expect { bad_pattern }.must_pattern_match
177
+ end
178
+ end
179
+
140
180
  it "needs to ensure silence" do
141
181
  @assertion_count -= 1 # no msg
142
182
  @assertion_count += 2 # assert_output is 2 assertions
@@ -172,6 +212,7 @@ describe Minitest::Spec do
172
212
  must_include
173
213
  must_match
174
214
  must_output
215
+ must_pattern_match
175
216
  must_raise
176
217
  must_respond_to
177
218
  must_throw
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.17.0
4
+ version: 5.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  ROfWo9Uyp8ba/j9eVG14KkYRaLydAY1MNQk2yd3R5CGfeOpD1kttxjoypoUJ2dOG
30
30
  nsNBRuQJ1UfiCG97a6DNm+Fr
31
31
  -----END CERTIFICATE-----
32
- date: 2023-01-01 00:00:00.000000000 Z
32
+ date: 2023-03-04 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdoc
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
185
  requirements: []
186
- rubygems_version: 3.3.12
186
+ rubygems_version: 3.4.6
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: minitest provides a complete suite of testing facilities supporting TDD,
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- |Plu�\���#/�\ogx
2
- ��o*[*��m�ݡ�^o3�w�S���o/��5��RO �˯' ��~RϖXl��?w���Al��ƀ���� *� �;�-ϯӛ�Si�Č�P=��d� �����0n0?"D�b�W�N�m��pk!�^�j�����X�]"���Ho��$�qe�7�:�=��T̿tEZ�6�[Yh5�Dq�4�RDt;D�� I
1
+ !�u��$��T����1X���޺wO��Nb�in��y��z+�|�Sܗbt�|9���_�aXߵ�����Op]9o��E�׀����G���k"����Hh���'�>K�����n�K<+\шy�CƏ?���x1�{j�&�:ߢ��Br�1