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
|
@@ -2,27 +2,57 @@ require 'tempfile'
|
|
|
2
2
|
require 'stringio'
|
|
3
3
|
require 'minitest/autorun'
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class Minitest::Test
|
|
6
6
|
def clean s
|
|
7
7
|
s.gsub(/^ {6}/, '')
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
class MetaMetaMetaTestCase <
|
|
11
|
+
class MetaMetaMetaTestCase < Minitest::Test
|
|
12
|
+
attr_accessor :reporter, :output, :tu
|
|
13
|
+
|
|
14
|
+
def run_tu_with_fresh_reporter flags = %w[--seed 42]
|
|
15
|
+
options = Minitest.process_args flags
|
|
16
|
+
|
|
17
|
+
@output = StringIO.new("")
|
|
18
|
+
|
|
19
|
+
self.reporter = Minitest::CompositeReporter.new
|
|
20
|
+
reporter << Minitest::SummaryReporter.new(@output, options)
|
|
21
|
+
reporter << Minitest::ProgressReporter.new(@output, options)
|
|
22
|
+
|
|
23
|
+
reporter.start
|
|
24
|
+
|
|
25
|
+
@tus ||= [@tu]
|
|
26
|
+
@tus.each do |tu|
|
|
27
|
+
Minitest::Runnable.runnables.delete tu
|
|
28
|
+
|
|
29
|
+
tu.run reporter, options
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
reporter.report
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def first_reporter
|
|
36
|
+
reporter.reporters.first
|
|
37
|
+
end
|
|
38
|
+
|
|
12
39
|
def assert_report expected, flags = %w[--seed 42]
|
|
13
40
|
header = clean <<-EOM
|
|
14
41
|
Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}
|
|
15
42
|
|
|
16
|
-
# Running
|
|
43
|
+
# Running:
|
|
17
44
|
|
|
18
45
|
EOM
|
|
19
46
|
|
|
20
|
-
|
|
21
|
-
@tu.run flags
|
|
22
|
-
end
|
|
47
|
+
run_tu_with_fresh_reporter flags
|
|
23
48
|
|
|
24
|
-
output = @output.string.dup
|
|
25
|
-
|
|
49
|
+
output = normalize_output @output.string.dup
|
|
50
|
+
|
|
51
|
+
assert_equal header + expected, output
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def normalize_output output
|
|
55
|
+
output.sub!(/Finished in .*/, "Finished in 0.00")
|
|
26
56
|
output.sub!(/Loaded suite .*/, 'Loaded suite blah')
|
|
27
57
|
|
|
28
58
|
output.gsub!(/ = \d+.\d\d s = /, ' = 0.00 s = ')
|
|
@@ -36,32 +66,13 @@ class MetaMetaMetaTestCase < MiniTest::Unit::TestCase
|
|
|
36
66
|
output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
|
|
37
67
|
end
|
|
38
68
|
|
|
39
|
-
|
|
69
|
+
output
|
|
40
70
|
end
|
|
41
71
|
|
|
42
72
|
def setup
|
|
43
73
|
super
|
|
44
74
|
srand 42
|
|
45
|
-
|
|
46
|
-
@tu =
|
|
47
|
-
|
|
48
|
-
MiniTest::Unit.runner = nil # protect the outer runner from the inner tests
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def teardown
|
|
52
|
-
super
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def with_output
|
|
56
|
-
synchronize do
|
|
57
|
-
begin
|
|
58
|
-
@output = StringIO.new("")
|
|
59
|
-
MiniTest::Unit.output = @output
|
|
60
|
-
|
|
61
|
-
yield
|
|
62
|
-
ensure
|
|
63
|
-
MiniTest::Unit.output = STDOUT
|
|
64
|
-
end
|
|
65
|
-
end
|
|
75
|
+
Minitest::Test.reset
|
|
76
|
+
@tu = nil
|
|
66
77
|
end
|
|
67
78
|
end
|
|
@@ -5,28 +5,28 @@ require 'minitest/benchmark'
|
|
|
5
5
|
# Used to verify data:
|
|
6
6
|
# http://www.wolframalpha.com/examples/RegressionAnalysis.html
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class TestMinitestBenchmark < Minitest::Test
|
|
9
9
|
def test_cls_bench_exp
|
|
10
|
-
assert_equal [2, 4, 8, 16, 32],
|
|
10
|
+
assert_equal [2, 4, 8, 16, 32], Minitest::Benchmark.bench_exp(2, 32, 2)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def test_cls_bench_linear
|
|
14
|
-
assert_equal [2, 4, 6, 8, 10],
|
|
14
|
+
assert_equal [2, 4, 6, 8, 10], Minitest::Benchmark.bench_linear(2, 10, 2)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def
|
|
18
|
-
assert_equal [],
|
|
17
|
+
def test_cls_runnable_methods
|
|
18
|
+
assert_equal [], Minitest::Benchmark.runnable_methods
|
|
19
19
|
|
|
20
|
-
c = Class.new(
|
|
20
|
+
c = Class.new(Minitest::Benchmark) do
|
|
21
21
|
def bench_blah
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
assert_equal ["bench_blah"], c.
|
|
25
|
+
assert_equal ["bench_blah"], c.runnable_methods
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def test_cls_bench_range
|
|
29
|
-
assert_equal [1, 10, 100, 1_000, 10_000],
|
|
29
|
+
assert_equal [1, 10, 100, 1_000, 10_000], Minitest::Benchmark.bench_range
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def test_fit_exponential_clean
|
|
@@ -119,7 +119,9 @@ class TestMiniTestBenchmark < MiniTest::Unit::TestCase
|
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
def assert_fit msg, x, y, fit, exp_a, exp_b
|
|
122
|
-
|
|
122
|
+
bench = Minitest::Benchmark.new :blah
|
|
123
|
+
|
|
124
|
+
a, b, rr = bench.send "fit_#{msg}", x, y
|
|
123
125
|
|
|
124
126
|
assert_operator rr, :>=, fit if fit
|
|
125
127
|
assert_in_delta exp_a, a
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'minitest/autorun'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class TestMinitestMock < Minitest::Test
|
|
4
4
|
parallelize_me!
|
|
5
5
|
|
|
6
6
|
def setup
|
|
7
|
-
@mock =
|
|
7
|
+
@mock = Minitest::Mock.new.expect(:foo, nil)
|
|
8
8
|
@mock.expect(:meaning_of_life, 42)
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -55,8 +55,8 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def test_return_mock_does_not_raise
|
|
58
|
-
retval =
|
|
59
|
-
mock =
|
|
58
|
+
retval = Minitest::Mock.new
|
|
59
|
+
mock = Minitest::Mock.new
|
|
60
60
|
mock.expect(:foo, retval)
|
|
61
61
|
mock.foo
|
|
62
62
|
|
|
@@ -66,14 +66,57 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
66
66
|
def test_mock_args_does_not_raise
|
|
67
67
|
skip "non-opaque use of ==" if maglev?
|
|
68
68
|
|
|
69
|
-
arg =
|
|
70
|
-
mock =
|
|
69
|
+
arg = Minitest::Mock.new
|
|
70
|
+
mock = Minitest::Mock.new
|
|
71
71
|
mock.expect(:foo, nil, [arg])
|
|
72
72
|
mock.foo(arg)
|
|
73
73
|
|
|
74
74
|
assert mock.verify
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
def test_set_expectation_on_special_methods
|
|
78
|
+
mock = Minitest::Mock.new
|
|
79
|
+
|
|
80
|
+
mock.expect :object_id, "received object_id"
|
|
81
|
+
assert_equal "received object_id", mock.object_id
|
|
82
|
+
|
|
83
|
+
mock.expect :respond_to_missing?, "received respond_to_missing?"
|
|
84
|
+
assert_equal "received respond_to_missing?", mock.respond_to_missing?
|
|
85
|
+
|
|
86
|
+
mock.expect :===, "received ==="
|
|
87
|
+
assert_equal "received ===", mock.===
|
|
88
|
+
|
|
89
|
+
mock.expect :inspect, "received inspect"
|
|
90
|
+
assert_equal "received inspect", mock.inspect
|
|
91
|
+
|
|
92
|
+
mock.expect :to_s, "received to_s"
|
|
93
|
+
assert_equal "received to_s", mock.to_s
|
|
94
|
+
|
|
95
|
+
mock.expect :public_send, "received public_send"
|
|
96
|
+
assert_equal "received public_send", mock.public_send
|
|
97
|
+
|
|
98
|
+
mock.expect :send, "received send"
|
|
99
|
+
assert_equal "received send", mock.send
|
|
100
|
+
|
|
101
|
+
assert mock.verify
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_expectations_can_be_satisfied_via_send
|
|
105
|
+
@mock.send :foo
|
|
106
|
+
@mock.send :meaning_of_life
|
|
107
|
+
|
|
108
|
+
assert @mock.verify
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_expectations_can_be_satisfied_via_public_send
|
|
112
|
+
skip "Doesn't run on 1.8" if RUBY_VERSION < "1.9"
|
|
113
|
+
|
|
114
|
+
@mock.public_send :foo
|
|
115
|
+
@mock.public_send :meaning_of_life
|
|
116
|
+
|
|
117
|
+
assert @mock.verify
|
|
118
|
+
end
|
|
119
|
+
|
|
77
120
|
def test_blow_up_on_wrong_arguments
|
|
78
121
|
@mock.foo
|
|
79
122
|
@mock.meaning_of_life
|
|
@@ -113,8 +156,8 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
113
156
|
end
|
|
114
157
|
|
|
115
158
|
def test_assign_per_mock_return_values
|
|
116
|
-
a =
|
|
117
|
-
b =
|
|
159
|
+
a = Minitest::Mock.new
|
|
160
|
+
b = Minitest::Mock.new
|
|
118
161
|
|
|
119
162
|
a.expect(:foo, :a)
|
|
120
163
|
b.expect(:foo, :b)
|
|
@@ -124,10 +167,10 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
124
167
|
end
|
|
125
168
|
|
|
126
169
|
def test_do_not_create_stub_method_on_new_mocks
|
|
127
|
-
a =
|
|
170
|
+
a = Minitest::Mock.new
|
|
128
171
|
a.expect(:foo, :a)
|
|
129
172
|
|
|
130
|
-
assert !
|
|
173
|
+
assert !Minitest::Mock.new.respond_to?(:foo)
|
|
131
174
|
end
|
|
132
175
|
|
|
133
176
|
def test_mock_is_a_blank_slate
|
|
@@ -139,7 +182,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
139
182
|
end
|
|
140
183
|
|
|
141
184
|
def test_verify_allows_called_args_to_be_loosely_specified
|
|
142
|
-
mock =
|
|
185
|
+
mock = Minitest::Mock.new
|
|
143
186
|
mock.expect :loose_expectation, true, [Integer]
|
|
144
187
|
mock.loose_expectation 1
|
|
145
188
|
|
|
@@ -147,7 +190,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
147
190
|
end
|
|
148
191
|
|
|
149
192
|
def test_verify_raises_with_strict_args
|
|
150
|
-
mock =
|
|
193
|
+
mock = Minitest::Mock.new
|
|
151
194
|
mock.expect :strict_expectation, true, [2]
|
|
152
195
|
|
|
153
196
|
e = assert_raises MockExpectationError do
|
|
@@ -159,7 +202,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
159
202
|
end
|
|
160
203
|
|
|
161
204
|
def test_method_missing_empty
|
|
162
|
-
mock =
|
|
205
|
+
mock = Minitest::Mock.new
|
|
163
206
|
|
|
164
207
|
mock.expect :a, nil
|
|
165
208
|
|
|
@@ -173,7 +216,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
173
216
|
end
|
|
174
217
|
|
|
175
218
|
def test_same_method_expects_are_verified_when_all_called
|
|
176
|
-
mock =
|
|
219
|
+
mock = Minitest::Mock.new
|
|
177
220
|
mock.expect :foo, nil, [:bar]
|
|
178
221
|
mock.expect :foo, nil, [:baz]
|
|
179
222
|
|
|
@@ -184,7 +227,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
184
227
|
end
|
|
185
228
|
|
|
186
229
|
def test_same_method_expects_blow_up_when_not_all_called
|
|
187
|
-
mock =
|
|
230
|
+
mock = Minitest::Mock.new
|
|
188
231
|
mock.expect :foo, nil, [:bar]
|
|
189
232
|
mock.expect :foo, nil, [:baz]
|
|
190
233
|
|
|
@@ -198,7 +241,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
198
241
|
end
|
|
199
242
|
|
|
200
243
|
def test_verify_passes_when_mock_block_returns_true
|
|
201
|
-
mock =
|
|
244
|
+
mock = Minitest::Mock.new
|
|
202
245
|
mock.expect :foo, nil do
|
|
203
246
|
true
|
|
204
247
|
end
|
|
@@ -210,7 +253,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
210
253
|
|
|
211
254
|
def test_mock_block_is_passed_function_params
|
|
212
255
|
arg1, arg2, arg3 = :bar, [1,2,3], {:a => 'a'}
|
|
213
|
-
mock =
|
|
256
|
+
mock = Minitest::Mock.new
|
|
214
257
|
mock.expect :foo, nil do |a1, a2, a3|
|
|
215
258
|
a1 == arg1 &&
|
|
216
259
|
a2 == arg2 &&
|
|
@@ -223,7 +266,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
223
266
|
end
|
|
224
267
|
|
|
225
268
|
def test_verify_fails_when_mock_block_returns_false
|
|
226
|
-
mock =
|
|
269
|
+
mock = Minitest::Mock.new
|
|
227
270
|
mock.expect :foo, nil do
|
|
228
271
|
false
|
|
229
272
|
end
|
|
@@ -235,7 +278,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
235
278
|
end
|
|
236
279
|
|
|
237
280
|
def test_mock_block_throws_if_args_passed
|
|
238
|
-
mock =
|
|
281
|
+
mock = Minitest::Mock.new
|
|
239
282
|
|
|
240
283
|
e = assert_raises(ArgumentError) do
|
|
241
284
|
mock.expect :foo, nil, [:a, :b, :c] do
|
|
@@ -249,7 +292,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
249
292
|
end
|
|
250
293
|
|
|
251
294
|
def test_mock_returns_retval_when_called_with_block
|
|
252
|
-
mock =
|
|
295
|
+
mock = Minitest::Mock.new
|
|
253
296
|
mock.expect(:foo, 32) do
|
|
254
297
|
true
|
|
255
298
|
end
|
|
@@ -266,24 +309,49 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
|
266
309
|
|
|
267
310
|
assert_equal exp, e.message
|
|
268
311
|
end
|
|
312
|
+
|
|
313
|
+
def test_mock_called_via_send
|
|
314
|
+
mock = Minitest::Mock.new
|
|
315
|
+
mock.expect(:foo, true)
|
|
316
|
+
|
|
317
|
+
mock.send :foo
|
|
318
|
+
mock.verify
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def test_mock_called_via___send__
|
|
322
|
+
mock = Minitest::Mock.new
|
|
323
|
+
mock.expect(:foo, true)
|
|
324
|
+
|
|
325
|
+
mock.__send__ :foo
|
|
326
|
+
mock.verify
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def test_mock_called_via_send_with_args
|
|
330
|
+
mock = Minitest::Mock.new
|
|
331
|
+
mock.expect(:foo, true, [1,2,3])
|
|
332
|
+
|
|
333
|
+
mock.send(:foo, 1, 2, 3)
|
|
334
|
+
mock.verify
|
|
335
|
+
end
|
|
336
|
+
|
|
269
337
|
end
|
|
270
338
|
|
|
271
339
|
require "minitest/metametameta"
|
|
272
340
|
|
|
273
|
-
class
|
|
341
|
+
class TestMinitestStub < Minitest::Test
|
|
274
342
|
parallelize_me!
|
|
275
343
|
|
|
276
344
|
def setup
|
|
277
345
|
super
|
|
278
|
-
|
|
346
|
+
Minitest::Test.reset
|
|
279
347
|
|
|
280
|
-
@tc =
|
|
348
|
+
@tc = Minitest::Test.new 'fake tc'
|
|
281
349
|
@assertion_count = 1
|
|
282
350
|
end
|
|
283
351
|
|
|
284
352
|
def teardown
|
|
285
353
|
super
|
|
286
|
-
assert_equal @assertion_count, @tc.
|
|
354
|
+
assert_equal @assertion_count, @tc.assertions
|
|
287
355
|
end
|
|
288
356
|
|
|
289
357
|
class Time
|
|
@@ -319,22 +387,22 @@ class TestMiniTestStub < MiniTest::Unit::TestCase
|
|
|
319
387
|
def test_stub_private_module_method_indirect
|
|
320
388
|
@assertion_count += 1
|
|
321
389
|
|
|
322
|
-
|
|
323
|
-
def
|
|
324
|
-
|
|
390
|
+
fail_clapper = Class.new do
|
|
391
|
+
def fail_clap
|
|
392
|
+
fail
|
|
325
393
|
:clap
|
|
326
394
|
end
|
|
327
395
|
end.new
|
|
328
396
|
|
|
329
|
-
|
|
330
|
-
@tc.assert_equal :clap,
|
|
331
|
-
@tc.assert_equal :clap,
|
|
397
|
+
fail_clapper.stub :fail, nil do |safe_clapper|
|
|
398
|
+
@tc.assert_equal :clap, safe_clapper.fail_clap # either form works
|
|
399
|
+
@tc.assert_equal :clap, fail_clapper.fail_clap # yay closures
|
|
332
400
|
end
|
|
333
401
|
end
|
|
334
402
|
|
|
335
403
|
def test_stub_public_module_method
|
|
336
|
-
Math.stub
|
|
337
|
-
@tc.
|
|
404
|
+
Math.stub :log10, :stubbed do
|
|
405
|
+
@tc.assert_equal :stubbed, Math.log10(1000)
|
|
338
406
|
end
|
|
339
407
|
end
|
|
340
408
|
|
|
@@ -402,4 +470,20 @@ class TestMiniTestStub < MiniTest::Unit::TestCase
|
|
|
402
470
|
@tc.assert_equal true, val
|
|
403
471
|
@tc.assert_equal false, dynamic.found
|
|
404
472
|
end
|
|
473
|
+
|
|
474
|
+
def test_mock_with_yield
|
|
475
|
+
mock = Minitest::Mock.new
|
|
476
|
+
mock.expect(:write, true) do
|
|
477
|
+
true
|
|
478
|
+
end
|
|
479
|
+
rs = nil
|
|
480
|
+
|
|
481
|
+
File.stub(:open, true, mock) do
|
|
482
|
+
File.open("foo.txt", "r") do |f|
|
|
483
|
+
rs = f.write
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
@tc.assert_equal true, rs
|
|
487
|
+
end
|
|
488
|
+
|
|
405
489
|
end
|