minitest 5.11.3 → 5.14.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +102 -3
- data/Manifest.txt +1 -0
- data/README.rdoc +61 -7
- data/Rakefile +4 -16
- data/lib/minitest/assertions.rb +140 -26
- data/lib/minitest/benchmark.rb +2 -2
- data/lib/minitest/expectations.rb +54 -35
- data/lib/minitest/mock.rb +5 -1
- data/lib/minitest/spec.rb +19 -8
- data/lib/minitest.rb +90 -21
- data/test/minitest/metametameta.rb +42 -8
- data/test/minitest/test_minitest_assertions.rb +1575 -0
- data/test/minitest/test_minitest_mock.rb +14 -4
- data/test/minitest/test_minitest_spec.rb +215 -141
- data/test/minitest/test_minitest_test.rb +38 -1096
- data.tar.gz.sig +0 -0
- metadata +33 -22
- 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: 1edfa85bfac65503ab66f88d6ca07571a6e788bfd9eb513399cc60ffeae32e1f
|
4
|
+
data.tar.gz: 68a4cc4fcf8b54f8ba97dbda48e7ee4a8f818c67a3c4021920d5c6e4dfe9866c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f808ea45c7d6755da784bc6d70356f6beb7b794bd4df3cf509ce08d762f125c1bcafd92c406c73ea6a13809d836c75812fed83605f18b1d82e6f16b98e97004
|
7
|
+
data.tar.gz: d75f3b41034e4a70b8f372a79af5971eb2a589f87a4a80bfc20f23ebf1e5ac50235bfa5c300a25bba99f55746a8148cddde804cc9181d941ad62c71626482e06
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,3 +1,103 @@
|
|
1
|
+
=== 5.14.4 / 2021-02-23
|
2
|
+
|
3
|
+
* 1 bug fix:
|
4
|
+
|
5
|
+
* Fixed deprecation warning using stub with methods using keyword arguments. (Nakilon)
|
6
|
+
|
7
|
+
=== 5.14.3 / 2021-01-05
|
8
|
+
|
9
|
+
* 1 bug fix:
|
10
|
+
|
11
|
+
* Bumped require_ruby_version to < 4 (trunk = 3.1).
|
12
|
+
|
13
|
+
=== 5.14.2 / 2020-08-31
|
14
|
+
|
15
|
+
* 1 bug fix:
|
16
|
+
|
17
|
+
* Bumped ruby version to include 3.0 (trunk).
|
18
|
+
|
19
|
+
=== 5.14.1 / 2020-05-15
|
20
|
+
|
21
|
+
* 3 minor enhancements:
|
22
|
+
|
23
|
+
* Minitest.filter_backtrace returns original backtrace if filter comes back empty.
|
24
|
+
* Minitest::BacktraceFilter now returns entire backtrace if $MT_DEBUG set in env.
|
25
|
+
* Return true on a successful refute. (jusleg)
|
26
|
+
|
27
|
+
* 1 bug fix:
|
28
|
+
|
29
|
+
* Fixed expectation doco to not use global expectations.
|
30
|
+
|
31
|
+
=== 5.14.0 / 2020-01-11
|
32
|
+
|
33
|
+
* 2 minor enhancements:
|
34
|
+
|
35
|
+
* Block-assertions (eg assert_output) now error if raised inside the block. (casperisfine)
|
36
|
+
* Changed assert_raises to only catch Assertion since that covers Skip and friends.
|
37
|
+
|
38
|
+
* 3 bug fixes:
|
39
|
+
|
40
|
+
* Added example for value wrapper with block to Expectations module. (stomar)
|
41
|
+
* Fixed use of must/wont_be_within_delta on Expectation instance. (stomar)
|
42
|
+
* Renamed UnexpectedError#exception to #error to avoid problems with reraising. (casperisfine)
|
43
|
+
|
44
|
+
=== 5.13.0 / 2019-10-29
|
45
|
+
|
46
|
+
* 9 minor enhancements:
|
47
|
+
|
48
|
+
* Added Minitest::Guard#osx?
|
49
|
+
* Added examples to documentation for assert_raises. (lxxxvi)
|
50
|
+
* Added expectations #path_must_exist and #path_wont_exist. Not thrilled with the names.
|
51
|
+
* Added fail_after(year, month, day, msg) to allow time-bombing after a deadline.
|
52
|
+
* Added skip_until(year, month, day, msg) to allow deferring until a deadline.
|
53
|
+
* Deprecated Minitest::Guard#maglev?
|
54
|
+
* Deprecated Minitest::Guard#rubinius?
|
55
|
+
* Finally added assert_path_exists and refute_path_exists. (deivid-rodriguez)
|
56
|
+
* Refactored and pulled Assertions#things_to_diff out of #diff. (BurdetteLamar)
|
57
|
+
|
58
|
+
* 3 bug fixes:
|
59
|
+
|
60
|
+
* Fix autorun bug that affects fork exit status in tests. (dylanahsmith/jhawthorn)
|
61
|
+
* Improved documentation for _/value/expect, especially for blocks. (svoop)
|
62
|
+
* Support new Proc#to_s format. (ko1)
|
63
|
+
|
64
|
+
=== 5.12.2 / 2019-09-28
|
65
|
+
|
66
|
+
* 1 bug fix:
|
67
|
+
|
68
|
+
* After chatting w/ @y-yagi and others, decided to lower support to include ruby 2.2.
|
69
|
+
|
70
|
+
=== 5.12.1 / 2019-09-28
|
71
|
+
|
72
|
+
* 1 minor enhancement:
|
73
|
+
|
74
|
+
* Added documentation for Reporter classes. (sshaw)
|
75
|
+
|
76
|
+
* 3 bug fixes:
|
77
|
+
|
78
|
+
* Avoid using 'match?' to support older ruby versions. (y-yagi)
|
79
|
+
* Fixed broken link to reference on goodness-of-fit testing. (havenwood)
|
80
|
+
* Update requirements in readme and Rakefile/hoe spec.
|
81
|
+
|
82
|
+
=== 5.12.0 / 2019-09-22
|
83
|
+
|
84
|
+
* 8 minor enhancements:
|
85
|
+
|
86
|
+
* Added a descriptive error if assert_output or assert_raises called without a block. (okuramasafumi)
|
87
|
+
* Changed mu_pp_for_diff to make having both \n and \\n easier to debug.
|
88
|
+
* Deprecated $N for specifying number of parallel test runners. Use MT_CPU.
|
89
|
+
* Deprecated use of global expectations. To be removed from MT6.
|
90
|
+
* Extended Assertions#mu_pp to encoding validity output for strings to improve diffs.
|
91
|
+
* Extended Assertions#mu_pp to output encoding and validity if invalid to improve diffs.
|
92
|
+
* Extended Assertions#mu_pp_for_diff to make escaped newlines more obvious in diffs.
|
93
|
+
* Fail gracefully when expectation used outside of `it`.
|
94
|
+
|
95
|
+
* 3 bug fixes:
|
96
|
+
|
97
|
+
* Check `option[:filter]` klass before match. Fixes 2.6 warning. (y-yagi)
|
98
|
+
* Fixed Assertions#diff from recalculating if set to nil
|
99
|
+
* Fixed spec section of readme to not use deprecated global expectations. (CheezItMan)
|
100
|
+
|
1
101
|
=== 5.11.3 / 2018-01-26
|
2
102
|
|
3
103
|
* 1 bug fix:
|
@@ -123,7 +223,7 @@
|
|
123
223
|
* 2 bug fixes:
|
124
224
|
|
125
225
|
* Re-release to refresh gem certificate signing. ugh.
|
126
|
-
* Fixed hoe/minitest to not augment load path if we're actually testing minitest.
|
226
|
+
* Fixed hoe/minitest to not augment load path if we're actually testing minitest.
|
127
227
|
|
128
228
|
=== 5.9.0 / 2016-05-16
|
129
229
|
|
@@ -147,7 +247,7 @@
|
|
147
247
|
* 2 bug fixes:
|
148
248
|
|
149
249
|
* Re-release to refresh gem certificate signing. ugh.
|
150
|
-
* Fixed hoe/minitest to not augment load path if we're actually testing minitest.
|
250
|
+
* Fixed hoe/minitest to not augment load path if we're actually testing minitest.
|
151
251
|
|
152
252
|
=== 5.8.4 / 2016-01-21
|
153
253
|
|
@@ -1307,4 +1407,3 @@ back.
|
|
1307
1407
|
* 1 major enhancement
|
1308
1408
|
|
1309
1409
|
* Birthday!
|
1310
|
-
|
data/Manifest.txt
CHANGED
@@ -19,6 +19,7 @@ lib/minitest/spec.rb
|
|
19
19
|
lib/minitest/test.rb
|
20
20
|
lib/minitest/unit.rb
|
21
21
|
test/minitest/metametameta.rb
|
22
|
+
test/minitest/test_minitest_assertions.rb
|
22
23
|
test/minitest/test_minitest_benchmark.rb
|
23
24
|
test/minitest/test_minitest_mock.rb
|
24
25
|
test/minitest/test_minitest_reporter.rb
|
data/README.rdoc
CHANGED
@@ -126,13 +126,13 @@ Define your tests as methods beginning with +test_+.
|
|
126
126
|
|
127
127
|
describe "when asked about cheeseburgers" do
|
128
128
|
it "must respond positively" do
|
129
|
-
@meme.i_can_has_cheezburger
|
129
|
+
_(@meme.i_can_has_cheezburger?).must_equal "OHAI!"
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
describe "when asked about blending possibilities" do
|
134
134
|
it "won't say no" do
|
135
|
-
@meme.will_it_blend
|
135
|
+
_(@meme.will_it_blend?).wont_match /^no/i
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -220,9 +220,9 @@ verification to ensure they got all the calls they were expecting."
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
-
|
223
|
+
==== Multi-threading and Mocks
|
224
224
|
|
225
|
-
Minitest mocks do not support multi-threading
|
225
|
+
Minitest mocks do not support multi-threading. If it works, fine, if it doesn't
|
226
226
|
you can use regular ruby patterns and facilities like local variables. Here's
|
227
227
|
an example of asserting that code inside a thread is run:
|
228
228
|
|
@@ -294,6 +294,18 @@ 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
|
+
You can set up a rake task to run all your tests by adding this to your Rakefile:
|
298
|
+
|
299
|
+
require "rake/testtask"
|
300
|
+
|
301
|
+
Rake::TestTask.new(:test) do |t|
|
302
|
+
t.libs << "test"
|
303
|
+
t.libs << "lib"
|
304
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
305
|
+
end
|
306
|
+
|
307
|
+
task :default => :test
|
308
|
+
|
297
309
|
== Writing Extensions
|
298
310
|
|
299
311
|
To define a plugin, add a file named minitest/XXX_plugin.rb to your
|
@@ -364,6 +376,42 @@ Using our example above, here is how we might implement MyCI:
|
|
364
376
|
|
365
377
|
== FAQ
|
366
378
|
|
379
|
+
=== What versions are compatible with what? Or what versions are supported?
|
380
|
+
|
381
|
+
Minitest is a dependency of rails, which until fairly recently had an
|
382
|
+
overzealous backwards compatibility policy. As such, I'm stuck
|
383
|
+
supporting versions of ruby that are long past EOL. Once rails 5.2 is
|
384
|
+
dropped (hopefully April 2021), I get to drop a bunch of versions of
|
385
|
+
ruby that I have to currently test against.
|
386
|
+
|
387
|
+
(As of 2021-01-31)
|
388
|
+
|
389
|
+
Current versions of rails: (https://endoflife.date/rails)
|
390
|
+
|
391
|
+
| rails | min ruby | rec ruby | minitest | status |
|
392
|
+
|-------+----------+----------+----------+----------|
|
393
|
+
| 7.0 | >= 2.7 | 3.0 | >= 5.1 | Future |
|
394
|
+
| 6.1 | >= 2.5 | 3.0 | >= 5.1 | Current |
|
395
|
+
| 6.0 | >= 2.5 | 2.6 | >= 5.1 | Security |
|
396
|
+
| 5.2 | >= 2.2.2 | 2.5 | ~> 5.1 | Security | EOL @railsconf 2021?
|
397
|
+
|
398
|
+
Current versions of ruby: (https://endoflife.date/ruby)
|
399
|
+
|
400
|
+
| ruby | Status | EOL Date |
|
401
|
+
|------+---------+------------|
|
402
|
+
| 3.0 | Current | 2024-03-31 |
|
403
|
+
| 2.7 | Maint | 2023-03-31 |
|
404
|
+
| 2.6 | Maint | 2022-03-31 |
|
405
|
+
| 2.5 | Maint* | 2021-03-31 |
|
406
|
+
| 2.4 | EOL | 2020-03-31 |
|
407
|
+
| 2.3 | EOL | 2019-03-31 |
|
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/
|
414
|
+
|
367
415
|
=== How to test SimpleDelegates?
|
368
416
|
|
369
417
|
The following implementation and test:
|
@@ -379,7 +427,7 @@ The following implementation and test:
|
|
379
427
|
end
|
380
428
|
|
381
429
|
it "must respond to work" do
|
382
|
-
@worker.must_respond_to :work
|
430
|
+
_(@worker).must_respond_to :work
|
383
431
|
end
|
384
432
|
end
|
385
433
|
|
@@ -469,6 +517,8 @@ able to require minitest and run your tests.
|
|
469
517
|
|
470
518
|
== Developing Minitest:
|
471
519
|
|
520
|
+
Minitest requires {Hoe}[https://rubygems.org/gems/hoe].
|
521
|
+
|
472
522
|
=== Minitest's own tests require UTF-8 external encoding.
|
473
523
|
|
474
524
|
This is a common problem in Windows, where the default external Encoding is
|
@@ -547,6 +597,7 @@ minispec-metadata :: Metadata for describe/it blocks & CLI tag filter.
|
|
547
597
|
E.g. <tt>it "requires JS driver", js: true do</tt> &
|
548
598
|
<tt>ruby test.rb --tag js</tt> runs tests tagged :js.
|
549
599
|
minispec-rails :: Minimal support to use Spec style in Rails 5+.
|
600
|
+
mini-apivore :: for swagger based automated API testing.
|
550
601
|
minitest-around :: Around block for minitest. An alternative to
|
551
602
|
setup/teardown dance.
|
552
603
|
minitest-assert_errors :: Adds Minitest assertions to test for errors raised
|
@@ -589,6 +640,7 @@ minitest-firemock :: Makes your Minitest mocks more resilient.
|
|
589
640
|
minitest-focus :: Focus on one test at a time.
|
590
641
|
minitest-gcstats :: A minitest plugin that adds a report of the top
|
591
642
|
tests by number of objects allocated.
|
643
|
+
minitest-global_expectations:: Support minitest expectation methods for all objects
|
592
644
|
minitest-great_expectations :: Generally useful additions to minitest's
|
593
645
|
assertions and expectations.
|
594
646
|
minitest-growl :: Test notifier for minitest via growl.
|
@@ -615,6 +667,7 @@ minitest-matchers :: Adds support for RSpec-style matchers to
|
|
615
667
|
minitest-matchers_vaccine :: Adds assertions that adhere to the matcher spec,
|
616
668
|
but without any expectation infections.
|
617
669
|
minitest-metadata :: Annotate tests with metadata (key-value).
|
670
|
+
minitest-mock_expectations :: Provides method call assertions for minitest.
|
618
671
|
minitest-mongoid :: Mongoid assertion matchers for Minitest.
|
619
672
|
minitest-must_not :: Provides must_not as an alias for wont in
|
620
673
|
Minitest.
|
@@ -660,10 +713,12 @@ minitest-unordered :: Adds a new assertion to minitest for checking the
|
|
660
713
|
contents of a collection, ignoring element order.
|
661
714
|
minitest-vcr :: Automatic cassette managment with Minitest::Spec
|
662
715
|
and VCR.
|
716
|
+
minitest_log :: Adds structured logging, data explication, and verdicts.
|
663
717
|
minitest_owrapper :: Get tests results as a TestResult object.
|
664
718
|
minitest_should :: Shoulda style syntax for minitest test::unit.
|
665
719
|
minitest_tu_shim :: Bridges between test/unit and minitest.
|
666
720
|
mongoid-minitest :: Minitest matchers for Mongoid.
|
721
|
+
mutant-minitest :: Minitest integration for mutant.
|
667
722
|
pry-rescue :: A pry plugin w/ minitest support. See
|
668
723
|
pry-rescue/minitest.rb.
|
669
724
|
rspec2minitest :: Easily translate any RSpec matchers to Minitest
|
@@ -697,8 +752,7 @@ Authors... Please send me a pull request with a description of your minitest ext
|
|
697
752
|
|
698
753
|
== REQUIREMENTS:
|
699
754
|
|
700
|
-
* Ruby
|
701
|
-
* NOTE: 1.8 and 1.9 will be dropped in minitest 6+.
|
755
|
+
* Ruby 2.3+. No magic is involved. I hope.
|
702
756
|
|
703
757
|
== INSTALL:
|
704
758
|
|
data/Rakefile
CHANGED
@@ -11,21 +11,7 @@ Hoe.spec "minitest" do
|
|
11
11
|
|
12
12
|
license "MIT"
|
13
13
|
|
14
|
-
|
15
|
-
#
|
16
|
-
# self.post_install_message = <<-"EOM"
|
17
|
-
# NOTE: minitest 5 will be the last in the minitest family to support
|
18
|
-
# ruby 1.8 and 1.9 (and maybe 2.0?). If you need to keep using 1.8
|
19
|
-
# or 1.9, you need to pin your dependency to minitest with
|
20
|
-
# something like "~> 5.0".
|
21
|
-
#
|
22
|
-
# Further, minitest 6 will be dropping the following:
|
23
|
-
#
|
24
|
-
# + MiniTest (it's been Minitest for *years*)
|
25
|
-
# + MiniTest::Unit
|
26
|
-
# + MiniTest::Unit::TestCase
|
27
|
-
# + assert_send (unless you argue for it well)
|
28
|
-
# EOM
|
14
|
+
require_ruby_version [">= 2.2", "< 4.0"]
|
29
15
|
end
|
30
16
|
|
31
17
|
desc "Find missing expectations"
|
@@ -35,7 +21,7 @@ task :specs do
|
|
35
21
|
require "minitest/spec"
|
36
22
|
|
37
23
|
pos_prefix, neg_prefix = "must", "wont"
|
38
|
-
skip_re = /^(must|wont)$|wont_(throw)|must_(block|not?_|nothing|raise$)/x
|
24
|
+
skip_re = /^(must|wont)$|wont_(throw)|must_(block|not?_|nothing|send|raise$)/x
|
39
25
|
dont_flip_re = /(must|wont)_(include|respond_to)/
|
40
26
|
|
41
27
|
map = {
|
@@ -46,6 +32,8 @@ task :specs do
|
|
46
32
|
/_includes/ => "_include",
|
47
33
|
/(must|wont)_(.*_of|nil|silent|empty)/ => '\1_be_\2',
|
48
34
|
/must_raises/ => "must_raise",
|
35
|
+
/(must|wont)_predicate/ => '\1_be',
|
36
|
+
/(must|wont)_path_exists/ => 'path_\1_exist',
|
49
37
|
}
|
50
38
|
|
51
39
|
expectations = Minitest::Expectations.public_instance_methods.map(&:to_s)
|
data/lib/minitest/assertions.rb
CHANGED
@@ -27,20 +27,18 @@ module Minitest
|
|
27
27
|
# figure out what diff to use.
|
28
28
|
|
29
29
|
def self.diff
|
30
|
+
return @diff if defined? @diff
|
31
|
+
|
30
32
|
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ &&
|
31
33
|
system("diff.exe", __FILE__, __FILE__)) then
|
32
34
|
"diff.exe -u"
|
33
|
-
elsif Minitest::Test.maglev? then
|
34
|
-
"diff -u"
|
35
35
|
elsif system("gdiff", __FILE__, __FILE__)
|
36
36
|
"gdiff -u" # solaris and kin suck
|
37
37
|
elsif system("diff", __FILE__, __FILE__)
|
38
38
|
"diff -u"
|
39
39
|
else
|
40
40
|
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
@diff
|
41
|
+
end
|
44
42
|
end
|
45
43
|
|
46
44
|
##
|
@@ -55,22 +53,16 @@ module Minitest
|
|
55
53
|
# diff command or if it doesn't make sense to diff the output
|
56
54
|
# (single line, short output), then it simply returns a basic
|
57
55
|
# comparison between the two.
|
56
|
+
#
|
57
|
+
# See +things_to_diff+ for more info.
|
58
58
|
|
59
59
|
def diff exp, act
|
60
|
-
expect = mu_pp_for_diff exp
|
61
|
-
butwas = mu_pp_for_diff act
|
62
60
|
result = nil
|
63
61
|
|
64
|
-
|
65
|
-
(expect.include?("\n") ||
|
66
|
-
butwas.include?("\n") ||
|
67
|
-
expect.size > 30 ||
|
68
|
-
butwas.size > 30 ||
|
69
|
-
expect == butwas) &&
|
70
|
-
Minitest::Assertions.diff
|
62
|
+
expect, butwas = things_to_diff(exp, act)
|
71
63
|
|
72
64
|
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
|
73
|
-
|
65
|
+
expect
|
74
66
|
|
75
67
|
Tempfile.open("expect") do |a|
|
76
68
|
a.puts expect
|
@@ -99,10 +91,40 @@ module Minitest
|
|
99
91
|
result
|
100
92
|
end
|
101
93
|
|
94
|
+
##
|
95
|
+
# Returns things to diff [expect, butwas], or [nil, nil] if nothing to diff.
|
96
|
+
#
|
97
|
+
# Criterion:
|
98
|
+
#
|
99
|
+
# 1. Strings include newlines or escaped newlines, but not both.
|
100
|
+
# 2. or: String lengths are > 30 characters.
|
101
|
+
# 3. or: Strings are equal to each other (but maybe different encodings?).
|
102
|
+
# 4. and: we found a diff executable.
|
103
|
+
|
104
|
+
def things_to_diff exp, act
|
105
|
+
expect = mu_pp_for_diff exp
|
106
|
+
butwas = mu_pp_for_diff act
|
107
|
+
|
108
|
+
e1, e2 = expect.include?("\n"), expect.include?("\\n")
|
109
|
+
b1, b2 = butwas.include?("\n"), butwas.include?("\\n")
|
110
|
+
|
111
|
+
need_to_diff =
|
112
|
+
(e1 ^ e2 ||
|
113
|
+
b1 ^ b2 ||
|
114
|
+
expect.size > 30 ||
|
115
|
+
butwas.size > 30 ||
|
116
|
+
expect == butwas) &&
|
117
|
+
Minitest::Assertions.diff
|
118
|
+
|
119
|
+
need_to_diff && [expect, butwas]
|
120
|
+
end
|
121
|
+
|
102
122
|
##
|
103
123
|
# This returns a human-readable version of +obj+. By default
|
104
|
-
# #inspect is called. You can override this to use #
|
124
|
+
# #inspect is called. You can override this to use #pretty_inspect
|
105
125
|
# if you want.
|
126
|
+
#
|
127
|
+
# See Minitest::Test.make_my_diffs_pretty!
|
106
128
|
|
107
129
|
def mu_pp obj
|
108
130
|
s = obj.inspect
|
@@ -110,8 +132,11 @@ module Minitest
|
|
110
132
|
if defined? Encoding then
|
111
133
|
s = s.encode Encoding.default_external
|
112
134
|
|
113
|
-
if String === obj && obj.encoding != Encoding.default_external
|
114
|
-
|
135
|
+
if String === obj && (obj.encoding != Encoding.default_external ||
|
136
|
+
!obj.valid_encoding?) then
|
137
|
+
enc = "# encoding: #{obj.encoding}"
|
138
|
+
val = "# valid: #{obj.valid_encoding?}"
|
139
|
+
s = "#{enc}\n#{val}\n#{s}"
|
115
140
|
end
|
116
141
|
end
|
117
142
|
|
@@ -119,13 +144,32 @@ module Minitest
|
|
119
144
|
end
|
120
145
|
|
121
146
|
##
|
122
|
-
# This returns a diff-able human-readable version of +obj+.
|
123
|
-
# differs from the regular mu_pp because it expands escaped
|
124
|
-
# newlines and makes hex-values
|
147
|
+
# This returns a diff-able more human-readable version of +obj+.
|
148
|
+
# This differs from the regular mu_pp because it expands escaped
|
149
|
+
# newlines and makes hex-values (like object_ids) generic. This
|
125
150
|
# uses mu_pp to do the first pass and then cleans it up.
|
126
151
|
|
127
152
|
def mu_pp_for_diff obj
|
128
|
-
mu_pp
|
153
|
+
str = mu_pp obj
|
154
|
+
|
155
|
+
# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
|
156
|
+
single = !!str.match(/(?<!\\|^)\\n/)
|
157
|
+
double = !!str.match(/(?<=\\|^)\\n/)
|
158
|
+
|
159
|
+
process =
|
160
|
+
if single ^ double then
|
161
|
+
if single then
|
162
|
+
lambda { |s| s == "\\n" ? "\n" : s } # unescape
|
163
|
+
else
|
164
|
+
lambda { |s| s == "\\\\n" ? "\\n\n" : s } # unescape a bit, add nls
|
165
|
+
end
|
166
|
+
else
|
167
|
+
:itself # leave it alone
|
168
|
+
end
|
169
|
+
|
170
|
+
str.
|
171
|
+
gsub(/\\?\\n/, &process).
|
172
|
+
gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
129
173
|
end
|
130
174
|
|
131
175
|
##
|
@@ -283,6 +327,9 @@ module Minitest
|
|
283
327
|
# See also: #assert_silent
|
284
328
|
|
285
329
|
def assert_output stdout = nil, stderr = nil
|
330
|
+
flunk "assert_output requires a block to capture output." unless
|
331
|
+
block_given?
|
332
|
+
|
286
333
|
out, err = capture_io do
|
287
334
|
yield
|
288
335
|
end
|
@@ -294,6 +341,18 @@ module Minitest
|
|
294
341
|
x = send out_msg, stdout, out, "In stdout" if out_msg
|
295
342
|
|
296
343
|
(!stdout || x) && (!stderr || y)
|
344
|
+
rescue Assertion
|
345
|
+
raise
|
346
|
+
rescue => e
|
347
|
+
raise UnexpectedError, e
|
348
|
+
end
|
349
|
+
|
350
|
+
##
|
351
|
+
# Fails unless +path+ exists.
|
352
|
+
|
353
|
+
def assert_path_exists path, msg = nil
|
354
|
+
msg = message(msg) { "Expected path '#{path}' to exist" }
|
355
|
+
assert File.exist?(path), msg
|
297
356
|
end
|
298
357
|
|
299
358
|
##
|
@@ -316,9 +375,26 @@ module Minitest
|
|
316
375
|
#
|
317
376
|
# +exp+ takes an optional message on the end to help explain
|
318
377
|
# failures and defaults to StandardError if no exception class is
|
319
|
-
# passed.
|
378
|
+
# passed. Eg:
|
379
|
+
#
|
380
|
+
# assert_raises(CustomError) { method_with_custom_error }
|
381
|
+
#
|
382
|
+
# With custom error message:
|
383
|
+
#
|
384
|
+
# assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
|
385
|
+
#
|
386
|
+
# Using the returned object:
|
387
|
+
#
|
388
|
+
# error = assert_raises(CustomError) do
|
389
|
+
# raise CustomError, 'This is really bad'
|
390
|
+
# end
|
391
|
+
#
|
392
|
+
# assert_equal 'This is really bad', error.message
|
320
393
|
|
321
394
|
def assert_raises *exp
|
395
|
+
flunk "assert_raises requires a block to capture errors." unless
|
396
|
+
block_given?
|
397
|
+
|
322
398
|
msg = "#{exp.pop}.\n" if String === exp.last
|
323
399
|
exp << StandardError if exp.empty?
|
324
400
|
|
@@ -327,7 +403,7 @@ module Minitest
|
|
327
403
|
rescue *exp => e
|
328
404
|
pass # count assertion
|
329
405
|
return e
|
330
|
-
rescue Minitest::Skip
|
406
|
+
rescue Minitest::Assertion # incl Skip & UnexpectedError
|
331
407
|
# don't count assertion
|
332
408
|
raise
|
333
409
|
rescue SignalException, SystemExit
|
@@ -413,6 +489,10 @@ module Minitest
|
|
413
489
|
end
|
414
490
|
|
415
491
|
assert caught, message(msg) { default }
|
492
|
+
rescue Assertion
|
493
|
+
raise
|
494
|
+
rescue => e
|
495
|
+
raise UnexpectedError, e
|
416
496
|
end
|
417
497
|
|
418
498
|
##
|
@@ -485,6 +565,11 @@ module Minitest
|
|
485
565
|
captured_stderr.unlink
|
486
566
|
$stdout.reopen orig_stdout
|
487
567
|
$stderr.reopen orig_stderr
|
568
|
+
|
569
|
+
orig_stdout.close
|
570
|
+
orig_stderr.close
|
571
|
+
captured_stdout.close
|
572
|
+
captured_stderr.close
|
488
573
|
end
|
489
574
|
end
|
490
575
|
end
|
@@ -504,7 +589,16 @@ module Minitest
|
|
504
589
|
end
|
505
590
|
|
506
591
|
##
|
507
|
-
# Fails
|
592
|
+
# Fails after a given date (in the local time zone). This allows
|
593
|
+
# you to put time-bombs in your tests if you need to keep
|
594
|
+
# something around until a later date lest you forget about it.
|
595
|
+
|
596
|
+
def fail_after y,m,d,msg
|
597
|
+
flunk msg if Time.now > Time.local(y, m, d)
|
598
|
+
end
|
599
|
+
|
600
|
+
##
|
601
|
+
# Fails with +msg+.
|
508
602
|
|
509
603
|
def flunk msg = nil
|
510
604
|
msg ||= "Epic Fail!"
|
@@ -534,7 +628,7 @@ module Minitest
|
|
534
628
|
|
535
629
|
def refute test, msg = nil
|
536
630
|
msg ||= message { "Expected #{mu_pp(test)} to not be truthy" }
|
537
|
-
|
631
|
+
assert !test, msg
|
538
632
|
end
|
539
633
|
|
540
634
|
##
|
@@ -638,6 +732,14 @@ module Minitest
|
|
638
732
|
refute o1.__send__(op, o2), msg
|
639
733
|
end
|
640
734
|
|
735
|
+
##
|
736
|
+
# Fails if +path+ exists.
|
737
|
+
|
738
|
+
def refute_path_exists path, msg = nil
|
739
|
+
msg = message(msg) { "Expected path '#{path}' to not exist" }
|
740
|
+
refute File.exist?(path), msg
|
741
|
+
end
|
742
|
+
|
641
743
|
##
|
642
744
|
# For testing with predicates.
|
643
745
|
#
|
@@ -683,6 +785,18 @@ module Minitest
|
|
683
785
|
raise Minitest::Skip, msg, bt
|
684
786
|
end
|
685
787
|
|
788
|
+
##
|
789
|
+
# Skips the current run until a given date (in the local time
|
790
|
+
# zone). This allows you to put some fixes on hold until a later
|
791
|
+
# date, but still holds you accountable and prevents you from
|
792
|
+
# forgetting it.
|
793
|
+
|
794
|
+
def skip_until y,m,d,msg
|
795
|
+
skip msg if Time.now < Time.local(y, m, d)
|
796
|
+
where = caller.first.split(/:/, 3).first(2).join ":"
|
797
|
+
warn "Stale skip_until %p at %s" % [msg, where]
|
798
|
+
end
|
799
|
+
|
686
800
|
##
|
687
801
|
# Was this testcase skipped? Meant for #teardown.
|
688
802
|
|
data/lib/minitest/benchmark.rb
CHANGED
@@ -109,8 +109,8 @@ module Minitest
|
|
109
109
|
# is applied against the slope itself. As such, you probably want
|
110
110
|
# to tighten it from the default.
|
111
111
|
#
|
112
|
-
# See
|
113
|
-
# more details.
|
112
|
+
# See https://www.graphpad.com/guides/prism/8/curve-fitting/reg_intepretingnonlinr2.htm
|
113
|
+
# for more details.
|
114
114
|
#
|
115
115
|
# Fit is calculated by #fit_linear.
|
116
116
|
#
|