minitest 5.11.3 → 5.25.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 +375 -4
- data/Manifest.txt +6 -0
- data/README.rdoc +106 -17
- data/Rakefile +11 -16
- data/lib/hoe/minitest.rb +2 -5
- data/lib/minitest/assertions.rb +255 -93
- data/lib/minitest/autorun.rb +0 -7
- data/lib/minitest/benchmark.rb +13 -16
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +72 -35
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +151 -44
- data/lib/minitest/parallel.rb +5 -5
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/spec.rb +38 -19
- data/lib/minitest/test.rb +50 -33
- data/lib/minitest/test_task.rb +307 -0
- data/lib/minitest/unit.rb +5 -8
- data/lib/minitest.rb +414 -166
- data/test/minitest/metametameta.rb +65 -17
- data/test/minitest/test_minitest_assertions.rb +1720 -0
- data/test/minitest/test_minitest_benchmark.rb +3 -3
- data/test/minitest/test_minitest_mock.rb +409 -65
- data/test/minitest/test_minitest_reporter.rb +169 -32
- data/test/minitest/test_minitest_spec.rb +369 -193
- data/test/minitest/test_minitest_test.rb +463 -1249
- data/test/minitest/test_minitest_test_task.rb +57 -0
- data.tar.gz.sig +0 -0
- metadata +40 -23
- metadata.gz.sig +0 -0
data/README.rdoc
CHANGED
@@ -1,8 +1,9 @@
|
|
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
|
+
clog :: https://github.com/minitest/minitest/blob/master/History.rdoc
|
6
7
|
vim :: https://github.com/sunaku/vim-ruby-minitest
|
7
8
|
emacs:: https://github.com/arthurnn/minitest-emacs
|
8
9
|
|
@@ -70,6 +71,7 @@ extract-method refactorings still apply.
|
|
70
71
|
* minitest/mock - a simple and clean mock/stub system.
|
71
72
|
* minitest/benchmark - an awesome way to assert your algorithm's performance.
|
72
73
|
* minitest/pride - show your pride in testing!
|
74
|
+
* minitest/test_task - a full-featured and clean rake task generator.
|
73
75
|
* Incredibly small and fast runner, but no bells and whistles.
|
74
76
|
* Written by squishy human beings. Software can never be perfect. We will all eventually die.
|
75
77
|
|
@@ -126,13 +128,13 @@ Define your tests as methods beginning with +test_+.
|
|
126
128
|
|
127
129
|
describe "when asked about cheeseburgers" do
|
128
130
|
it "must respond positively" do
|
129
|
-
@meme.i_can_has_cheezburger
|
131
|
+
_(@meme.i_can_has_cheezburger?).must_equal "OHAI!"
|
130
132
|
end
|
131
133
|
end
|
132
134
|
|
133
135
|
describe "when asked about blending possibilities" do
|
134
136
|
it "won't say no" do
|
135
|
-
@meme.will_it_blend
|
137
|
+
_(@meme.will_it_blend?).wont_match /^no/i
|
136
138
|
end
|
137
139
|
end
|
138
140
|
end
|
@@ -186,7 +188,7 @@ Output is tab-delimited to make it easy to paste into a spreadsheet.
|
|
186
188
|
=== Mocks
|
187
189
|
|
188
190
|
Mocks and stubs defined using terminology by Fowler & Meszaros at
|
189
|
-
|
191
|
+
https://www.martinfowler.com/bliki/TestDouble.html:
|
190
192
|
|
191
193
|
"Mocks are pre-programmed with expectations which form a specification
|
192
194
|
of the calls they are expected to receive. They can throw an exception
|
@@ -220,9 +222,9 @@ verification to ensure they got all the calls they were expecting."
|
|
220
222
|
end
|
221
223
|
end
|
222
224
|
|
223
|
-
|
225
|
+
==== Multi-threading and Mocks
|
224
226
|
|
225
|
-
Minitest mocks do not support multi-threading
|
227
|
+
Minitest mocks do not support multi-threading. If it works, fine, if it doesn't
|
226
228
|
you can use regular ruby patterns and facilities like local variables. Here's
|
227
229
|
an example of asserting that code inside a thread is run:
|
228
230
|
|
@@ -237,7 +239,7 @@ an example of asserting that code inside a thread is run:
|
|
237
239
|
=== Stubs
|
238
240
|
|
239
241
|
Mocks and stubs are defined using terminology by Fowler & Meszaros at
|
240
|
-
|
242
|
+
https://www.martinfowler.com/bliki/TestDouble.html:
|
241
243
|
|
242
244
|
"Stubs provide canned answers to calls made during the test".
|
243
245
|
|
@@ -264,9 +266,8 @@ new non-existing method:
|
|
264
266
|
|
265
267
|
=== Running Your Tests
|
266
268
|
|
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:
|
269
|
+
Ideally, you'll use a rake task to run your tests (see below), either
|
270
|
+
piecemeal or all at once. BUT! You don't have to:
|
270
271
|
|
271
272
|
% ruby -Ilib:test test/minitest/test_minitest_test.rb
|
272
273
|
Run options: --seed 37685
|
@@ -294,6 +295,45 @@ provided via plugins. To see them, simply run with +--help+:
|
|
294
295
|
-p, --pride Pride. Show your testing pride!
|
295
296
|
-a, --autotest Connect to autotest server.
|
296
297
|
|
298
|
+
=== Rake Tasks
|
299
|
+
|
300
|
+
You can set up a rake task to run all your tests by adding this to your Rakefile:
|
301
|
+
|
302
|
+
require "minitest/test_task"
|
303
|
+
|
304
|
+
Minitest::TestTask.create # named test, sensible defaults
|
305
|
+
|
306
|
+
# or more explicitly:
|
307
|
+
|
308
|
+
Minitest::TestTask.create(:test) do |t|
|
309
|
+
t.libs << "test"
|
310
|
+
t.libs << "lib"
|
311
|
+
t.warning = false
|
312
|
+
t.test_globs = ["test/**/*_test.rb"]
|
313
|
+
end
|
314
|
+
|
315
|
+
task :default => :test
|
316
|
+
|
317
|
+
Each of these will generate 4 tasks:
|
318
|
+
|
319
|
+
rake test :: Run the test suite.
|
320
|
+
rake test:cmd :: Print out the test command.
|
321
|
+
rake test:isolated :: Show which test files fail when run separately.
|
322
|
+
rake test:slow :: Show bottom 25 tests sorted by time.
|
323
|
+
|
324
|
+
=== Rake Task Variables
|
325
|
+
|
326
|
+
There are a bunch of variables you can supply to rake to modify the run.
|
327
|
+
|
328
|
+
MT_LIB_EXTRAS :: Extra libs to dynamically override/inject for custom runs.
|
329
|
+
N :: -n: Tests to run (string or /regexp/).
|
330
|
+
X :: -x: Tests to exclude (string or /regexp/).
|
331
|
+
A :: Any extra arguments. Honors shell quoting.
|
332
|
+
MT_CPU :: How many threads to use for parallel test runs
|
333
|
+
SEED :: -s --seed Sets random seed.
|
334
|
+
TESTOPTS :: Deprecated, same as A
|
335
|
+
FILTER :: Deprecated, same as A
|
336
|
+
|
297
337
|
== Writing Extensions
|
298
338
|
|
299
339
|
To define a plugin, add a file named minitest/XXX_plugin.rb to your
|
@@ -364,6 +404,42 @@ Using our example above, here is how we might implement MyCI:
|
|
364
404
|
|
365
405
|
== FAQ
|
366
406
|
|
407
|
+
=== What versions are compatible with what? Or what versions are supported?
|
408
|
+
|
409
|
+
Minitest is a dependency of rails, which until very recently had an
|
410
|
+
overzealous backwards compatibility policy. As such, I'm stuck
|
411
|
+
supporting versions of ruby that are long past EOL. Hopefully I'll be
|
412
|
+
able to support only current versions of ruby sometime in the near
|
413
|
+
future.
|
414
|
+
|
415
|
+
(As of 2024-05-10)
|
416
|
+
|
417
|
+
Current versions of rails: (https://endoflife.date/rails)
|
418
|
+
|
419
|
+
| rails | min ruby | minitest | status | EOL Date |
|
420
|
+
|-------+----------+----------+----------+------------|
|
421
|
+
| 7.1 | >= 2.7 | >= 5.1 | Current | 2026-06-01?|
|
422
|
+
| 7.0 | >= 2.7 | >= 5.1 | Maint | 2025-06-01?|
|
423
|
+
| 6.1 | >= 2.5 | >= 5.1 | Security | 2024-06-01?|
|
424
|
+
| 6.0 | >= 2.5 | >= 5.1 | EOL | 2023-06-01 |
|
425
|
+
| 5.2 | >= 2.2.2 | ~> 5.1 | EOL | 2022-06-01 |
|
426
|
+
|
427
|
+
If you want to look at the requirements for a specific version, run:
|
428
|
+
|
429
|
+
gem spec -r --ruby rails -v 7.0.0
|
430
|
+
|
431
|
+
Current versions of ruby: (https://endoflife.date/ruby)
|
432
|
+
|
433
|
+
| ruby | Status | EOL Date |
|
434
|
+
|------+---------+------------|
|
435
|
+
| 3.3 | Current | 2027-03-31 |
|
436
|
+
| 3.2 | Maint | 2026-03-31 |
|
437
|
+
| 3.1 | Security| 2025-03-31 |
|
438
|
+
| 3.0 | EOL | 2024-03-31 |
|
439
|
+
| 2.7 | EOL | 2023-03-31 |
|
440
|
+
| 2.6 | EOL | 2022-03-31 |
|
441
|
+
| 2.5 | EOL | 2021-03-31 | DO YOU SEE WHAT I'M STUCK WITH???
|
442
|
+
|
367
443
|
=== How to test SimpleDelegates?
|
368
444
|
|
369
445
|
The following implementation and test:
|
@@ -379,7 +455,7 @@ The following implementation and test:
|
|
379
455
|
end
|
380
456
|
|
381
457
|
it "must respond to work" do
|
382
|
-
@worker.must_respond_to :work
|
458
|
+
_(@worker).must_respond_to :work
|
383
459
|
end
|
384
460
|
end
|
385
461
|
|
@@ -469,6 +545,8 @@ able to require minitest and run your tests.
|
|
469
545
|
|
470
546
|
== Developing Minitest:
|
471
547
|
|
548
|
+
Minitest requires {Hoe}[https://rubygems.org/gems/hoe].
|
549
|
+
|
472
550
|
=== Minitest's own tests require UTF-8 external encoding.
|
473
551
|
|
474
552
|
This is a common problem in Windows, where the default external Encoding is
|
@@ -547,6 +625,7 @@ minispec-metadata :: Metadata for describe/it blocks & CLI tag filter.
|
|
547
625
|
E.g. <tt>it "requires JS driver", js: true do</tt> &
|
548
626
|
<tt>ruby test.rb --tag js</tt> runs tests tagged :js.
|
549
627
|
minispec-rails :: Minimal support to use Spec style in Rails 5+.
|
628
|
+
mini-apivore :: for swagger based automated API testing.
|
550
629
|
minitest-around :: Around block for minitest. An alternative to
|
551
630
|
setup/teardown dance.
|
552
631
|
minitest-assert_errors :: Adds Minitest assertions to test for errors raised
|
@@ -563,6 +642,7 @@ minitest-capistrano :: Assertions and expectations for testing
|
|
563
642
|
Capistrano recipes.
|
564
643
|
minitest-capybara :: Capybara matchers support for minitest unit and
|
565
644
|
spec.
|
645
|
+
minitest-cc :: It provides minimal information about code coverage.
|
566
646
|
minitest-chef-handler :: Run Minitest suites as Chef report handlers
|
567
647
|
minitest-ci :: CI reporter plugin for Minitest.
|
568
648
|
minitest-context :: Defines contexts for code reuse in Minitest
|
@@ -589,12 +669,14 @@ minitest-firemock :: Makes your Minitest mocks more resilient.
|
|
589
669
|
minitest-focus :: Focus on one test at a time.
|
590
670
|
minitest-gcstats :: A minitest plugin that adds a report of the top
|
591
671
|
tests by number of objects allocated.
|
672
|
+
minitest-global_expectations:: Support minitest expectation methods for all objects
|
592
673
|
minitest-great_expectations :: Generally useful additions to minitest's
|
593
674
|
assertions and expectations.
|
594
675
|
minitest-growl :: Test notifier for minitest via growl.
|
595
676
|
minitest-happy :: GLOBALLY ACTIVATE MINITEST PRIDE! RAWR!
|
596
677
|
minitest-have_tag :: Adds Minitest assertions to test for the existence of
|
597
678
|
HTML tags, including contents, within a provided string.
|
679
|
+
minitest-heat :: Reporting that builds a heat map of failure locations
|
598
680
|
minitest-hooks :: Around and before_all/after_all/around_all hooks
|
599
681
|
minitest-hyper :: Pretty, single-page HTML reports for your Minitest runs
|
600
682
|
minitest-implicit-subject :: Implicit declaration of the test subject.
|
@@ -615,6 +697,7 @@ minitest-matchers :: Adds support for RSpec-style matchers to
|
|
615
697
|
minitest-matchers_vaccine :: Adds assertions that adhere to the matcher spec,
|
616
698
|
but without any expectation infections.
|
617
699
|
minitest-metadata :: Annotate tests with metadata (key-value).
|
700
|
+
minitest-mock_expectations :: Provides method call assertions for minitest.
|
618
701
|
minitest-mongoid :: Mongoid assertion matchers for Minitest.
|
619
702
|
minitest-must_not :: Provides must_not as an alias for wont in
|
620
703
|
Minitest.
|
@@ -658,16 +741,23 @@ minitest-stub-const :: Stub constants for the duration of a block.
|
|
658
741
|
minitest-tags :: Add tags for minitest.
|
659
742
|
minitest-unordered :: Adds a new assertion to minitest for checking the
|
660
743
|
contents of a collection, ignoring element order.
|
661
|
-
minitest-vcr :: Automatic cassette
|
744
|
+
minitest-vcr :: Automatic cassette management with Minitest::Spec
|
662
745
|
and VCR.
|
746
|
+
minitest_log :: Adds structured logging, data explication, and verdicts.
|
663
747
|
minitest_owrapper :: Get tests results as a TestResult object.
|
664
748
|
minitest_should :: Shoulda style syntax for minitest test::unit.
|
665
749
|
minitest_tu_shim :: Bridges between test/unit and minitest.
|
666
750
|
mongoid-minitest :: Minitest matchers for Mongoid.
|
751
|
+
mutant-minitest :: Minitest integration for mutant.
|
667
752
|
pry-rescue :: A pry plugin w/ minitest support. See
|
668
753
|
pry-rescue/minitest.rb.
|
754
|
+
rematch :: Declutter your test files from large hardcoded data
|
755
|
+
and update them automatically when your code changes.
|
669
756
|
rspec2minitest :: Easily translate any RSpec matchers to Minitest
|
670
757
|
assertions and expectations.
|
758
|
+
stubberry :: Multiple stubbing 'berries', sweet and useful
|
759
|
+
stub helpers and assertions. ( stub_must,
|
760
|
+
assert_method_called, stubbing ORM objects by id )
|
671
761
|
|
672
762
|
== Unknown Extensions:
|
673
763
|
|
@@ -693,12 +783,11 @@ Authors... Please send me a pull request with a description of your minitest ext
|
|
693
783
|
|
694
784
|
== Minitest related goods
|
695
785
|
|
696
|
-
* minitest/pride fabric:
|
786
|
+
* minitest/pride fabric: https://www.spoonflower.com/fabric/3928730-again-by-katie_allen
|
697
787
|
|
698
788
|
== REQUIREMENTS:
|
699
789
|
|
700
|
-
* Ruby
|
701
|
-
* NOTE: 1.8 and 1.9 will be dropped in minitest 6+.
|
790
|
+
* Ruby 2.3+. No magic is involved. I hope.
|
702
791
|
|
703
792
|
== INSTALL:
|
704
793
|
|
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,21 +12,7 @@ Hoe.spec "minitest" do
|
|
11
12
|
|
12
13
|
license "MIT"
|
13
14
|
|
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
|
15
|
+
require_ruby_version [">= 2.6", "< 4.0"]
|
29
16
|
end
|
30
17
|
|
31
18
|
desc "Find missing expectations"
|
@@ -35,7 +22,7 @@ task :specs do
|
|
35
22
|
require "minitest/spec"
|
36
23
|
|
37
24
|
pos_prefix, neg_prefix = "must", "wont"
|
38
|
-
skip_re = /^(must|wont)$|wont_(throw)|must_(block|not?_|nothing|raise$)/x
|
25
|
+
skip_re = /^(must|wont)$|wont_(throw)|must_(block|not?_|nothing|send|raise$)/x
|
39
26
|
dont_flip_re = /(must|wont)_(include|respond_to)/
|
40
27
|
|
41
28
|
map = {
|
@@ -46,6 +33,9 @@ task :specs do
|
|
46
33
|
/_includes/ => "_include",
|
47
34
|
/(must|wont)_(.*_of|nil|silent|empty)/ => '\1_be_\2',
|
48
35
|
/must_raises/ => "must_raise",
|
36
|
+
/(must|wont)_pattern/ => '\1_pattern_match',
|
37
|
+
/(must|wont)_predicate/ => '\1_be',
|
38
|
+
/(must|wont)_path_exists/ => 'path_\1_exist',
|
49
39
|
}
|
50
40
|
|
51
41
|
expectations = Minitest::Expectations.public_instance_methods.map(&:to_s)
|
@@ -83,4 +73,9 @@ task :bugs do
|
|
83
73
|
sh "for f in bug*.rb ; do echo $f; echo; #{Gem.ruby} -Ilib $f && rm $f ; done"
|
84
74
|
end
|
85
75
|
|
76
|
+
Minitest::TestTask.create :testW0 do |t|
|
77
|
+
t.warning = false
|
78
|
+
t.test_prelude = "$-w = nil"
|
79
|
+
end
|
80
|
+
|
86
81
|
# vim: syntax=Ruby
|
data/lib/hoe/minitest.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# :stopdoc:
|
2
2
|
|
3
3
|
class Hoe
|
4
|
+
# empty
|
4
5
|
end
|
5
6
|
|
6
7
|
module Hoe::Minitest
|
@@ -16,7 +17,7 @@ module Hoe::Minitest
|
|
16
17
|
|
17
18
|
gem "minitest"
|
18
19
|
require "minitest"
|
19
|
-
version = Minitest::VERSION.split(
|
20
|
+
version = Minitest::VERSION.split(".").first(2).join "."
|
20
21
|
|
21
22
|
dependency "minitest", "~> #{version}", :development unless
|
22
23
|
minitest? or ENV["MT_NO_ISOLATE"]
|
@@ -24,9 +25,5 @@ module Hoe::Minitest
|
|
24
25
|
|
25
26
|
def define_minitest_tasks
|
26
27
|
self.testlib = :minitest
|
27
|
-
|
28
|
-
# make sure we use the gemmed minitest on 1.9
|
29
|
-
self.test_prelude = 'gem "minitest"' unless
|
30
|
-
minitest? or ENV["MT_NO_ISOLATE"]
|
31
28
|
end
|
32
29
|
end
|