minitest 5.14.4 → 5.20.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +121 -1
- data/Manifest.txt +2 -0
- data/README.rdoc +67 -35
- data/Rakefile +2 -1
- data/lib/hoe/minitest.rb +0 -4
- data/lib/minitest/assertions.rb +57 -6
- data/lib/minitest/benchmark.rb +5 -5
- data/lib/minitest/expectations.rb +18 -0
- data/lib/minitest/mock.rb +116 -33
- data/lib/minitest/pride_plugin.rb +1 -1
- data/lib/minitest/spec.rb +9 -2
- data/lib/minitest/test.rb +44 -16
- data/lib/minitest/test_task.rb +302 -0
- data/lib/minitest/unit.rb +5 -8
- data/lib/minitest.rb +101 -36
- data/test/minitest/metametameta.rb +1 -1
- data/test/minitest/test_minitest_assertions.rb +142 -16
- data/test/minitest/test_minitest_benchmark.rb +2 -2
- data/test/minitest/test_minitest_mock.rb +275 -13
- data/test/minitest/test_minitest_reporter.rb +59 -17
- data/test/minitest/test_minitest_spec.rb +101 -16
- data/test/minitest/test_minitest_test.rb +230 -32
- data/test/minitest/test_minitest_test_task.rb +46 -0
- data.tar.gz.sig +0 -0
- metadata +19 -17
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 667a803a272949e7b05440f91a56155ea3977a5b9d364542801889c5a2fe0ff0
|
4
|
+
data.tar.gz: 862bf0ff3d24eea4bbe6c7f435ceef19aaa97748f6a87ec3fa51dc218ca79298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2284c84ae5f98a3454e9a95417e609ca1a8ef9af8ee8b1fad8f2aca2632fde6a309e266ef1d399d9a7d47337cdcba696500a1b36f1fa7d952615eb390a89e329
|
7
|
+
data.tar.gz: a76204f74c2caf693a4302065815b871863ae655372d25fc4d41e416b0d4935704c1e1068457b5cda934312e3915ae8a27595ca962c98e544dd45b54cac2aef7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,3 +1,123 @@
|
|
1
|
+
=== 5.20.0 / 2023-09-06
|
2
|
+
|
3
|
+
* 1 minor enhancement:
|
4
|
+
|
5
|
+
* Optionally allow autorun exit hook to remain active in forked child. (casperisfine)
|
6
|
+
|
7
|
+
=== 5.19.0 / 2023-07-26
|
8
|
+
|
9
|
+
* 2 minor enhancements:
|
10
|
+
|
11
|
+
* Add metadata lazy accessor to Runnable / Result. (matteeyah)
|
12
|
+
* Only load minitest/unit (aka ancient MiniTest compatibility layer) if ENV["MT_COMPAT"]
|
13
|
+
|
14
|
+
* 1 bug fix:
|
15
|
+
|
16
|
+
* Minitest::TestTask enthusiastically added itself to default. (ParadoxV5)
|
17
|
+
|
18
|
+
=== 5.18.1 / 2023-06-16
|
19
|
+
|
20
|
+
* 3 bug fixes:
|
21
|
+
|
22
|
+
* Avoid extra string allocations when filtering tests. (tenderlove)
|
23
|
+
* Only mention deprecated ENV['N'] if it is an integer string.
|
24
|
+
* Push up test_order to Minitest::Runnable to fix minitest/hell. (koic)
|
25
|
+
|
26
|
+
=== 5.18.0 / 2023-03-04
|
27
|
+
|
28
|
+
* 2 major enhancements:
|
29
|
+
|
30
|
+
* Added assert_pattern & refute_pattern for pattern matching. (flavorjones)
|
31
|
+
* Added matching must_pattern_match & wont_pattern_match to minitest/spec.
|
32
|
+
|
33
|
+
* 1 bug fix:
|
34
|
+
|
35
|
+
* Support the new message format of NameError in Ruby 3.3 (mame)
|
36
|
+
|
37
|
+
=== 5.17.0 / 2022-12-31
|
38
|
+
|
39
|
+
* 1 minor enhancement:
|
40
|
+
|
41
|
+
* Refactor setup hooks into a SETUP_METHODS constant. (MSP-Greg)
|
42
|
+
|
43
|
+
* 3 bug fixes:
|
44
|
+
|
45
|
+
* Fix kwargs for Mock calls to delegator. (blowmage)
|
46
|
+
* Fix kwargs for expectations. (bobmazanec, blowmage)
|
47
|
+
* Remove check for .b method. (tenderlove)
|
48
|
+
|
49
|
+
=== 5.16.3 / 2022-08-17
|
50
|
+
|
51
|
+
* 2 bug fixes:
|
52
|
+
|
53
|
+
* Fixed exception sanitization by removing TypeError restriction on rescue.
|
54
|
+
* Use A instead of deprecated TESTOPTS in rake test:slow. (davidstosik)
|
55
|
+
|
56
|
+
=== 5.16.2 / 2022-07-03
|
57
|
+
|
58
|
+
* 4 bug fixes:
|
59
|
+
|
60
|
+
* Added MT_KWARGS_HACK kludge for stub to deal with ruby 2.7 kwargs nastiness. (tsugimoto)
|
61
|
+
* In #expect, pop Hash class from args if $MT_KWARGS_HACK. (casperisfine)
|
62
|
+
* In above scenario, set expected kwargs (as Objects) based on actual kwargs.
|
63
|
+
* Nuke ivars if exception fails to marshal twice (eg better_errors). (irphilli)
|
64
|
+
|
65
|
+
=== 5.16.1 / 2022-06-20
|
66
|
+
|
67
|
+
* 2 bug fixes:
|
68
|
+
|
69
|
+
* Apparently adding real kwarg support to mocks/stubs broke some code. Fixed.
|
70
|
+
* Use `MT_KWARGS_HACK=1` to activate the kludgy kwargs support w/ caveats.
|
71
|
+
* Clarified some doco wrt the block on #stub.
|
72
|
+
|
73
|
+
=== 5.16.0 / 2022-06-14
|
74
|
+
|
75
|
+
* 2 major enhancements:
|
76
|
+
|
77
|
+
* Added Minitest::TestTask.
|
78
|
+
* Dropping ruby 2.2 - 2.5. 2.6 is DTM soon too.
|
79
|
+
|
80
|
+
* 11 minor enhancements:
|
81
|
+
|
82
|
+
* Added --show-skips option to show skips at end of run but not require --verbose. (MSP-Greg)
|
83
|
+
* Added Minitest.seed, the random seed used by the run.
|
84
|
+
* Calling `srand Minitest.seed` before all shuffles to ensure determinism.
|
85
|
+
* Extended #stub to handle kwargs for both block and call args. (SampsonCrowley)
|
86
|
+
* Extended Mock#__call to display kwargs.
|
87
|
+
* Extended Mock#expect to record kwargs.
|
88
|
+
* Extended Mock#method_missing to take kwargs & compare them against expected.
|
89
|
+
* Mock#method_missing displays better errors on arity mismatch.
|
90
|
+
* Removed minor optimization removing empty suites before run.
|
91
|
+
* Simplified test randomization (test order will change even with fixed seed).
|
92
|
+
* assert_match now returns the MatchData on success. (Nakilon)
|
93
|
+
|
94
|
+
* 3 bug fixes:
|
95
|
+
|
96
|
+
* (Re)Fixed marshalling of exceptions, neutering them in 2 passes.
|
97
|
+
* Fixed more problems with rdoc.
|
98
|
+
* Had to patch up mock and stub to deal with <=2.7 kwargs oddities
|
99
|
+
|
100
|
+
=== 5.15.0 / 2021-12-14
|
101
|
+
|
102
|
+
* 1 major enhancement:
|
103
|
+
|
104
|
+
* assert_throws returns the value returned, if any. (volmer)
|
105
|
+
|
106
|
+
* 3 minor enhancements:
|
107
|
+
|
108
|
+
* Added -S <CODES> option to skip reporting of certain types of output
|
109
|
+
* Enable Ruby deprecation warnings by default. (casperisfine)
|
110
|
+
* Use Etc.nprocessors by default in order to maximize cpu usage. (tonytonyjan)
|
111
|
+
|
112
|
+
* 6 bug fixes:
|
113
|
+
|
114
|
+
* Close then unlink tempfiles on Windows. (nobu)
|
115
|
+
* Fixed #skip_until for windows paths. (MSP-Greg)
|
116
|
+
* Fixed a bunch of tests for jruby and windows. (MSP-Greg)
|
117
|
+
* Fixed marshalling of specs if they error. (tenderlove, jeremyevans, et al)
|
118
|
+
* Updated deprecation message for block expectations. (blowmage)
|
119
|
+
* Use Kernel.warn directly in expectations in case CUT defines their own warn. (firien)
|
120
|
+
|
1
121
|
=== 5.14.4 / 2021-02-23
|
2
122
|
|
3
123
|
* 1 bug fix:
|
@@ -561,7 +681,7 @@ Minitest 5:
|
|
561
681
|
* Added Minitest::Benchmark.
|
562
682
|
* Your benchmarks need to move to their own subclass.
|
563
683
|
* Benchmarks using the spec DSL have to have "Bench" somewhere in their describe.
|
564
|
-
* MiniTest::Unit.after_tests moved to Minitest.
|
684
|
+
* MiniTest::Unit.after_tests moved to Minitest.after_run
|
565
685
|
* MiniTest::Unit.autorun is now Minitest.autorun. Just require minitest/autorun pls.
|
566
686
|
* Removed ParallelEach#grep since it isn't used anywhere.
|
567
687
|
* Renamed Runnable#__name__ to Runnable#name (but uses @NAME internally).
|
data/Manifest.txt
CHANGED
@@ -17,6 +17,7 @@ lib/minitest/pride.rb
|
|
17
17
|
lib/minitest/pride_plugin.rb
|
18
18
|
lib/minitest/spec.rb
|
19
19
|
lib/minitest/test.rb
|
20
|
+
lib/minitest/test_task.rb
|
20
21
|
lib/minitest/unit.rb
|
21
22
|
test/minitest/metametameta.rb
|
22
23
|
test/minitest/test_minitest_assertions.rb
|
@@ -25,3 +26,4 @@ test/minitest/test_minitest_mock.rb
|
|
25
26
|
test/minitest/test_minitest_reporter.rb
|
26
27
|
test/minitest/test_minitest_spec.rb
|
27
28
|
test/minitest/test_minitest_test.rb
|
29
|
+
test/minitest/test_minitest_test_task.rb
|
data/README.rdoc
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
= minitest/{test,spec,mock,benchmark}
|
2
2
|
|
3
|
-
home :: https://github.com/
|
4
|
-
bugs :: https://github.com/
|
5
|
-
rdoc ::
|
3
|
+
home :: https://github.com/minitest/minitest
|
4
|
+
bugs :: https://github.com/minitest/minitest/issues
|
5
|
+
rdoc :: https://docs.seattlerb.org/minitest
|
6
6
|
vim :: https://github.com/sunaku/vim-ruby-minitest
|
7
7
|
emacs:: https://github.com/arthurnn/minitest-emacs
|
8
8
|
|
@@ -70,6 +70,7 @@ extract-method refactorings still apply.
|
|
70
70
|
* minitest/mock - a simple and clean mock/stub system.
|
71
71
|
* minitest/benchmark - an awesome way to assert your algorithm's performance.
|
72
72
|
* minitest/pride - show your pride in testing!
|
73
|
+
* minitest/test_task - a full-featured and clean rake task generator.
|
73
74
|
* Incredibly small and fast runner, but no bells and whistles.
|
74
75
|
* Written by squishy human beings. Software can never be perfect. We will all eventually die.
|
75
76
|
|
@@ -186,7 +187,7 @@ Output is tab-delimited to make it easy to paste into a spreadsheet.
|
|
186
187
|
=== Mocks
|
187
188
|
|
188
189
|
Mocks and stubs defined using terminology by Fowler & Meszaros at
|
189
|
-
|
190
|
+
https://www.martinfowler.com/bliki/TestDouble.html:
|
190
191
|
|
191
192
|
"Mocks are pre-programmed with expectations which form a specification
|
192
193
|
of the calls they are expected to receive. They can throw an exception
|
@@ -237,7 +238,7 @@ an example of asserting that code inside a thread is run:
|
|
237
238
|
=== Stubs
|
238
239
|
|
239
240
|
Mocks and stubs are defined using terminology by Fowler & Meszaros at
|
240
|
-
|
241
|
+
https://www.martinfowler.com/bliki/TestDouble.html:
|
241
242
|
|
242
243
|
"Stubs provide canned answers to calls made during the test".
|
243
244
|
|
@@ -264,9 +265,8 @@ new non-existing method:
|
|
264
265
|
|
265
266
|
=== Running Your Tests
|
266
267
|
|
267
|
-
Ideally, you'll use a rake task to run your tests, either
|
268
|
-
all at once.
|
269
|
-
tests. BUT! You don't have to:
|
268
|
+
Ideally, you'll use a rake task to run your tests (see below), either
|
269
|
+
piecemeal or all at once. BUT! You don't have to:
|
270
270
|
|
271
271
|
% ruby -Ilib:test test/minitest/test_minitest_test.rb
|
272
272
|
Run options: --seed 37685
|
@@ -294,18 +294,45 @@ provided via plugins. To see them, simply run with +--help+:
|
|
294
294
|
-p, --pride Pride. Show your testing pride!
|
295
295
|
-a, --autotest Connect to autotest server.
|
296
296
|
|
297
|
+
=== Rake Tasks
|
298
|
+
|
297
299
|
You can set up a rake task to run all your tests by adding this to your Rakefile:
|
298
300
|
|
299
|
-
require "
|
301
|
+
require "minitest/test_task"
|
302
|
+
|
303
|
+
Minitest::TestTask.create # named test, sensible defaults
|
304
|
+
|
305
|
+
# or more explicitly:
|
300
306
|
|
301
|
-
|
307
|
+
Minitest::TestTask.create(:test) do |t|
|
302
308
|
t.libs << "test"
|
303
309
|
t.libs << "lib"
|
304
|
-
t.
|
310
|
+
t.warning = false
|
311
|
+
t.test_globs = ["test/**/*_test.rb"]
|
305
312
|
end
|
306
313
|
|
307
314
|
task :default => :test
|
308
315
|
|
316
|
+
Each of these will generate 4 tasks:
|
317
|
+
|
318
|
+
rake test :: Run the test suite.
|
319
|
+
rake test:cmd :: Print out the test command.
|
320
|
+
rake test:isolated :: Show which test files fail when run separately.
|
321
|
+
rake test:slow :: Show bottom 25 tests sorted by time.
|
322
|
+
|
323
|
+
=== Rake Task Variables
|
324
|
+
|
325
|
+
There are a bunch of variables you can supply to rake to modify the run.
|
326
|
+
|
327
|
+
MT_LIB_EXTRAS :: Extra libs to dynamically override/inject for custom runs.
|
328
|
+
N :: -n: Tests to run (string or /regexp/).
|
329
|
+
X :: -x: Tests to exclude (string or /regexp/).
|
330
|
+
A :: Any extra arguments. Honors shell quoting.
|
331
|
+
MT_CPU :: How many threads to use for parallel test runs
|
332
|
+
SEED :: -s --seed Sets random seed.
|
333
|
+
TESTOPTS :: Deprecated, same as A
|
334
|
+
FILTER :: Deprecated, same as A
|
335
|
+
|
309
336
|
== Writing Extensions
|
310
337
|
|
311
338
|
To define a plugin, add a file named minitest/XXX_plugin.rb to your
|
@@ -380,37 +407,35 @@ Using our example above, here is how we might implement MyCI:
|
|
380
407
|
|
381
408
|
Minitest is a dependency of rails, which until fairly recently had an
|
382
409
|
overzealous backwards compatibility policy. As such, I'm stuck
|
383
|
-
supporting versions of ruby that are long past EOL.
|
384
|
-
|
385
|
-
|
410
|
+
supporting versions of ruby that are long past EOL. Hopefully I'll be
|
411
|
+
able to support only current versions of ruby sometime in the near
|
412
|
+
future.
|
386
413
|
|
387
|
-
(As of
|
414
|
+
(As of 2023-03-05)
|
388
415
|
|
389
416
|
Current versions of rails: (https://endoflife.date/rails)
|
390
417
|
|
391
|
-
| rails | min ruby | rec ruby | minitest | status |
|
392
|
-
|
393
|
-
| 7.0 | >= 2.7 | 3.
|
394
|
-
| 6.1 | >= 2.5 | 3.0 | >= 5.1 |
|
395
|
-
| 6.0 | >= 2.5 | 2.6 | >= 5.1 | Security |
|
396
|
-
| 5.2 | >= 2.2.2 | 2.5 | ~> 5.1 |
|
418
|
+
| rails | min ruby | rec ruby | minitest | status | EOL Date |
|
419
|
+
|-------+----------+----------+----------+----------+------------|
|
420
|
+
| 7.0 | >= 2.7 | 3.1 | >= 5.1 | Current | 2025-06-01?|
|
421
|
+
| 6.1 | >= 2.5 | 3.0 | >= 5.1 | Maint | 2024-06-01?|
|
422
|
+
| 6.0 | >= 2.5 | 2.6 | >= 5.1 | Security | 2023-06-01 |
|
423
|
+
| 5.2 | >= 2.2.2 | 2.5 | ~> 5.1 | EOL | 2022-06-01 |
|
424
|
+
|
425
|
+
If you want to look at the requirements for a specific version, run:
|
426
|
+
|
427
|
+
gem spec -r --ruby rails -v 7.0.0
|
397
428
|
|
398
429
|
Current versions of ruby: (https://endoflife.date/ruby)
|
399
430
|
|
400
431
|
| ruby | Status | EOL Date |
|
401
432
|
|------+---------+------------|
|
402
|
-
| 3.
|
403
|
-
|
|
404
|
-
|
|
405
|
-
| 2.
|
406
|
-
| 2.
|
407
|
-
| 2.
|
408
|
-
| 2.2 | EOL | 2018-03-31 |
|
409
|
-
|
410
|
-
See also:
|
411
|
-
|
412
|
-
* https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
|
413
|
-
* https://jamesjeffersconsulting.com/ruby-rails-version-matrix/
|
433
|
+
| 3.2 | Current | 2026-03-31 |
|
434
|
+
| 3.1 | Maint | 2025-03-31 |
|
435
|
+
| 3.0 | Maint | 2024-03-31 |
|
436
|
+
| 2.7 | Security| 2023-03-31 |
|
437
|
+
| 2.6 | EOL | 2022-03-31 |
|
438
|
+
| 2.5 | EOL | 2021-03-31 |
|
414
439
|
|
415
440
|
=== How to test SimpleDelegates?
|
416
441
|
|
@@ -614,6 +639,7 @@ minitest-capistrano :: Assertions and expectations for testing
|
|
614
639
|
Capistrano recipes.
|
615
640
|
minitest-capybara :: Capybara matchers support for minitest unit and
|
616
641
|
spec.
|
642
|
+
minitest-cc :: It provides minimal information about code coverage.
|
617
643
|
minitest-chef-handler :: Run Minitest suites as Chef report handlers
|
618
644
|
minitest-ci :: CI reporter plugin for Minitest.
|
619
645
|
minitest-context :: Defines contexts for code reuse in Minitest
|
@@ -647,6 +673,7 @@ minitest-growl :: Test notifier for minitest via growl.
|
|
647
673
|
minitest-happy :: GLOBALLY ACTIVATE MINITEST PRIDE! RAWR!
|
648
674
|
minitest-have_tag :: Adds Minitest assertions to test for the existence of
|
649
675
|
HTML tags, including contents, within a provided string.
|
676
|
+
minitest-heat :: Reporting that builds a heat map of failure locations
|
650
677
|
minitest-hooks :: Around and before_all/after_all/around_all hooks
|
651
678
|
minitest-hyper :: Pretty, single-page HTML reports for your Minitest runs
|
652
679
|
minitest-implicit-subject :: Implicit declaration of the test subject.
|
@@ -711,7 +738,7 @@ minitest-stub-const :: Stub constants for the duration of a block.
|
|
711
738
|
minitest-tags :: Add tags for minitest.
|
712
739
|
minitest-unordered :: Adds a new assertion to minitest for checking the
|
713
740
|
contents of a collection, ignoring element order.
|
714
|
-
minitest-vcr :: Automatic cassette
|
741
|
+
minitest-vcr :: Automatic cassette management with Minitest::Spec
|
715
742
|
and VCR.
|
716
743
|
minitest_log :: Adds structured logging, data explication, and verdicts.
|
717
744
|
minitest_owrapper :: Get tests results as a TestResult object.
|
@@ -721,8 +748,13 @@ mongoid-minitest :: Minitest matchers for Mongoid.
|
|
721
748
|
mutant-minitest :: Minitest integration for mutant.
|
722
749
|
pry-rescue :: A pry plugin w/ minitest support. See
|
723
750
|
pry-rescue/minitest.rb.
|
751
|
+
rematch :: Declutter your test files from large hardcoded data
|
752
|
+
and update them automatically when your code changes.
|
724
753
|
rspec2minitest :: Easily translate any RSpec matchers to Minitest
|
725
754
|
assertions and expectations.
|
755
|
+
stubberry :: Multiple stubbing 'berries', sweet and useful
|
756
|
+
stub helpers and assertions. ( stub_must,
|
757
|
+
assert_method_called, stubbing ORM objects by id )
|
726
758
|
|
727
759
|
== Unknown Extensions:
|
728
760
|
|
@@ -748,7 +780,7 @@ Authors... Please send me a pull request with a description of your minitest ext
|
|
748
780
|
|
749
781
|
== Minitest related goods
|
750
782
|
|
751
|
-
* minitest/pride fabric:
|
783
|
+
* minitest/pride fabric: https://www.spoonflower.com/fabric/3928730-again-by-katie_allen
|
752
784
|
|
753
785
|
== REQUIREMENTS:
|
754
786
|
|
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
|
@@ -11,7 +12,7 @@ Hoe.spec "minitest" do
|
|
11
12
|
|
12
13
|
license "MIT"
|
13
14
|
|
14
|
-
require_ruby_version [">= 2.
|
15
|
+
require_ruby_version [">= 2.6", "< 4.0"]
|
15
16
|
end
|
16
17
|
|
17
18
|
desc "Find missing expectations"
|
data/lib/hoe/minitest.rb
CHANGED
data/lib/minitest/assertions.rb
CHANGED
@@ -293,6 +293,8 @@ module Minitest
|
|
293
293
|
assert_respond_to matcher, :"=~"
|
294
294
|
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
295
295
|
assert matcher =~ obj, msg
|
296
|
+
|
297
|
+
Regexp.last_match
|
296
298
|
end
|
297
299
|
|
298
300
|
##
|
@@ -355,6 +357,32 @@ module Minitest
|
|
355
357
|
assert File.exist?(path), msg
|
356
358
|
end
|
357
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
|
+
|
358
386
|
##
|
359
387
|
# For testing with predicates. Eg:
|
360
388
|
#
|
@@ -473,7 +501,7 @@ module Minitest
|
|
473
501
|
def assert_throws sym, msg = nil
|
474
502
|
default = "Expected #{mu_pp(sym)} to have been thrown"
|
475
503
|
caught = true
|
476
|
-
catch(sym) do
|
504
|
+
value = catch(sym) do
|
477
505
|
begin
|
478
506
|
yield
|
479
507
|
rescue ThreadError => e # wtf?!? 1.8 + threads == suck
|
@@ -489,6 +517,7 @@ module Minitest
|
|
489
517
|
end
|
490
518
|
|
491
519
|
assert caught, message(msg) { default }
|
520
|
+
value
|
492
521
|
rescue Assertion
|
493
522
|
raise
|
494
523
|
rescue => e
|
@@ -561,15 +590,13 @@ module Minitest
|
|
561
590
|
|
562
591
|
return captured_stdout.read, captured_stderr.read
|
563
592
|
ensure
|
564
|
-
captured_stdout.unlink
|
565
|
-
captured_stderr.unlink
|
566
593
|
$stdout.reopen orig_stdout
|
567
594
|
$stderr.reopen orig_stderr
|
568
595
|
|
569
596
|
orig_stdout.close
|
570
597
|
orig_stderr.close
|
571
|
-
captured_stdout.close
|
572
|
-
captured_stderr.close
|
598
|
+
captured_stdout.close!
|
599
|
+
captured_stderr.close!
|
573
600
|
end
|
574
601
|
end
|
575
602
|
end
|
@@ -720,6 +747,30 @@ module Minitest
|
|
720
747
|
refute obj.nil?, msg
|
721
748
|
end
|
722
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
|
+
|
723
774
|
##
|
724
775
|
# Fails if +o1+ is not +op+ +o2+. Eg:
|
725
776
|
#
|
@@ -793,7 +844,7 @@ module Minitest
|
|
793
844
|
|
794
845
|
def skip_until y,m,d,msg
|
795
846
|
skip msg if Time.now < Time.local(y, m, d)
|
796
|
-
where = caller.first.
|
847
|
+
where = caller.first.rpartition(':in').reject(&:empty?).first
|
797
848
|
warn "Stale skip_until %p at %s" % [msg, where]
|
798
849
|
end
|
799
850
|
|
data/lib/minitest/benchmark.rb
CHANGED
@@ -217,7 +217,7 @@ module Minitest
|
|
217
217
|
##
|
218
218
|
# Takes an array of x/y pairs and calculates the general R^2 value.
|
219
219
|
#
|
220
|
-
# See:
|
220
|
+
# See: https://en.wikipedia.org/wiki/Coefficient_of_determination
|
221
221
|
|
222
222
|
def fit_error xys
|
223
223
|
y_bar = sigma(xys) { |_, y| y } / xys.size.to_f
|
@@ -232,7 +232,7 @@ module Minitest
|
|
232
232
|
#
|
233
233
|
# Takes x and y values and returns [a, b, r^2].
|
234
234
|
#
|
235
|
-
# See:
|
235
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFittingExponential.html
|
236
236
|
|
237
237
|
def fit_exponential xs, ys
|
238
238
|
n = xs.size
|
@@ -254,7 +254,7 @@ module Minitest
|
|
254
254
|
#
|
255
255
|
# Takes x and y values and returns [a, b, r^2].
|
256
256
|
#
|
257
|
-
# See:
|
257
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
|
258
258
|
|
259
259
|
def fit_logarithmic xs, ys
|
260
260
|
n = xs.size
|
@@ -276,7 +276,7 @@ module Minitest
|
|
276
276
|
#
|
277
277
|
# Takes x and y values and returns [a, b, r^2].
|
278
278
|
#
|
279
|
-
# See:
|
279
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFitting.html
|
280
280
|
|
281
281
|
def fit_linear xs, ys
|
282
282
|
n = xs.size
|
@@ -298,7 +298,7 @@ module Minitest
|
|
298
298
|
#
|
299
299
|
# Takes x and y values and returns [a, b, r^2].
|
300
300
|
#
|
301
|
-
# See:
|
301
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
|
302
302
|
|
303
303
|
def fit_power xs, ys
|
304
304
|
n = xs.size
|
@@ -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
|
#
|