minitest 4.7.5 → 5.0.7
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.
- data/.autotest +21 -8
- data/History.txt +132 -12
- data/Manifest.txt +6 -0
- data/README.txt +109 -59
- data/Rakefile +3 -31
- data/design_rationale.rb +2 -2
- data/lib/hoe/minitest.rb +9 -5
- data/lib/minitest/assertions.rb +649 -0
- data/lib/minitest/autorun.rb +6 -6
- data/lib/minitest/benchmark.rb +92 -85
- data/lib/minitest/expectations.rb +281 -0
- data/lib/minitest/hell.rb +3 -5
- data/lib/minitest/mock.rb +40 -13
- data/lib/minitest/parallel_each.rb +59 -12
- data/lib/minitest/pride.rb +3 -111
- data/lib/minitest/pride_plugin.rb +143 -0
- data/lib/minitest/spec.rb +45 -312
- data/lib/minitest/test.rb +287 -0
- data/lib/minitest/unit.rb +32 -1402
- data/lib/minitest.rb +733 -0
- data/test/minitest/metametameta.rb +41 -30
- data/test/minitest/test_minitest_benchmark.rb +11 -9
- data/test/minitest/test_minitest_mock.rb +116 -32
- data/test/minitest/test_minitest_reporter.rb +313 -0
- data/test/minitest/test_minitest_spec.rb +52 -63
- data/test/minitest/test_minitest_unit.rb +231 -235
- data.tar.gz.sig +0 -0
- metadata +17 -10
- metadata.gz.sig +2 -1
data/lib/minitest/spec.rb
CHANGED
|
@@ -9,39 +9,26 @@ class Module # :nodoc:
|
|
|
9
9
|
def #{new_name} *args
|
|
10
10
|
case
|
|
11
11
|
when Proc === self then
|
|
12
|
-
|
|
12
|
+
Minitest::Spec.current.#{meth}(*args, &self)
|
|
13
13
|
when #{!!dont_flip} then
|
|
14
|
-
|
|
14
|
+
Minitest::Spec.current.#{meth}(self, *args)
|
|
15
15
|
else
|
|
16
|
-
|
|
16
|
+
Minitest::Spec.current.#{meth}(args.first, self, *args[1..-1])
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
EOM
|
|
20
20
|
end
|
|
21
|
-
|
|
22
|
-
##
|
|
23
|
-
# infect_with_assertions has been removed due to excessive clever.
|
|
24
|
-
# Use infect_an_assertion directly instead.
|
|
25
|
-
|
|
26
|
-
def infect_with_assertions(pos_prefix, neg_prefix,
|
|
27
|
-
skip_re,
|
|
28
|
-
dont_flip_re = /\c0/,
|
|
29
|
-
map = {})
|
|
30
|
-
abort "infect_with_assertions is dead. Use infect_an_assertion directly"
|
|
31
|
-
end
|
|
32
21
|
end
|
|
33
22
|
|
|
34
23
|
module Kernel # :nodoc:
|
|
35
24
|
##
|
|
36
25
|
# Describe a series of expectations for a given target +desc+.
|
|
37
26
|
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
# Defines a test class subclassing from either MiniTest::Spec or
|
|
27
|
+
# Defines a test class subclassing from either Minitest::Spec or
|
|
41
28
|
# from the surrounding describe's class. The surrounding class may
|
|
42
|
-
# subclass
|
|
29
|
+
# subclass Minitest::Spec manually in order to easily share code:
|
|
43
30
|
#
|
|
44
|
-
# class MySpec <
|
|
31
|
+
# class MySpec < Minitest::Spec
|
|
45
32
|
# # ... shared code ...
|
|
46
33
|
# end
|
|
47
34
|
#
|
|
@@ -55,14 +42,27 @@ module Kernel # :nodoc:
|
|
|
55
42
|
# end
|
|
56
43
|
# end
|
|
57
44
|
# end
|
|
45
|
+
#
|
|
46
|
+
# For more information on getting started with writing specs, see:
|
|
47
|
+
#
|
|
48
|
+
# http://www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html
|
|
49
|
+
#
|
|
50
|
+
# For some suggestions on how to improve your specs, try:
|
|
51
|
+
#
|
|
52
|
+
# http://betterspecs.org
|
|
53
|
+
#
|
|
54
|
+
# but do note that several items there are debatable or specific to
|
|
55
|
+
# rspec.
|
|
56
|
+
#
|
|
57
|
+
# For more information about expectations, see Minitest::Expectations.
|
|
58
58
|
|
|
59
59
|
def describe desc, additional_desc = nil, &block # :doc:
|
|
60
|
-
stack =
|
|
60
|
+
stack = Minitest::Spec.describe_stack
|
|
61
61
|
name = [stack.last, desc, additional_desc].compact.join("::")
|
|
62
|
-
sclas = stack.last || if Class === self && is_a?(
|
|
62
|
+
sclas = stack.last || if Class === self && is_a?(Minitest::Spec::DSL) then
|
|
63
63
|
self
|
|
64
64
|
else
|
|
65
|
-
|
|
65
|
+
Minitest::Spec.spec_type desc
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
cls = sclas.create name, desc
|
|
@@ -76,14 +76,23 @@ module Kernel # :nodoc:
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
##
|
|
79
|
-
#
|
|
79
|
+
# Minitest::Spec -- The faster, better, less-magical spec framework!
|
|
80
80
|
#
|
|
81
|
-
# For a list of expectations, see
|
|
81
|
+
# For a list of expectations, see Minitest::Expectations.
|
|
82
82
|
|
|
83
|
-
class
|
|
83
|
+
class Minitest::Spec < Minitest::Test
|
|
84
|
+
|
|
85
|
+
def self.current # :nodoc:
|
|
86
|
+
Thread.current[:current_spec]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def initialize name # :nodoc:
|
|
90
|
+
super
|
|
91
|
+
Thread.current[:current_spec] = self
|
|
92
|
+
end
|
|
84
93
|
|
|
85
94
|
##
|
|
86
|
-
# Oh look! A
|
|
95
|
+
# Oh look! A Minitest::Spec::DSL module! Eat your heart out DHH.
|
|
87
96
|
|
|
88
97
|
module DSL
|
|
89
98
|
##
|
|
@@ -93,7 +102,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
93
102
|
#
|
|
94
103
|
# See: register_spec_type and spec_type
|
|
95
104
|
|
|
96
|
-
TYPES = [[//,
|
|
105
|
+
TYPES = [[//, Minitest::Spec]]
|
|
97
106
|
|
|
98
107
|
##
|
|
99
108
|
# Register a new type of spec that matches the spec's description.
|
|
@@ -103,11 +112,11 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
103
112
|
#
|
|
104
113
|
# Eg:
|
|
105
114
|
#
|
|
106
|
-
# register_spec_type(/Controller$/,
|
|
115
|
+
# register_spec_type(/Controller$/, Minitest::Spec::Rails)
|
|
107
116
|
#
|
|
108
117
|
# or:
|
|
109
118
|
#
|
|
110
|
-
# register_spec_type(
|
|
119
|
+
# register_spec_type(Minitest::Spec::RailsModel) do |desc|
|
|
111
120
|
# desc.superclass == ActiveRecord::Base
|
|
112
121
|
# end
|
|
113
122
|
|
|
@@ -123,7 +132,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
123
132
|
##
|
|
124
133
|
# Figure out the spec class to use based on a spec's description. Eg:
|
|
125
134
|
#
|
|
126
|
-
# spec_type("BlahController") # =>
|
|
135
|
+
# spec_type("BlahController") # => Minitest::Spec::Rails
|
|
127
136
|
|
|
128
137
|
def spec_type desc
|
|
129
138
|
TYPES.find { |matcher, klass|
|
|
@@ -157,7 +166,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
157
166
|
#
|
|
158
167
|
# NOTE: +type+ is ignored and is only there to make porting easier.
|
|
159
168
|
#
|
|
160
|
-
# Equivalent to
|
|
169
|
+
# Equivalent to Minitest::Test#setup.
|
|
161
170
|
|
|
162
171
|
def before type = nil, &block
|
|
163
172
|
define_method :setup do
|
|
@@ -171,7 +180,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
171
180
|
#
|
|
172
181
|
# NOTE: +type+ is ignored and is only there to make porting easier.
|
|
173
182
|
#
|
|
174
|
-
# Equivalent to
|
|
183
|
+
# Equivalent to Minitest::Test#teardown.
|
|
175
184
|
|
|
176
185
|
def after type = nil, &block
|
|
177
186
|
define_method :teardown do
|
|
@@ -188,7 +197,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
188
197
|
#
|
|
189
198
|
# This is also aliased to #specify and doesn't require a +desc+ arg.
|
|
190
199
|
#
|
|
191
|
-
# Hint: If you _do_ want inheritence, use minitest/
|
|
200
|
+
# Hint: If you _do_ want inheritence, use minitest/test. You can mix
|
|
192
201
|
# and match between assertions and expectations as much as you want.
|
|
193
202
|
|
|
194
203
|
def it desc = "anonymous", &block
|
|
@@ -214,6 +223,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
214
223
|
# Why use let instead of def? I honestly don't know.
|
|
215
224
|
|
|
216
225
|
def let name, &block
|
|
226
|
+
raise ArgumentError, 'name cannot begin with "test"' if name.to_s =~ /\Atest/
|
|
217
227
|
define_method name do
|
|
218
228
|
@_memoized ||= {}
|
|
219
229
|
@_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }
|
|
@@ -260,285 +270,8 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|
|
260
270
|
TYPES = DSL::TYPES # :nodoc:
|
|
261
271
|
end
|
|
262
272
|
|
|
263
|
-
|
|
264
|
-
# It's where you hide your "assertions".
|
|
265
|
-
|
|
266
|
-
module MiniTest::Expectations
|
|
267
|
-
##
|
|
268
|
-
# See MiniTest::Assertions#assert_empty.
|
|
269
|
-
#
|
|
270
|
-
# collection.must_be_empty
|
|
271
|
-
#
|
|
272
|
-
# :method: must_be_empty
|
|
273
|
-
|
|
274
|
-
infect_an_assertion :assert_empty, :must_be_empty, :unary
|
|
275
|
-
|
|
276
|
-
##
|
|
277
|
-
# See MiniTest::Assertions#assert_equal
|
|
278
|
-
#
|
|
279
|
-
# a.must_equal b
|
|
280
|
-
#
|
|
281
|
-
# :method: must_equal
|
|
282
|
-
|
|
283
|
-
infect_an_assertion :assert_equal, :must_equal
|
|
284
|
-
|
|
285
|
-
##
|
|
286
|
-
# See MiniTest::Assertions#assert_in_delta
|
|
287
|
-
#
|
|
288
|
-
# n.must_be_close_to m [, delta]
|
|
289
|
-
#
|
|
290
|
-
# :method: must_be_close_to
|
|
291
|
-
|
|
292
|
-
infect_an_assertion :assert_in_delta, :must_be_close_to
|
|
293
|
-
|
|
294
|
-
alias :must_be_within_delta :must_be_close_to # :nodoc:
|
|
295
|
-
|
|
296
|
-
##
|
|
297
|
-
# See MiniTest::Assertions#assert_in_epsilon
|
|
298
|
-
#
|
|
299
|
-
# n.must_be_within_epsilon m [, epsilon]
|
|
300
|
-
#
|
|
301
|
-
# :method: must_be_within_epsilon
|
|
302
|
-
|
|
303
|
-
infect_an_assertion :assert_in_epsilon, :must_be_within_epsilon
|
|
304
|
-
|
|
305
|
-
##
|
|
306
|
-
# See MiniTest::Assertions#assert_includes
|
|
307
|
-
#
|
|
308
|
-
# collection.must_include obj
|
|
309
|
-
#
|
|
310
|
-
# :method: must_include
|
|
311
|
-
|
|
312
|
-
infect_an_assertion :assert_includes, :must_include, :reverse
|
|
313
|
-
|
|
314
|
-
##
|
|
315
|
-
# See MiniTest::Assertions#assert_instance_of
|
|
316
|
-
#
|
|
317
|
-
# obj.must_be_instance_of klass
|
|
318
|
-
#
|
|
319
|
-
# :method: must_be_instance_of
|
|
320
|
-
|
|
321
|
-
infect_an_assertion :assert_instance_of, :must_be_instance_of
|
|
322
|
-
|
|
323
|
-
##
|
|
324
|
-
# See MiniTest::Assertions#assert_kind_of
|
|
325
|
-
#
|
|
326
|
-
# obj.must_be_kind_of mod
|
|
327
|
-
#
|
|
328
|
-
# :method: must_be_kind_of
|
|
329
|
-
|
|
330
|
-
infect_an_assertion :assert_kind_of, :must_be_kind_of
|
|
331
|
-
|
|
332
|
-
##
|
|
333
|
-
# See MiniTest::Assertions#assert_match
|
|
334
|
-
#
|
|
335
|
-
# a.must_match b
|
|
336
|
-
#
|
|
337
|
-
# :method: must_match
|
|
338
|
-
|
|
339
|
-
infect_an_assertion :assert_match, :must_match
|
|
340
|
-
|
|
341
|
-
##
|
|
342
|
-
# See MiniTest::Assertions#assert_nil
|
|
343
|
-
#
|
|
344
|
-
# obj.must_be_nil
|
|
345
|
-
#
|
|
346
|
-
# :method: must_be_nil
|
|
347
|
-
|
|
348
|
-
infect_an_assertion :assert_nil, :must_be_nil, :unary
|
|
349
|
-
|
|
350
|
-
##
|
|
351
|
-
# See MiniTest::Assertions#assert_operator
|
|
352
|
-
#
|
|
353
|
-
# n.must_be :<=, 42
|
|
354
|
-
#
|
|
355
|
-
# This can also do predicates:
|
|
356
|
-
#
|
|
357
|
-
# str.must_be :empty?
|
|
358
|
-
#
|
|
359
|
-
# :method: must_be
|
|
360
|
-
|
|
361
|
-
infect_an_assertion :assert_operator, :must_be, :reverse
|
|
362
|
-
|
|
363
|
-
##
|
|
364
|
-
# See MiniTest::Assertions#assert_output
|
|
365
|
-
#
|
|
366
|
-
# proc { ... }.must_output out_or_nil [, err]
|
|
367
|
-
#
|
|
368
|
-
# :method: must_output
|
|
369
|
-
|
|
370
|
-
infect_an_assertion :assert_output, :must_output
|
|
371
|
-
|
|
372
|
-
##
|
|
373
|
-
# See MiniTest::Assertions#assert_raises
|
|
374
|
-
#
|
|
375
|
-
# proc { ... }.must_raise exception
|
|
376
|
-
#
|
|
377
|
-
# :method: must_raise
|
|
378
|
-
|
|
379
|
-
infect_an_assertion :assert_raises, :must_raise
|
|
380
|
-
|
|
381
|
-
##
|
|
382
|
-
# See MiniTest::Assertions#assert_respond_to
|
|
383
|
-
#
|
|
384
|
-
# obj.must_respond_to msg
|
|
385
|
-
#
|
|
386
|
-
# :method: must_respond_to
|
|
387
|
-
|
|
388
|
-
infect_an_assertion :assert_respond_to, :must_respond_to, :reverse
|
|
389
|
-
|
|
390
|
-
##
|
|
391
|
-
# See MiniTest::Assertions#assert_same
|
|
392
|
-
#
|
|
393
|
-
# a.must_be_same_as b
|
|
394
|
-
#
|
|
395
|
-
# :method: must_be_same_as
|
|
396
|
-
|
|
397
|
-
infect_an_assertion :assert_same, :must_be_same_as
|
|
398
|
-
|
|
399
|
-
##
|
|
400
|
-
# See MiniTest::Assertions#assert_send
|
|
401
|
-
# TODO: remove me
|
|
402
|
-
#
|
|
403
|
-
# a.must_send
|
|
404
|
-
#
|
|
405
|
-
# :method: must_send
|
|
406
|
-
|
|
407
|
-
infect_an_assertion :assert_send, :must_send
|
|
408
|
-
|
|
409
|
-
##
|
|
410
|
-
# See MiniTest::Assertions#assert_silent
|
|
411
|
-
#
|
|
412
|
-
# proc { ... }.must_be_silent
|
|
413
|
-
#
|
|
414
|
-
# :method: must_be_silent
|
|
415
|
-
|
|
416
|
-
infect_an_assertion :assert_silent, :must_be_silent
|
|
417
|
-
|
|
418
|
-
##
|
|
419
|
-
# See MiniTest::Assertions#assert_throws
|
|
420
|
-
#
|
|
421
|
-
# proc { ... }.must_throw sym
|
|
422
|
-
#
|
|
423
|
-
# :method: must_throw
|
|
424
|
-
|
|
425
|
-
infect_an_assertion :assert_throws, :must_throw
|
|
426
|
-
|
|
427
|
-
##
|
|
428
|
-
# See MiniTest::Assertions#refute_empty
|
|
429
|
-
#
|
|
430
|
-
# collection.wont_be_empty
|
|
431
|
-
#
|
|
432
|
-
# :method: wont_be_empty
|
|
433
|
-
|
|
434
|
-
infect_an_assertion :refute_empty, :wont_be_empty, :unary
|
|
435
|
-
|
|
436
|
-
##
|
|
437
|
-
# See MiniTest::Assertions#refute_equal
|
|
438
|
-
#
|
|
439
|
-
# a.wont_equal b
|
|
440
|
-
#
|
|
441
|
-
# :method: wont_equal
|
|
442
|
-
|
|
443
|
-
infect_an_assertion :refute_equal, :wont_equal
|
|
444
|
-
|
|
445
|
-
##
|
|
446
|
-
# See MiniTest::Assertions#refute_in_delta
|
|
447
|
-
#
|
|
448
|
-
# n.wont_be_close_to m [, delta]
|
|
449
|
-
#
|
|
450
|
-
# :method: wont_be_close_to
|
|
451
|
-
|
|
452
|
-
infect_an_assertion :refute_in_delta, :wont_be_close_to
|
|
453
|
-
|
|
454
|
-
alias :wont_be_within_delta :wont_be_close_to # :nodoc:
|
|
455
|
-
|
|
456
|
-
##
|
|
457
|
-
# See MiniTest::Assertions#refute_in_epsilon
|
|
458
|
-
#
|
|
459
|
-
# n.wont_be_within_epsilon m [, epsilon]
|
|
460
|
-
#
|
|
461
|
-
# :method: wont_be_within_epsilon
|
|
462
|
-
|
|
463
|
-
infect_an_assertion :refute_in_epsilon, :wont_be_within_epsilon
|
|
464
|
-
|
|
465
|
-
##
|
|
466
|
-
# See MiniTest::Assertions#refute_includes
|
|
467
|
-
#
|
|
468
|
-
# collection.wont_include obj
|
|
469
|
-
#
|
|
470
|
-
# :method: wont_include
|
|
471
|
-
|
|
472
|
-
infect_an_assertion :refute_includes, :wont_include, :reverse
|
|
473
|
-
|
|
474
|
-
##
|
|
475
|
-
# See MiniTest::Assertions#refute_instance_of
|
|
476
|
-
#
|
|
477
|
-
# obj.wont_be_instance_of klass
|
|
478
|
-
#
|
|
479
|
-
# :method: wont_be_instance_of
|
|
480
|
-
|
|
481
|
-
infect_an_assertion :refute_instance_of, :wont_be_instance_of
|
|
482
|
-
|
|
483
|
-
##
|
|
484
|
-
# See MiniTest::Assertions#refute_kind_of
|
|
485
|
-
#
|
|
486
|
-
# obj.wont_be_kind_of mod
|
|
487
|
-
#
|
|
488
|
-
# :method: wont_be_kind_of
|
|
489
|
-
|
|
490
|
-
infect_an_assertion :refute_kind_of, :wont_be_kind_of
|
|
491
|
-
|
|
492
|
-
##
|
|
493
|
-
# See MiniTest::Assertions#refute_match
|
|
494
|
-
#
|
|
495
|
-
# a.wont_match b
|
|
496
|
-
#
|
|
497
|
-
# :method: wont_match
|
|
498
|
-
|
|
499
|
-
infect_an_assertion :refute_match, :wont_match
|
|
500
|
-
|
|
501
|
-
##
|
|
502
|
-
# See MiniTest::Assertions#refute_nil
|
|
503
|
-
#
|
|
504
|
-
# obj.wont_be_nil
|
|
505
|
-
#
|
|
506
|
-
# :method: wont_be_nil
|
|
507
|
-
|
|
508
|
-
infect_an_assertion :refute_nil, :wont_be_nil, :unary
|
|
509
|
-
|
|
510
|
-
##
|
|
511
|
-
# See MiniTest::Assertions#refute_operator
|
|
512
|
-
#
|
|
513
|
-
# n.wont_be :<=, 42
|
|
514
|
-
#
|
|
515
|
-
# This can also do predicates:
|
|
516
|
-
#
|
|
517
|
-
# str.wont_be :empty?
|
|
518
|
-
#
|
|
519
|
-
# :method: wont_be
|
|
520
|
-
|
|
521
|
-
infect_an_assertion :refute_operator, :wont_be, :reverse
|
|
522
|
-
|
|
523
|
-
##
|
|
524
|
-
# See MiniTest::Assertions#refute_respond_to
|
|
525
|
-
#
|
|
526
|
-
# obj.wont_respond_to msg
|
|
527
|
-
#
|
|
528
|
-
# :method: wont_respond_to
|
|
529
|
-
|
|
530
|
-
infect_an_assertion :refute_respond_to, :wont_respond_to, :reverse
|
|
531
|
-
|
|
532
|
-
##
|
|
533
|
-
# See MiniTest::Assertions#refute_same
|
|
534
|
-
#
|
|
535
|
-
# a.wont_be_same_as b
|
|
536
|
-
#
|
|
537
|
-
# :method: wont_be_same_as
|
|
538
|
-
|
|
539
|
-
infect_an_assertion :refute_same, :wont_be_same_as
|
|
540
|
-
end
|
|
273
|
+
require "minitest/expectations"
|
|
541
274
|
|
|
542
275
|
class Object # :nodoc:
|
|
543
|
-
include
|
|
276
|
+
include Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
|
|
544
277
|
end
|