minitest 5.26.1 → 6.0.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/History.rdoc +138 -0
  4. data/Manifest.txt +13 -4
  5. data/README.rdoc +14 -98
  6. data/Rakefile +10 -1
  7. data/bin/minitest +5 -0
  8. data/lib/hoe/minitest.rb +2 -1
  9. data/lib/minitest/assertions.rb +44 -73
  10. data/lib/minitest/autorun.rb +3 -4
  11. data/lib/minitest/benchmark.rb +3 -3
  12. data/lib/minitest/bisect.rb +304 -0
  13. data/lib/minitest/complete.rb +56 -0
  14. data/lib/minitest/find_minimal_combination.rb +127 -0
  15. data/lib/minitest/hell.rb +1 -1
  16. data/lib/minitest/manual_plugins.rb +4 -16
  17. data/lib/minitest/parallel.rb +3 -3
  18. data/lib/minitest/path_expander.rb +432 -0
  19. data/lib/minitest/pride.rb +2 -2
  20. data/lib/minitest/pride_plugin.rb +1 -1
  21. data/lib/minitest/server.rb +49 -0
  22. data/lib/minitest/server_plugin.rb +88 -0
  23. data/lib/minitest/spec.rb +5 -33
  24. data/lib/minitest/sprint.rb +105 -0
  25. data/lib/minitest/sprint_plugin.rb +39 -0
  26. data/lib/minitest/test.rb +7 -13
  27. data/lib/minitest/test_task.rb +18 -16
  28. data/lib/minitest.rb +88 -94
  29. data/test/minitest/metametameta.rb +1 -1
  30. data/test/minitest/test_bisect.rb +249 -0
  31. data/test/minitest/test_find_minimal_combination.rb +138 -0
  32. data/test/minitest/test_minitest_assertions.rb +111 -102
  33. data/test/minitest/test_minitest_benchmark.rb +14 -0
  34. data/test/minitest/test_minitest_reporter.rb +6 -5
  35. data/test/minitest/test_minitest_spec.rb +51 -117
  36. data/test/minitest/test_minitest_test.rb +21 -100
  37. data/test/minitest/test_path_expander.rb +229 -0
  38. data/test/minitest/test_server.rb +146 -0
  39. data.tar.gz.sig +0 -0
  40. metadata +90 -28
  41. metadata.gz.sig +0 -0
  42. data/.autotest +0 -34
  43. data/lib/minitest/mock.rb +0 -347
  44. data/lib/minitest/unit.rb +0 -42
  45. data/test/minitest/test_minitest_mock.rb +0 -1218
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99c81ecf40f2e6edde9201cded0808484223cdf20d3e819e1b043e50bcc2564c
4
- data.tar.gz: 543e61e5ac5da94ddbaaa51969b0b5dbf2ea91b400c13fd88830396a22627867
3
+ metadata.gz: 5bd5f764a0e5823b6af414ce7869ad229d5f417e901796475965dc869f81b0c3
4
+ data.tar.gz: b82a599afbc0ea6d9e4fe022fdf2fb20f81d875d012c57dd0db9cc7bf2a15acc
5
5
  SHA512:
6
- metadata.gz: 1e73adb8391043dc989b7dd2c307f5e5af72f2f2e51ef1e0fda7654cff90755fd920e2003f86ef0fa62bae2fbc9e9ec9a7a6bea76abc6a46c5b7f0500fa5b337
7
- data.tar.gz: 3a860d654d72db62a86397b6849fa5509e21e5f5a021e920b0bca46d147cd8f5d7d5203ad28eb73b22b2a643683db0e8fa8948437688ec18642ef21666e3095f
6
+ metadata.gz: da7ef69a9a580f646ec8071574af269cc3c6a31055d2fbb5eecd6b4ba332338c91ad09469f85982b6882354e67fe82845636671bc8fd2cabe85db97497391d18
7
+ data.tar.gz: 05bad64ac6aa587be47737759231213c1ae86f2d7b78837392a6efddc3e7559b7f293a9d38056ed8dbcff868d601c2c6c2fea673a185da30d50d2c5193e164f7
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,141 @@
1
+ === 6.0.6 / 2026-04-30
2
+
3
+ * 2 bug fixes:
4
+
5
+ * Fix using assert_equal/same/nil w/ BasicObject by comparing w/ `nil == exp`. (mtasaka)
6
+ * Removed private Assertions#_where as it is no longer used.
7
+
8
+ === 6.0.5 / 2026-04-20
9
+
10
+ * 2 bug fixes:
11
+
12
+ * Avoid circular requires in lib/minitest/server_plugin.rb.
13
+ * Raise TypeError if assert_raises is passed anything but modules/classes.
14
+
15
+ === 6.0.4 / 2026-04-14
16
+
17
+ * 1 bug fix:
18
+
19
+ * Fixed refute_predicate to call assert_respond_to w/ include_all:true like assert_predicate does. (jparker)
20
+
21
+ === 6.0.3 / 2026-03-31
22
+
23
+ * 1 bug fix:
24
+
25
+ * assert_same(nil, value) no longer allowed. Use assert_nil to be explicit. (paddor)
26
+
27
+ === 6.0.2 / 2026-02-23
28
+
29
+ * 7 bug fixes:
30
+
31
+ * Added missing drb dependency from minitest-server. (y-yagi)
32
+ * Cleaned up bisect's sub-commands to load files directly, not ruby+require.
33
+ * Fixed bisect to use same cmd ($0) to run tests as original invocation.
34
+ * load server_plugin if server is loaded. (y-yagi)
35
+ * Manipulate local args instead of ARGV in Sprint.run.
36
+ * Only show --bisect in usage if using minitest.
37
+ * Remove -Itest:lib from bisect's rb_flags since bin/minitest adds them.
38
+
39
+ === 6.0.1 / 2025-12-26
40
+
41
+ * 1 minor enhancement:
42
+
43
+ * Added new rake task `test:fu` to Minitest::TestTask, to only run
44
+ tests with FU (focused units?) in their name. This should mostly
45
+ obviate the need for the minitest-focus plugin.
46
+
47
+ * 5 bug fixes:
48
+
49
+ * Fixed --help and --version exiting 1. (grosser)
50
+ * Fixed method signature of Minitest::Benchmark.run. (flavorjones)
51
+ * Flush stdout/stderr before exit./bin/minitest -Ilib ./bug1046.rb:1 < /dev/null (grosser)
52
+ * Improved usage banner output by reordering and reformatting.
53
+ * Normalize paths while processing file.rb:line args.
54
+
55
+ === 6.0.0 / 2025-12-17
56
+
57
+ This is a major release. Read this.
58
+
59
+ Please give feedback here: https://github.com/minitest/minitest/issues/1040
60
+
61
+ Oh god... here we go... (again)
62
+
63
+ * 8 deaths in the family(!!):
64
+
65
+ * Deleted MiniTest and MiniTest::Unit::TestCase compatibility namespaces.
66
+ * Deleted all use of Marshal for serialization.
67
+ * Deleted maglev? and rubinius? guard methods. LOL.
68
+ * Deleted all minitest/spec expectations from Object. Use _/value/expect.
69
+ * Dropped minitest/mock.rb. This has been extracted to the minitest-mock gem.
70
+ * assert_equal(nil, value) no longer allowed. Use assert_nil to be explicit.
71
+ * Removed assert_send. Use assert_predicate or assert_operator.
72
+ * Removed Minitest::Test#class_name.
73
+
74
+ * 7 major (oft incompatible) changes:
75
+
76
+ * Big: Major refactored MT6's run path!
77
+ * Minitest.__run -> Minitest.run_all_suites
78
+ * Runnable.run -> Runnable.run_suite & Runnable.filter_runnable_methods
79
+ * Runnable.run_one_method -> Runnable.run
80
+ * Removed Minitest.run_one_method (might bring it back to raise?)
81
+ * Removed deprecated <tt>ENV["N"]</tt> to specify number of parallel tests. Use MT_CPU.
82
+ * Renamed +options[:filter]+ to +options[:include]+, added <tt>--include</tt> cmdline option.
83
+ * <tt>--name</tt> is still handled, but that will be removed in the future.
84
+ * Renamed Minitest::Runnable#test_order to #run_order.
85
+ * If #message is passed a proc then that proc overrides all other output.
86
+ * They are no longer chained!
87
+ * And it does less for formatting of your output.
88
+ * Removed reporter arg from with_info_handler as it has never(?) been used. (HACK?)
89
+ * Plugin loading is now opt-in!
90
+ * Require the plugin in your test_helper.
91
+ * Or use Minitest.load :x
92
+ * Or call Minitest.load_plugins for the old autoloading behavior.
93
+
94
+ * 5 additions:
95
+
96
+ * Added minitest-sprint's minitest cmdline, now with line support!
97
+ * Added minitest-bisect. Run with minitest --bisect or -b.
98
+ * Added minitest-server.
99
+ * Added minitest/complete to help with shell's tab-completion of tests.
100
+ * Vendored latest version of path_expander.
101
+
102
+ * 5 other:
103
+
104
+ * Bumped to ruby 3.2+.
105
+ * Removed obsolete conditional for CompositeReporter#prerecord.
106
+ * Removed obsolete version guards around Minitest::Result in reporters.
107
+ * assert_operator and assert_predicate both call assert_respond_to first.
108
+ * Assertions reuse themselves a lot more. Bumps assertion count in some places.
109
+
110
+ === 5.27.0 / 2025-12-11
111
+
112
+ * 1 major enhancement:
113
+
114
+ * Adding post install message announcing the EOL for minitest 5!
115
+
116
+ * 2 minor enhancements:
117
+
118
+ * Removed TestTask::Work#initialize since Queue can now initialize with an Enumerable! AMAZING!
119
+ * Use Kernel#warn uplevel argument for nicer warnings. (byroot)
120
+
121
+ * 5 bug fixes:
122
+
123
+ * Cleaned up option aliasing a tad.
124
+ * Removed obsolete conditional for prerecord
125
+ * Removed obsolete guards around Warning.
126
+ * Removed obsolete version guards for pattern matching assertions.
127
+ * Switched all internal requires to require_relative.
128
+
129
+ === 5.26.2 / 2025-11-17
130
+
131
+ * 5 bug fixes:
132
+
133
+ * Bumped minimum ruby to 3.1.
134
+ * Alias Spec#name to #inspect for cleaner output in repls.
135
+ * Fix pathing for Hoe::Minitest initialization to be more generic.
136
+ * Fixed refute_in_epsilon to use min of abs values. (wtn)
137
+ * Improved options processing and usage output to be more clear.
138
+
1
139
  === 5.26.1 / 2025-11-08
2
140
 
3
141
  The Ocean Shores, Slightly Less Tipsy Edition!
data/Manifest.txt CHANGED
@@ -1,32 +1,41 @@
1
- .autotest
2
1
  History.rdoc
3
2
  Manifest.txt
4
3
  README.rdoc
5
4
  Rakefile
5
+ bin/minitest
6
6
  design_rationale.rb
7
7
  lib/hoe/minitest.rb
8
8
  lib/minitest.rb
9
9
  lib/minitest/assertions.rb
10
10
  lib/minitest/autorun.rb
11
11
  lib/minitest/benchmark.rb
12
+ lib/minitest/bisect.rb
13
+ lib/minitest/complete.rb
12
14
  lib/minitest/compress.rb
13
15
  lib/minitest/error_on_warning.rb
14
16
  lib/minitest/expectations.rb
17
+ lib/minitest/find_minimal_combination.rb
15
18
  lib/minitest/hell.rb
16
19
  lib/minitest/manual_plugins.rb
17
- lib/minitest/mock.rb
18
20
  lib/minitest/parallel.rb
21
+ lib/minitest/path_expander.rb
19
22
  lib/minitest/pride.rb
20
23
  lib/minitest/pride_plugin.rb
24
+ lib/minitest/server.rb
25
+ lib/minitest/server_plugin.rb
21
26
  lib/minitest/spec.rb
27
+ lib/minitest/sprint.rb
28
+ lib/minitest/sprint_plugin.rb
22
29
  lib/minitest/test.rb
23
30
  lib/minitest/test_task.rb
24
- lib/minitest/unit.rb
25
31
  test/minitest/metametameta.rb
32
+ test/minitest/test_bisect.rb
33
+ test/minitest/test_find_minimal_combination.rb
26
34
  test/minitest/test_minitest_assertions.rb
27
35
  test/minitest/test_minitest_benchmark.rb
28
- test/minitest/test_minitest_mock.rb
29
36
  test/minitest/test_minitest_reporter.rb
30
37
  test/minitest/test_minitest_spec.rb
31
38
  test/minitest/test_minitest_test.rb
32
39
  test/minitest/test_minitest_test_task.rb
40
+ test/minitest/test_path_expander.rb
41
+ test/minitest/test_server.rb
data/README.rdoc CHANGED
@@ -1,16 +1,17 @@
1
- = minitest/{test,spec,mock,benchmark}
1
+ = minitest/{test,spec,benchmark}
2
2
 
3
- home :: https://github.com/minitest/minitest
3
+ home :: https://minite.st/
4
+ code :: https://github.com/minitest/minitest
4
5
  bugs :: https://github.com/minitest/minitest/issues
5
6
  rdoc :: https://docs.seattlerb.org/minitest
6
7
  clog :: https://github.com/minitest/minitest/blob/master/History.rdoc
7
- vim :: https://github.com/sunaku/vim-ruby-minitest
8
8
  emacs:: https://github.com/arthurnn/minitest-emacs
9
+ vim :: https://github.com/vim-test/vim-test
9
10
 
10
11
  == DESCRIPTION:
11
12
 
12
13
  minitest provides a complete suite of testing facilities supporting
13
- TDD, BDD, mocking, and benchmarking.
14
+ TDD, BDD, and benchmarking.
14
15
 
15
16
  "I had a class with Jim Weirich on testing last week and we were
16
17
  allowed to choose our testing frameworks. Kirk Haines and I were
@@ -36,9 +37,6 @@ algorithms in a repeatable manner. Now you can assert that your newb
36
37
  co-worker doesn't replace your linear algorithm with an exponential
37
38
  one!
38
39
 
39
- minitest/mock by Steven Baker, is a beautifully tiny mock (and stub)
40
- object framework.
41
-
42
40
  minitest/pride shows pride in testing and adds coloring to your test
43
41
  output. I guess it is an example of how to write IO pipes too. :P
44
42
 
@@ -68,7 +66,6 @@ extract-method refactorings still apply.
68
66
  * minitest/autorun - the easy and explicit way to run all your tests.
69
67
  * minitest/test - a very fast, simple, and clean test system.
70
68
  * minitest/spec - a very fast, simple, and clean spec system.
71
- * minitest/mock - a simple and clean mock/stub system.
72
69
  * minitest/benchmark - an awesome way to assert your algorithm's performance.
73
70
  * minitest/pride - show your pride in testing!
74
71
  * minitest/test_task - a full-featured and clean rake task generator.
@@ -190,85 +187,6 @@ outputs something like:
190
187
 
191
188
  Output is tab-delimited to make it easy to paste into a spreadsheet.
192
189
 
193
- === Mocks
194
-
195
- Mocks and stubs defined using terminology by Fowler & Meszaros at
196
- https://www.martinfowler.com/bliki/TestDouble.html:
197
-
198
- "Mocks are pre-programmed with expectations which form a specification
199
- of the calls they are expected to receive. They can throw an exception
200
- if they receive a call they don't expect and are checked during
201
- verification to ensure they got all the calls they were expecting."
202
-
203
- class MemeAsker
204
- def initialize(meme)
205
- @meme = meme
206
- end
207
-
208
- def ask(question)
209
- method = question.tr(" ", "_") + "?"
210
- @meme.__send__(method)
211
- end
212
- end
213
-
214
- require "minitest/autorun"
215
-
216
- describe MemeAsker, :ask do
217
- describe "when passed an unpunctuated question" do
218
- it "should invoke the appropriate predicate method on the meme" do
219
- @meme = Minitest::Mock.new
220
- @meme_asker = MemeAsker.new @meme
221
- @meme.expect :will_it_blend?, :return_value
222
-
223
- @meme_asker.ask "will it blend"
224
-
225
- @meme.verify
226
- end
227
- end
228
- end
229
-
230
- ==== Multi-threading and Mocks
231
-
232
- Minitest mocks do not support multi-threading. If it works, fine, if it doesn't
233
- you can use regular ruby patterns and facilities like local variables. Here's
234
- an example of asserting that code inside a thread is run:
235
-
236
- def test_called_inside_thread
237
- called = false
238
- pr = Proc.new { called = true }
239
- thread = Thread.new(&pr)
240
- thread.join
241
- assert called, "proc not called"
242
- end
243
-
244
- === Stubs
245
-
246
- Mocks and stubs are defined using terminology by Fowler & Meszaros at
247
- https://www.martinfowler.com/bliki/TestDouble.html:
248
-
249
- "Stubs provide canned answers to calls made during the test".
250
-
251
- Minitest's stub method overrides a single method for the duration of
252
- the block.
253
-
254
- def test_stale_eh
255
- obj_under_test = Something.new
256
-
257
- refute obj_under_test.stale?
258
-
259
- Time.stub :now, Time.at(0) do # stub goes away once the block is done
260
- assert obj_under_test.stale?
261
- end
262
- end
263
-
264
- A note on stubbing: In order to stub a method, the method must
265
- actually exist prior to stubbing. Use a singleton method to create a
266
- new non-existing method:
267
-
268
- def obj_under_test.fake_method
269
- ...
270
- end
271
-
272
190
  === Running Your Tests
273
191
 
274
192
  Ideally, you'll use a rake task to run your tests (see below), either
@@ -427,13 +345,10 @@ Current versions of rails: (https://endoflife.date/rails)
427
345
 
428
346
  | rails | min ruby | minitest | status | EOL Date |
429
347
  |-------+----------+----------+----------+------------|
348
+ | 8.1 | >= 3.2 | >= 5.1 | Current | 2027-10-07 |
430
349
  | 8.0 | >= 3.2 | >= 5.1 | Current | 2026-11-07 |
431
- | 7.2 | >= 3.1 | >= 5.1 | Current | 2026-08-09 |
432
- | 7.1 | >= 2.7 | >= 5.1 | Security | 2025-10-01 |
433
- | 7.0 | >= 2.7 | >= 5.1 | Security | 2025-04-01 |
434
- | 6.1 | >= 2.5 | >= 5.1 | EOL | 2024-10-01 |
435
- | 6.0 | >= 2.5 | >= 5.1 | EOL | 2023-06-01 |
436
- | 5.2 | >= 2.2.2 | ~> 5.1 | EOL | 2022-06-01 |
350
+ | 7.2 | >= 3.1 | >= 5.1 | Security | 2026-08-09 |
351
+ | 7.1 | >= 2.7 | >= 5.1 | EOL | 2025-10-01 |
437
352
 
438
353
  If you want to look at the requirements for a specific version, run:
439
354
 
@@ -689,6 +604,9 @@ minitest-happy :: GLOBALLY ACTIVATE MINITEST PRIDE! RAWR!
689
604
  minitest-have_tag :: Adds Minitest assertions to test for the existence of
690
605
  HTML tags, including contents, within a provided string.
691
606
  minitest-heat :: Reporting that builds a heat map of failure locations
607
+ minitest-holdify :: Stop maintaining large expected values in your
608
+ test/fixture files! Hold them automatically.
609
+ Update them effortlessly.
692
610
  minitest-hooks :: Around and before_all/after_all/around_all hooks
693
611
  minitest-hyper :: Pretty, single-page HTML reports for your Minitest runs
694
612
  minitest-implicit-subject :: Implicit declaration of the test subject.
@@ -763,12 +681,10 @@ mongoid-minitest :: Minitest matchers for Mongoid.
763
681
  mutant-minitest :: Minitest integration for mutant.
764
682
  pry-rescue :: A pry plugin w/ minitest support. See
765
683
  pry-rescue/minitest.rb.
766
- rematch :: Declutter your test files from large hardcoded data
767
- and update them automatically when your code changes.
768
684
  rspec2minitest :: Easily translate any RSpec matchers to Minitest
769
685
  assertions and expectations.
770
- stubberry :: Multiple stubbing 'berries', sweet and useful
771
- stub helpers and assertions. ( stub_must,
686
+ stubberry :: Multiple stubbing 'berries', sweet and useful
687
+ stub helpers and assertions. ( stub_must,
772
688
  assert_method_called, stubbing ORM objects by id )
773
689
 
774
690
  == Unknown Extensions:
@@ -799,7 +715,7 @@ Authors... Please send me a pull request with a description of your minitest ext
799
715
 
800
716
  == REQUIREMENTS:
801
717
 
802
- * Ruby 2.3+. No magic is involved. I hope.
718
+ * Ruby 3.2+. No magic is involved. I hope.
803
719
 
804
720
  == INSTALL:
805
721
 
data/Rakefile CHANGED
@@ -4,14 +4,23 @@ require "hoe"
4
4
  $:.unshift "lib" # to pick up lib/minitest/test_task.rb when minitest not installed
5
5
 
6
6
  Hoe.plugin :seattlerb
7
+ Hoe.plugin :isolate
7
8
  Hoe.plugin :rdoc
9
+ Hoe.plugin :cov
8
10
 
9
11
  Hoe.spec "minitest" do
10
12
  developer "Ryan Davis", "ryand-ruby@zenspider.com"
11
13
 
12
14
  license "MIT"
13
15
 
14
- require_ruby_version ">= 2.7"
16
+ require_ruby_version ">= 3.2"
17
+
18
+ dependency "prism", "~> 1.5"
19
+ dependency "drb", "~> 2.0"
20
+
21
+ self.rdoc_locations << "l:/home/www/minite.st/html/docs"
22
+
23
+ self.cov_filter = %w[ tmp ]
15
24
  end
16
25
 
17
26
  desc "Find missing expectations"
data/bin/minitest ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env -S ruby
2
+
3
+ require_relative "../lib/minitest/sprint"
4
+
5
+ Minitest::Sprint.run
data/lib/hoe/minitest.rb CHANGED
@@ -11,7 +11,8 @@ module Hoe::Minitest
11
11
 
12
12
  def initialize_minitest
13
13
  unless minitest? then
14
- dir = "../../minitest/dev/lib"
14
+ dir = File.expand_path "../..", __FILE__
15
+
15
16
  Hoe.add_include_dirs dir if File.directory? dir
16
17
  end
17
18
 
@@ -186,18 +186,10 @@ module Minitest
186
186
  # Fails unless +obj+ is empty.
187
187
 
188
188
  def assert_empty obj, msg = nil
189
- msg = message(msg) { "Expected #{mu_pp obj} to be empty" }
190
- assert_respond_to obj, :empty?
191
- assert obj.empty?, msg
189
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be empty" }
190
+ assert_predicate obj, :empty?, msg
192
191
  end
193
192
 
194
- def _where # :nodoc:
195
- Minitest.filter_backtrace(caller).first
196
- .split(":in ", 2).first # clean up noise
197
- end
198
-
199
- E = "" # :nodoc:
200
-
201
193
  ##
202
194
  # Fails unless <tt>exp == act</tt> printing the difference between
203
195
  # the two, if possible.
@@ -212,18 +204,11 @@ module Minitest
212
204
  # See also: Minitest::Assertions.diff
213
205
 
214
206
  def assert_equal exp, act, msg = nil
215
- msg = message(msg, E) { diff exp, act }
216
- result = assert exp == act, msg
207
+ msg = message(msg, nil) { diff exp, act }
217
208
 
218
- if nil == exp then
219
- if Minitest::VERSION >= "6" then
220
- refute_nil exp, "Use assert_nil if expecting nil."
221
- else
222
- warn "DEPRECATED: Use assert_nil if expecting nil from #{_where}. This will fail in Minitest 6."
223
- end
224
- end
209
+ refute_nil exp, message { "Use assert_nil if expecting nil" } if nil == exp # don't count
225
210
 
226
- result
211
+ assert exp == act, msg
227
212
  end
228
213
 
229
214
  ##
@@ -255,8 +240,7 @@ module Minitest
255
240
  msg = message(msg) {
256
241
  "Expected #{mu_pp collection} to include #{mu_pp obj}"
257
242
  }
258
- assert_respond_to collection, :include?
259
- assert collection.include?(obj), msg
243
+ assert_operator collection, :include?, obj, msg
260
244
  end
261
245
 
262
246
  ##
@@ -298,7 +282,7 @@ module Minitest
298
282
 
299
283
  def assert_nil obj, msg = nil
300
284
  msg = message(msg) { "Expected #{mu_pp obj} to be nil" }
301
- assert obj.nil?, msg
285
+ assert nil == obj, msg
302
286
  end
303
287
 
304
288
  ##
@@ -308,6 +292,7 @@ module Minitest
308
292
 
309
293
  def assert_operator o1, op, o2 = UNDEFINED, msg = nil
310
294
  return assert_predicate o1, op, msg if UNDEFINED == o2
295
+ assert_respond_to o1, op
311
296
  msg = message(msg) { "Expected #{mu_pp o1} to be #{op} #{mu_pp o2}" }
312
297
  assert o1.__send__(op, o2), msg
313
298
  end
@@ -368,15 +353,12 @@ module Minitest
368
353
  # error.
369
354
 
370
355
  def assert_pattern
371
- raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
372
356
  flunk "assert_pattern requires a block to capture errors." unless block_given?
373
357
 
374
- begin # TODO: remove after ruby 2.6 dropped
375
- yield
376
- pass
377
- rescue NoMatchingPatternError => e
378
- flunk e.message
379
- end
358
+ yield
359
+ pass
360
+ rescue NoMatchingPatternError => e
361
+ flunk e.message
380
362
  end
381
363
 
382
364
  ##
@@ -389,10 +371,13 @@ module Minitest
389
371
  # str.must_be :empty?
390
372
 
391
373
  def assert_predicate o1, op, msg = nil
374
+ assert_respond_to o1, op, include_all:true
392
375
  msg = message(msg) { "Expected #{mu_pp o1} to be #{op}" }
393
376
  assert o1.__send__(op), msg
394
377
  end
395
378
 
379
+ NO_RE_MSG = "class or module required for rescue clause. Got %p"
380
+
396
381
  ##
397
382
  # Fails unless the block raises one of +exp+. Returns the
398
383
  # exception matched so you can check the message, attributes, etc.
@@ -422,6 +407,9 @@ module Minitest
422
407
  msg = "#{exp.pop}.\n" if String === exp.last
423
408
  exp << StandardError if exp.empty?
424
409
 
410
+ # TODO: remove this if https://bugs.ruby-lang.org/issues/22007 gets fixed
411
+ raise TypeError, NO_RE_MSG % [exp] unless exp.all? Module
412
+
425
413
  begin
426
414
  yield
427
415
  rescue *exp => e
@@ -448,9 +436,7 @@ module Minitest
448
436
  # include_all defaults to false to match Object#respond_to?
449
437
 
450
438
  def assert_respond_to obj, meth, msg = nil, include_all: false
451
- msg = message(msg) {
452
- "Expected #{mu_pp obj} (#{obj.class}) to respond to ##{meth}"
453
- }
439
+ msg = message(msg) { "Expected #{mu_pp obj} (#{obj.class}) to respond to ##{meth}" }
454
440
  assert obj.respond_to?(meth, include_all), msg
455
441
  end
456
442
 
@@ -462,22 +448,10 @@ module Minitest
462
448
  data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
463
449
  "Expected %s (oid=%d) to be the same as %s (oid=%d)" % data
464
450
  }
465
- assert exp.equal?(act), msg
466
- end
467
451
 
468
- ##
469
- # +send_ary+ is a receiver, message and arguments.
470
- #
471
- # Fails unless the call returns a true value
452
+ refute_nil exp, message { "Use assert_nil if expecting nil" } if nil == exp # don't count
472
453
 
473
- def assert_send send_ary, m = nil
474
- warn "DEPRECATED: assert_send. From #{_where}"
475
-
476
- recv, msg, *args = send_ary
477
- m = message(m) {
478
- "Expected #{mu_pp recv}.#{msg}(*#{mu_pp args}) to return true"
479
- }
480
- assert recv.__send__(msg, *args), m
454
+ assert exp.equal?(act), msg
481
455
  end
482
456
 
483
457
  ##
@@ -624,13 +598,16 @@ module Minitest
624
598
  end
625
599
 
626
600
  ##
627
- # Returns a proc that will output +msg+ along with the default message.
601
+ # Returns a proc that delays generation of an output message. If
602
+ # +msg+ is a proc (eg, from another +message+ call) return +msg+
603
+ # as-is. Otherwise, return a proc that will output +msg+ along
604
+ # with the value of the result of the block passed to +message+.
628
605
 
629
- def message msg = nil, ending = nil, &default
606
+ def message msg = nil, ending = ".", &default
607
+ return msg if Proc === msg
630
608
  proc {
631
- msg = msg.call.chomp(".") if Proc === msg
632
- custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
633
- "#{custom_message}#{default.call}#{ending || "."}"
609
+ custom_message = "#{msg}.\n" unless nil == msg or msg.to_s.empty?
610
+ "#{custom_message}#{default.call}#{ending}"
634
611
  }
635
612
  end
636
613
 
@@ -654,8 +631,7 @@ module Minitest
654
631
 
655
632
  def refute_empty obj, msg = nil
656
633
  msg = message(msg) { "Expected #{mu_pp obj} to not be empty" }
657
- assert_respond_to obj, :empty?
658
- refute obj.empty?, msg
634
+ refute_predicate obj, :empty?, msg
659
635
  end
660
636
 
661
637
  ##
@@ -687,19 +663,16 @@ module Minitest
687
663
  # For comparing Floats. Fails if +exp+ and +act+ have a relative error
688
664
  # less than +epsilon+.
689
665
 
690
- def refute_in_epsilon a, b, epsilon = 0.001, msg = nil
691
- refute_in_delta a, b, a * epsilon, msg
666
+ def refute_in_epsilon exp, act, epsilon = 0.001, msg = nil
667
+ refute_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
692
668
  end
693
669
 
694
670
  ##
695
- # Fails if +collection+ includes +obj+.
671
+ # Fails if +obj+ includes +sub+.
696
672
 
697
- def refute_includes collection, obj, msg = nil
698
- msg = message(msg) {
699
- "Expected #{mu_pp collection} to not include #{mu_pp obj}"
700
- }
701
- assert_respond_to collection, :include?
702
- refute collection.include?(obj), msg
673
+ def refute_includes obj, sub, msg = nil
674
+ msg = message(msg) { "Expected #{mu_pp obj} to not include #{mu_pp sub}" }
675
+ refute_operator obj, :include?, sub, msg
703
676
  end
704
677
 
705
678
  ##
@@ -725,9 +698,8 @@ module Minitest
725
698
 
726
699
  def refute_match matcher, obj, msg = nil
727
700
  msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
728
- assert_respond_to matcher, :=~
729
701
  matcher = Regexp.new Regexp.escape matcher if String === matcher
730
- refute matcher =~ obj, msg
702
+ refute_operator matcher, :=~, obj, msg
731
703
  end
732
704
 
733
705
  ##
@@ -735,7 +707,7 @@ module Minitest
735
707
 
736
708
  def refute_nil obj, msg = nil
737
709
  msg = message(msg) { "Expected #{mu_pp obj} to not be nil" }
738
- refute obj.nil?, msg
710
+ refute nil == obj, msg
739
711
  end
740
712
 
741
713
  ##
@@ -751,15 +723,12 @@ module Minitest
751
723
  # other exceptions will be raised as normal and generate a test error.
752
724
 
753
725
  def refute_pattern
754
- raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
755
726
  flunk "refute_pattern requires a block to capture errors." unless block_given?
756
727
 
757
- begin
758
- yield
759
- flunk "NoMatchingPatternError expected, but nothing was raised."
760
- rescue NoMatchingPatternError
761
- pass
762
- end
728
+ yield
729
+ flunk "NoMatchingPatternError expected, but nothing was raised."
730
+ rescue NoMatchingPatternError
731
+ pass
763
732
  end
764
733
 
765
734
  ##
@@ -770,6 +739,7 @@ module Minitest
770
739
 
771
740
  def refute_operator o1, op, o2 = UNDEFINED, msg = nil
772
741
  return refute_predicate o1, op, msg if UNDEFINED == o2
742
+ assert_respond_to o1, op
773
743
  msg = message(msg) { "Expected #{mu_pp o1} to not be #{op} #{mu_pp o2}" }
774
744
  refute o1.__send__(op, o2), msg
775
745
  end
@@ -792,6 +762,7 @@ module Minitest
792
762
  # str.wont_be :empty?
793
763
 
794
764
  def refute_predicate o1, op, msg = nil
765
+ assert_respond_to o1, op, include_all:true
795
766
  msg = message(msg) { "Expected #{mu_pp o1} to not be #{op}" }
796
767
  refute o1.__send__(op), msg
797
768
  end