mega-sharp-tool 0.0.1

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/mega-sharp-tool.gemspec +12 -0
  3. data/minitest-6.0.6/History.rdoc +1860 -0
  4. data/minitest-6.0.6/Manifest.txt +41 -0
  5. data/minitest-6.0.6/README.rdoc +763 -0
  6. data/minitest-6.0.6/Rakefile +89 -0
  7. data/minitest-6.0.6/bin/minitest +5 -0
  8. data/minitest-6.0.6/design_rationale.rb +54 -0
  9. data/minitest-6.0.6/lib/hoe/minitest.rb +30 -0
  10. data/minitest-6.0.6/lib/minitest/assertions.rb +821 -0
  11. data/minitest-6.0.6/lib/minitest/autorun.rb +5 -0
  12. data/minitest-6.0.6/lib/minitest/benchmark.rb +452 -0
  13. data/minitest-6.0.6/lib/minitest/bisect.rb +304 -0
  14. data/minitest-6.0.6/lib/minitest/complete.rb +56 -0
  15. data/minitest-6.0.6/lib/minitest/compress.rb +94 -0
  16. data/minitest-6.0.6/lib/minitest/error_on_warning.rb +11 -0
  17. data/minitest-6.0.6/lib/minitest/expectations.rb +321 -0
  18. data/minitest-6.0.6/lib/minitest/find_minimal_combination.rb +127 -0
  19. data/minitest-6.0.6/lib/minitest/hell.rb +11 -0
  20. data/minitest-6.0.6/lib/minitest/manual_plugins.rb +4 -0
  21. data/minitest-6.0.6/lib/minitest/parallel.rb +72 -0
  22. data/minitest-6.0.6/lib/minitest/path_expander.rb +432 -0
  23. data/minitest-6.0.6/lib/minitest/pride.rb +4 -0
  24. data/minitest-6.0.6/lib/minitest/pride_plugin.rb +135 -0
  25. data/minitest-6.0.6/lib/minitest/server.rb +49 -0
  26. data/minitest-6.0.6/lib/minitest/server_plugin.rb +88 -0
  27. data/minitest-6.0.6/lib/minitest/spec.rb +324 -0
  28. data/minitest-6.0.6/lib/minitest/sprint.rb +105 -0
  29. data/minitest-6.0.6/lib/minitest/sprint_plugin.rb +39 -0
  30. data/minitest-6.0.6/lib/minitest/test.rb +232 -0
  31. data/minitest-6.0.6/lib/minitest/test_task.rb +331 -0
  32. data/minitest-6.0.6/lib/minitest.rb +1232 -0
  33. data/minitest-6.0.6/test/minitest/metametameta.rb +150 -0
  34. data/minitest-6.0.6/test/minitest/test_bisect.rb +249 -0
  35. data/minitest-6.0.6/test/minitest/test_find_minimal_combination.rb +138 -0
  36. data/minitest-6.0.6/test/minitest/test_minitest_assertions.rb +1729 -0
  37. data/minitest-6.0.6/test/minitest/test_minitest_benchmark.rb +151 -0
  38. data/minitest-6.0.6/test/minitest/test_minitest_reporter.rb +437 -0
  39. data/minitest-6.0.6/test/minitest/test_minitest_spec.rb +1095 -0
  40. data/minitest-6.0.6/test/minitest/test_minitest_test.rb +1295 -0
  41. data/minitest-6.0.6/test/minitest/test_minitest_test_task.rb +57 -0
  42. data/minitest-6.0.6/test/minitest/test_path_expander.rb +229 -0
  43. data/minitest-6.0.6/test/minitest/test_server.rb +146 -0
  44. metadata +83 -0
@@ -0,0 +1,1095 @@
1
+ require_relative "metametameta"
2
+ require "stringio"
3
+
4
+ class MiniSpecA < Minitest::Spec; end
5
+ class MiniSpecB < Minitest::Test; extend Minitest::Spec::DSL; end
6
+ class MiniSpecC < MiniSpecB; end
7
+ class NamedExampleA < MiniSpecA; end
8
+ class NamedExampleB < MiniSpecB; end
9
+ class NamedExampleC < MiniSpecC; end
10
+ class ExampleA; end
11
+ class ExampleB < ExampleA; end
12
+
13
+ describe Minitest::Spec do
14
+ # do not parallelize this suite... it just can"t handle it.
15
+
16
+ def assert_triggered expected = "blah", klass = Minitest::Assertion
17
+ @assertion_count += 1
18
+
19
+ e = assert_raises klass do
20
+ yield
21
+ end
22
+
23
+ msg = e.message.sub(/(---Backtrace---).*/m, '\1')
24
+ msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
25
+ msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
26
+ msg.gsub!(/:0x[Xa-fA-F0-9]{4,}[ @].+?>/, ":0xXXXXXX@PATH>")
27
+
28
+ return unless expected
29
+
30
+ @assertion_count += 1
31
+ case expected
32
+ when String then
33
+ assert_equal expected, msg
34
+ when Regexp then
35
+ @assertion_count += 1
36
+ assert_match expected, msg
37
+ else
38
+ flunk "Unknown: #{expected.inspect}"
39
+ end
40
+ end
41
+
42
+ def assert_success spec
43
+ assert_equal true, spec
44
+ end
45
+
46
+ before do
47
+ @assertion_count = 4
48
+ end
49
+
50
+ after do
51
+ _(self.assertions).must_equal @assertion_count if passed? and not skipped?
52
+ end
53
+
54
+ it "needs to be able to catch a Minitest::Assertion exception" do
55
+ @assertion_count = 1
56
+
57
+ assert_triggered "Expected 1 to not be equal to 1." do
58
+ _(1).wont_equal 1
59
+ end
60
+ end
61
+
62
+ it "needs to check for file existence" do
63
+ @assertion_count = 3
64
+
65
+ assert_success _(__FILE__).path_must_exist
66
+
67
+ assert_triggered "Expected path 'blah' to exist." do
68
+ _("blah").path_must_exist
69
+ end
70
+ end
71
+
72
+ it "needs to check for file non-existence" do
73
+ @assertion_count = 3
74
+
75
+ assert_success _("blah").path_wont_exist
76
+
77
+ assert_triggered "Expected path '#{__FILE__}' to not exist." do
78
+ _(__FILE__).path_wont_exist
79
+ end
80
+ end
81
+
82
+ it "needs to be sensible about must_include order" do
83
+ @assertion_count += 3 # must_include is 2 assertions
84
+
85
+ assert_success _([1, 2, 3]).must_include(2)
86
+
87
+ assert_triggered "Expected [1, 2, 3] to include 5." do
88
+ _([1, 2, 3]).must_include 5
89
+ end
90
+
91
+ assert_triggered "msg.\nExpected [1, 2, 3] to include 5." do
92
+ _([1, 2, 3]).must_include 5, "msg"
93
+ end
94
+ end
95
+
96
+ it "needs to be sensible about wont_include order" do
97
+ @assertion_count += 3 # wont_include is 2 assertions
98
+
99
+ assert_success _([1, 2, 3]).wont_include(5)
100
+
101
+ assert_triggered "Expected [1, 2, 3] to not include 2." do
102
+ _([1, 2, 3]).wont_include 2
103
+ end
104
+
105
+ assert_triggered "msg.\nExpected [1, 2, 3] to not include 2." do
106
+ _([1, 2, 3]).wont_include 2, "msg"
107
+ end
108
+ end
109
+
110
+ it "needs to catch an expected exception" do
111
+ @assertion_count -= 2
112
+
113
+ expect { raise "blah" }.must_raise RuntimeError
114
+ expect { raise Minitest::Assertion }.must_raise Minitest::Assertion
115
+ end
116
+
117
+ it "needs to catch an unexpected exception" do
118
+ @assertion_count -= 2 # no positive
119
+
120
+ msg = <<-EOM.gsub(/^ {6}/, "").chomp
121
+ [RuntimeError] exception expected, not
122
+ Class: <StandardError>
123
+ Message: <"woot">
124
+ ---Backtrace---
125
+ EOM
126
+
127
+ assert_triggered msg do
128
+ expect { raise StandardError, "woot" }.must_raise RuntimeError
129
+ end
130
+
131
+ assert_triggered "msg.\n#{msg}" do
132
+ expect { raise StandardError, "woot" }.must_raise RuntimeError, "msg"
133
+ end
134
+ end
135
+
136
+ def good_pattern
137
+ capture_io do # 3.0 is noisy
138
+ eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
139
+ end
140
+ end
141
+
142
+ def bad_pattern
143
+ capture_io do # 3.0 is noisy
144
+ eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
145
+ end
146
+ end
147
+
148
+ it "needs to pattern match" do
149
+ @assertion_count = 1
150
+
151
+ expect { good_pattern }.must_pattern_match
152
+ end
153
+
154
+ it "needs to error on bad pattern match" do
155
+ @assertion_count = 1
156
+
157
+ exp = /length mismatch/
158
+
159
+ assert_triggered exp do
160
+ expect { bad_pattern }.must_pattern_match
161
+ end
162
+ end
163
+
164
+ it "needs to ensure silence" do
165
+ @assertion_count -= 1 # no msg
166
+ @assertion_count += 2 # assert_output is 2 assertions
167
+
168
+ assert_success expect {}.must_be_silent
169
+
170
+ assert_triggered "In stdout.\nExpected: \"\"\n Actual: \"xxx\"" do
171
+ expect { print "xxx" }.must_be_silent
172
+ end
173
+ end
174
+
175
+ it "needs to have all methods named well" do
176
+ skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
177
+
178
+ @assertion_count = 2
179
+
180
+ methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
181
+ methods.map!(&:to_s) if Symbol === methods.first
182
+
183
+ musts, wonts = methods.sort.partition { |m| m.include? "must" }
184
+
185
+ expected_musts = %w[must_be
186
+ must_be_close_to
187
+ must_be_empty
188
+ must_be_instance_of
189
+ must_be_kind_of
190
+ must_be_nil
191
+ must_be_same_as
192
+ must_be_silent
193
+ must_be_within_delta
194
+ must_be_within_epsilon
195
+ must_equal
196
+ must_include
197
+ must_match
198
+ must_output
199
+ must_pattern_match
200
+ must_raise
201
+ must_respond_to
202
+ must_throw
203
+ path_must_exist]
204
+
205
+ bad = %w[not raise throw send output be_silent verify]
206
+
207
+ if methods.include? "must_infect" then # from test_minitest_mock.rb
208
+ expected_musts += %w[must_infect must_infect_without_flipping]
209
+ expected_musts.sort!
210
+ bad << "infect"
211
+ end
212
+
213
+ expected_wonts = expected_musts.map { |m| m.sub("must", "wont") }.sort
214
+ expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
215
+
216
+ _(musts).must_equal expected_musts
217
+ _(wonts).must_equal expected_wonts
218
+ end
219
+
220
+ it "needs to raise if an expected exception is not raised" do
221
+ @assertion_count -= 2 # no positive test
222
+
223
+ assert_triggered "RuntimeError expected but nothing was raised." do
224
+ expect { 42 }.must_raise RuntimeError
225
+ end
226
+
227
+ assert_triggered "msg.\nRuntimeError expected but nothing was raised." do
228
+ expect { 42 }.must_raise RuntimeError, "msg"
229
+ end
230
+ end
231
+
232
+ it "needs to verify binary messages" do
233
+ @assertion_count += 3
234
+
235
+ assert_success _(42).wont_be(:<, 24)
236
+
237
+ assert_triggered "Expected 24 to not be < 42." do
238
+ _(24).wont_be :<, 42
239
+ end
240
+
241
+ assert_triggered "msg.\nExpected 24 to not be < 42." do
242
+ _(24).wont_be :<, 42, "msg"
243
+ end
244
+ end
245
+
246
+ it "needs to verify emptyness" do
247
+ @assertion_count += 3 # empty is 2 assertions
248
+
249
+ assert_success _([]).must_be_empty
250
+
251
+ assert_triggered "Expected [42] to be empty." do
252
+ _([42]).must_be_empty
253
+ end
254
+
255
+ assert_triggered "msg.\nExpected [42] to be empty." do
256
+ _([42]).must_be_empty "msg"
257
+ end
258
+ end
259
+
260
+ it "needs to verify equality" do
261
+ @assertion_count += 1
262
+
263
+ assert_success _(6 * 7).must_equal(42)
264
+
265
+ assert_triggered "Expected: 42\n Actual: 54" do
266
+ _(6 * 9).must_equal 42
267
+ end
268
+
269
+ assert_triggered "msg.\nExpected: 42\n Actual: 54" do
270
+ _(6 * 9).must_equal 42, "msg"
271
+ end
272
+
273
+ assert_triggered(/^-42\n\+#<Proc:0xXXXXXX[ @]PATH>\n/) do
274
+ _(proc { 42 }).must_equal 42 # proc isn't called, so expectation fails
275
+ end
276
+ end
277
+
278
+ it "needs to fail on equality with nil" do
279
+ @assertion_count -= 2
280
+ expect { _(nil).must_equal(nil) }.must_raise Minitest::Assertion
281
+ end
282
+
283
+ it "needs to verify floats outside a delta" do
284
+ @assertion_count += 1 # extra test
285
+
286
+ assert_success _(24).wont_be_close_to(42)
287
+
288
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.001." do
289
+ _(6 * 7.0).wont_be_close_to 42
290
+ end
291
+
292
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 1.0e-05." do
293
+ _(6 * 7.0).wont_be_close_to 42, 0.00001
294
+ end
295
+
296
+ assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= 1.0e-05." do
297
+ _(6 * 7.0).wont_be_close_to 42, 0.00001, "msg"
298
+ end
299
+ end
300
+
301
+ it "needs to verify floats outside an epsilon" do
302
+ @assertion_count += 1 # extra test
303
+
304
+ assert_success _(24).wont_be_within_epsilon(42)
305
+
306
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.042." do
307
+ _(6 * 7.0).wont_be_within_epsilon 42
308
+ end
309
+
310
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.00042." do
311
+ _(6 * 7.0).wont_be_within_epsilon 42, 0.00001
312
+ end
313
+
314
+ assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= 0.00042." do
315
+ _(6 * 7.0).wont_be_within_epsilon 42, 0.00001, "msg"
316
+ end
317
+ end
318
+
319
+ it "needs to verify floats within a delta" do
320
+ @assertion_count += 1 # extra test
321
+
322
+ assert_success _(6.0 * 7).must_be_close_to(42.0)
323
+
324
+ assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.001." do
325
+ _(1.0 / 100).must_be_close_to 0.0
326
+ end
327
+
328
+ assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= 1.0e-06." do
329
+ _(1.0 / 1000).must_be_close_to 0.0, 0.000001
330
+ end
331
+
332
+ assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= 1.0e-06." do
333
+ _(1.0 / 1000).must_be_close_to 0.0, 0.000001, "msg"
334
+ end
335
+ end
336
+
337
+ it "needs to verify floats within an epsilon" do
338
+ @assertion_count += 1 # extra test
339
+
340
+ assert_success _(6.0 * 7).must_be_within_epsilon(42.0)
341
+
342
+ assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.0." do
343
+ _(1.0 / 100).must_be_within_epsilon 0.0
344
+ end
345
+
346
+ assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= 0.0." do
347
+ _(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001
348
+ end
349
+
350
+ assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= 0.0." do
351
+ _(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001, "msg"
352
+ end
353
+ end
354
+
355
+ it "needs to verify identity" do
356
+ assert_success _(1).must_be_same_as(1)
357
+
358
+ assert_triggered "Expected 1 (oid=N) to be the same as 2 (oid=N)." do
359
+ _(1).must_be_same_as 2
360
+ end
361
+
362
+ assert_triggered "msg.\nExpected 1 (oid=N) to be the same as 2 (oid=N)." do
363
+ _(1).must_be_same_as 2, "msg"
364
+ end
365
+ end
366
+
367
+ it "needs to verify inequality" do
368
+ @assertion_count += 2
369
+ assert_success _(42).wont_equal(6 * 9)
370
+ assert_success _(proc {}).wont_equal(42)
371
+
372
+ assert_triggered "Expected 1 to not be equal to 1." do
373
+ _(1).wont_equal 1
374
+ end
375
+
376
+ assert_triggered "msg.\nExpected 1 to not be equal to 1." do
377
+ _(1).wont_equal 1, "msg"
378
+ end
379
+ end
380
+
381
+ it "needs to verify instances of a class" do
382
+ assert_success _(42).wont_be_instance_of(String)
383
+
384
+ assert_triggered "Expected 42 to not be a kind of Integer." do
385
+ _(42).wont_be_kind_of Integer
386
+ end
387
+
388
+ assert_triggered "msg.\nExpected 42 to not be an instance of Integer." do
389
+ _(42).wont_be_instance_of Integer, "msg"
390
+ end
391
+ end
392
+
393
+ it "needs to verify kinds of a class" do
394
+ @assertion_count += 2
395
+
396
+ assert_success _(42).wont_be_kind_of(String)
397
+ assert_success _(proc {}).wont_be_kind_of(String)
398
+
399
+ assert_triggered "Expected 42 to not be a kind of Integer." do
400
+ _(42).wont_be_kind_of Integer
401
+ end
402
+
403
+ assert_triggered "msg.\nExpected 42 to not be a kind of Integer." do
404
+ _(42).wont_be_kind_of Integer, "msg"
405
+ end
406
+ end
407
+
408
+ it "needs to verify kinds of objects" do
409
+ @assertion_count += 3 # extra test
410
+
411
+ assert_success _(6 * 7).must_be_kind_of(Integer)
412
+ assert_success _(6 * 7).must_be_kind_of(Numeric)
413
+
414
+ assert_triggered "Expected 42 to be a kind of String, not Integer." do
415
+ _(6 * 7).must_be_kind_of String
416
+ end
417
+
418
+ assert_triggered "msg.\nExpected 42 to be a kind of String, not Integer." do
419
+ _(6 * 7).must_be_kind_of String, "msg"
420
+ end
421
+
422
+ exp = "Expected #<Proc:0xXXXXXX@PATH> to be a kind of String, not Proc."
423
+ assert_triggered exp do
424
+ _(proc {}).must_be_kind_of String
425
+ end
426
+ end
427
+
428
+ it "needs to verify mismatch" do
429
+ @assertion_count += 3 # match is 2
430
+
431
+ assert_success _("blah").wont_match(/\d+/)
432
+
433
+ assert_triggered "Expected /\\w+/ to not match \"blah\"." do
434
+ _("blah").wont_match(/\w+/)
435
+ end
436
+
437
+ assert_triggered "msg.\nExpected /\\w+/ to not match \"blah\"." do
438
+ _("blah").wont_match(/\w+/, "msg")
439
+ end
440
+ end
441
+
442
+ it "needs to verify nil" do
443
+ assert_success _(nil).must_be_nil
444
+
445
+ assert_triggered "Expected 42 to be nil." do
446
+ _(42).must_be_nil
447
+ end
448
+
449
+ assert_triggered "msg.\nExpected 42 to be nil." do
450
+ _(42).must_be_nil "msg"
451
+ end
452
+ end
453
+
454
+ it "needs to verify non-emptyness" do
455
+ @assertion_count += 3 # empty is 2 assertions
456
+
457
+ assert_success _(["some item"]).wont_be_empty
458
+
459
+ assert_triggered "Expected [] to not be empty." do
460
+ _([]).wont_be_empty
461
+ end
462
+
463
+ assert_triggered "msg.\nExpected [] to not be empty." do
464
+ _([]).wont_be_empty "msg"
465
+ end
466
+ end
467
+
468
+ it "needs to verify non-identity" do
469
+ assert_success _(1).wont_be_same_as(2)
470
+
471
+ assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
472
+ _(1).wont_be_same_as 1
473
+ end
474
+
475
+ assert_triggered "msg.\nExpected 1 (oid=N) to not be the same as 1 (oid=N)." do
476
+ _(1).wont_be_same_as 1, "msg"
477
+ end
478
+ end
479
+
480
+ it "needs to verify non-nil" do
481
+ assert_success _(42).wont_be_nil
482
+
483
+ assert_triggered "Expected nil to not be nil." do
484
+ _(nil).wont_be_nil
485
+ end
486
+
487
+ assert_triggered "msg.\nExpected nil to not be nil." do
488
+ _(nil).wont_be_nil "msg"
489
+ end
490
+ end
491
+
492
+ it "needs to verify objects not responding to a message" do
493
+ assert_success _("").wont_respond_to(:woot!)
494
+
495
+ assert_triggered "Expected \"\" to not respond to to_s." do
496
+ _("").wont_respond_to :to_s
497
+ end
498
+
499
+ assert_triggered "msg.\nExpected \"\" to not respond to to_s." do
500
+ _("").wont_respond_to :to_s, "msg"
501
+ end
502
+ end
503
+
504
+ it "needs to verify output in stderr" do
505
+ @assertion_count -= 1 # no msg
506
+
507
+ assert_success expect { $stderr.print "blah" }.must_output(nil, "blah")
508
+
509
+ assert_triggered "In stderr.\nExpected: \"blah\"\n Actual: \"xxx\"" do
510
+ expect { $stderr.print "xxx" }.must_output(nil, "blah")
511
+ end
512
+ end
513
+
514
+ it "needs to verify output in stdout" do
515
+ @assertion_count -= 1 # no msg
516
+
517
+ assert_success expect { print "blah" }.must_output("blah")
518
+
519
+ assert_triggered "In stdout.\nExpected: \"blah\"\n Actual: \"xxx\"" do
520
+ expect { print "xxx" }.must_output("blah")
521
+ end
522
+ end
523
+
524
+ it "needs to verify regexp matches" do
525
+ @assertion_count += 3 # must_match is 2 assertions
526
+
527
+ assert_kind_of MatchData, _("blah").must_match(/\w+/)
528
+
529
+ assert_triggered "Expected /\\d+/ to match \"blah\"." do
530
+ _("blah").must_match(/\d+/)
531
+ end
532
+
533
+ assert_triggered "msg.\nExpected /\\d+/ to match \"blah\"." do
534
+ _("blah").must_match(/\d+/, "msg")
535
+ end
536
+ end
537
+
538
+ describe "expect" do
539
+ before do
540
+ @assertion_count -= 3
541
+ end
542
+
543
+ it "can use expect" do
544
+ _(1 + 1).must_equal 2
545
+ end
546
+
547
+ it "can use expect with a lambda" do
548
+ _ { raise "blah" }.must_raise RuntimeError
549
+ end
550
+
551
+ it "can use expect in a thread" do
552
+ Thread.new { _(1 + 1).must_equal 2 }.join
553
+ end
554
+ end
555
+
556
+ it "needs to verify throw" do
557
+ @assertion_count += 4 # 2 extra tests
558
+
559
+ assert_nil expect { throw :blah }.must_throw(:blah)
560
+ assert_equal 42, expect { throw :blah, 42 }.must_throw(:blah)
561
+
562
+ assert_triggered "Expected :blah to have been thrown." do
563
+ expect {}.must_throw :blah
564
+ end
565
+
566
+ assert_triggered "Expected :blah to have been thrown, not :xxx." do
567
+ expect { throw :xxx }.must_throw :blah
568
+ end
569
+
570
+ assert_triggered "msg.\nExpected :blah to have been thrown." do
571
+ expect {}.must_throw :blah, "msg"
572
+ end
573
+
574
+ assert_triggered "msg.\nExpected :blah to have been thrown, not :xxx." do
575
+ expect { throw :xxx }.must_throw :blah, "msg"
576
+ end
577
+ end
578
+
579
+ it "needs to verify types of objects" do
580
+ assert_success _(6 * 7).must_be_instance_of(Integer)
581
+
582
+ exp = "Expected 42 to be an instance of String, not Integer."
583
+
584
+ assert_triggered exp do
585
+ _(6 * 7).must_be_instance_of String
586
+ end
587
+
588
+ assert_triggered "msg.\n#{exp}" do
589
+ _(6 * 7).must_be_instance_of String, "msg"
590
+ end
591
+ end
592
+
593
+ it "needs to verify using any (negative) predicate" do
594
+ @assertion_count += 1
595
+
596
+ assert_success _("blah").wont_be(:empty?)
597
+
598
+ assert_triggered "Expected \"\" to not be empty?." do
599
+ _("").wont_be :empty?
600
+ end
601
+ end
602
+
603
+ it "needs to verify using any binary operator" do
604
+ @assertion_count += 1
605
+
606
+ assert_success _(41).must_be(:<, 42)
607
+
608
+ assert_triggered "Expected 42 to be < 41." do
609
+ _(42).must_be :<, 41
610
+ end
611
+ end
612
+
613
+ it "needs to verify using any predicate" do
614
+ @assertion_count += 1
615
+
616
+ assert_success _("").must_be(:empty?)
617
+
618
+ assert_triggered "Expected \"blah\" to be empty?." do
619
+ _("blah").must_be :empty?
620
+ end
621
+ end
622
+
623
+ it "needs to verify using respond_to" do
624
+ assert_success _(42).must_respond_to(:+)
625
+
626
+ assert_triggered "Expected 42 (Integer) to respond to #clear." do
627
+ _(42).must_respond_to :clear
628
+ end
629
+
630
+ assert_triggered "msg.\nExpected 42 (Integer) to respond to #clear." do
631
+ _(42).must_respond_to :clear, "msg"
632
+ end
633
+ end
634
+ end
635
+
636
+ describe Minitest::Spec, :let do
637
+ def _count
638
+ $let_count ||= 0
639
+ end
640
+
641
+ let :count do
642
+ $let_count += 1
643
+ $let_count
644
+ end
645
+
646
+ it "is evaluated once per example" do
647
+ exp = _count + 1
648
+
649
+ _(count).must_equal exp
650
+ _(count).must_equal exp
651
+
652
+ _(_count).must_equal exp
653
+ end
654
+
655
+ it "is REALLY evaluated once per example" do
656
+ exp = _count + 1
657
+
658
+ _(count).must_equal exp
659
+ _(count).must_equal exp
660
+
661
+ _(_count).must_equal exp
662
+ end
663
+
664
+ it 'raises an error if the name begins with "test"' do
665
+ expect { self.class.let(:test_value) { true } }.must_raise ArgumentError
666
+ end
667
+
668
+ it "raises an error if the name shadows a normal instance method" do
669
+ expect { self.class.let(:message) { true } }.must_raise ArgumentError
670
+ end
671
+
672
+ it "doesn't raise an error if it is just another let" do
673
+ v = proc do
674
+ describe :outer do
675
+ let :bar
676
+ describe :inner do
677
+ let :bar
678
+ end
679
+ end
680
+ :good
681
+ end.call
682
+ _(v).must_equal :good
683
+ end
684
+
685
+ it "procs come after dont_flip" do
686
+ p = proc {}
687
+ assert_respond_to p, :call
688
+ _(p).must_respond_to :call
689
+ end
690
+ end
691
+
692
+ describe Minitest::Spec, :subject do
693
+ attr_reader :subject_evaluation_count
694
+
695
+ subject do
696
+ @subject_evaluation_count ||= 0
697
+ @subject_evaluation_count += 1
698
+ @subject_evaluation_count
699
+ end
700
+
701
+ it "is evaluated once per example" do
702
+ _(subject).must_equal 1
703
+ _(subject).must_equal 1
704
+ _(subject_evaluation_count).must_equal 1
705
+ end
706
+ end
707
+
708
+ class TestMetaStatic < Minitest::Test
709
+ def assert_method_count expected, klass
710
+ assert_equal expected, klass.public_instance_methods.grep(/^test_/).count
711
+ end
712
+
713
+ def test_children
714
+ Minitest::Spec.children.clear # prevents parallel run
715
+
716
+ y = z = nil
717
+ x = describe "top-level thingy" do
718
+ y = describe "first thingy" do end
719
+
720
+ it "top-level-it" do end
721
+
722
+ z = describe "second thingy" do end
723
+ end
724
+
725
+ assert_equal [x], Minitest::Spec.children
726
+ assert_equal [y, z], x.children
727
+ assert_equal [], y.children
728
+ assert_equal [], z.children
729
+ end
730
+
731
+ def test_it_wont_remove_existing_child_test_methods
732
+ Minitest::Spec.children.clear # prevents parallel run
733
+
734
+ inner = nil
735
+ outer = describe "outer" do
736
+ inner = describe "inner" do
737
+ it do
738
+ assert true
739
+ end
740
+ end
741
+ it do
742
+ assert true
743
+ end
744
+ end
745
+
746
+ assert_method_count 1, outer
747
+ assert_method_count 1, inner
748
+ end
749
+
750
+ def test_it_wont_add_test_methods_to_children
751
+ Minitest::Spec.children.clear # prevents parallel run
752
+
753
+ inner = nil
754
+ outer = describe "outer" do
755
+ inner = describe "inner" do end
756
+ it do
757
+ assert true
758
+ end
759
+ end
760
+
761
+ assert_method_count 1, outer
762
+ assert_method_count 0, inner
763
+ end
764
+ end
765
+
766
+ class TestMeta < MetaMetaMetaTestCase
767
+ # do not call parallelize_me! here because specs use register_spec_type globally
768
+
769
+ def assert_defined_methods expected, klass
770
+ assert_equal expected, klass.instance_methods(false).sort.map(&:to_s)
771
+ end
772
+
773
+ def util_structure
774
+ y = z = nil
775
+ before_list = []
776
+ after_list = []
777
+ x = describe "top-level thingy" do
778
+ before { before_list << 1 }
779
+ after { after_list << 1 }
780
+
781
+ it "top-level-it" do end
782
+
783
+ y = describe "inner thingy" do
784
+ before { before_list << 2 }
785
+ after { after_list << 2 }
786
+ it "inner-it" do end
787
+
788
+ z = describe "very inner thingy" do
789
+ before { before_list << 3 }
790
+ after { after_list << 3 }
791
+ it "inner-it" do end
792
+
793
+ it { } # ignore me
794
+ specify { } # anonymous it
795
+ end
796
+ end
797
+ end
798
+
799
+ return x, y, z, before_list, after_list
800
+ end
801
+
802
+ def test_register_spec_type
803
+ original_types = Minitest::Spec::TYPES.dup
804
+
805
+ assert_includes Minitest::Spec::TYPES, [//, Minitest::Spec]
806
+
807
+ Minitest::Spec.register_spec_type(/woot/, TestMeta)
808
+
809
+ p = lambda do |_| true end
810
+ Minitest::Spec.register_spec_type TestMeta, &p
811
+
812
+ keys = Minitest::Spec::TYPES.map(&:first)
813
+
814
+ assert_includes keys, /woot/
815
+ assert_includes keys, p
816
+ ensure
817
+ Minitest::Spec::TYPES.replace original_types
818
+ end
819
+
820
+ def test_spec_type
821
+ original_types = Minitest::Spec::TYPES.dup
822
+
823
+ Minitest::Spec.register_spec_type(/A$/, MiniSpecA)
824
+ Minitest::Spec.register_spec_type MiniSpecB do |desc|
825
+ desc.superclass == ExampleA
826
+ end
827
+ Minitest::Spec.register_spec_type MiniSpecC do |_desc, *addl|
828
+ addl.include? :woot
829
+ end
830
+
831
+ assert_equal MiniSpecA, Minitest::Spec.spec_type(ExampleA)
832
+ assert_equal MiniSpecB, Minitest::Spec.spec_type(ExampleB)
833
+ assert_equal MiniSpecC, Minitest::Spec.spec_type(ExampleB, :woot)
834
+ ensure
835
+ Minitest::Spec::TYPES.replace original_types
836
+ end
837
+
838
+ def test_bug_dsl_expectations
839
+ spec_class = Class.new MiniSpecB do
840
+ it "should work" do
841
+ _(0).must_equal 0
842
+ end
843
+ end
844
+
845
+ test_name = spec_class.instance_methods.sort.grep(/test_/).first
846
+
847
+ spec = spec_class.new test_name
848
+
849
+ result = spec.run
850
+
851
+ assert spec.passed?
852
+ assert result.passed?
853
+ assert_equal 1, result.assertions
854
+ end
855
+
856
+ def test_name
857
+ spec_a = describe ExampleA do; end
858
+ spec_b = describe ExampleB, :random_method do; end
859
+ spec_c = describe ExampleB, :random_method, :addl_context do; end
860
+
861
+ assert_equal "ExampleA", spec_a.name
862
+ assert_equal "ExampleB::random_method", spec_b.name
863
+ assert_equal "ExampleB::random_method::addl_context", spec_c.name
864
+ end
865
+
866
+ def test_inspect
867
+ spec_a = describe ExampleA do; end
868
+ spec_b = describe ExampleB, :random_method do; end
869
+ spec_c = describe ExampleB, :random_method, :addl_context do; end
870
+
871
+ assert_equal "ExampleA", spec_a.inspect
872
+ assert_equal "ExampleB::random_method", spec_b.inspect
873
+ assert_equal "ExampleB::random_method::addl_context", spec_c.inspect
874
+ end
875
+
876
+ def test_name2
877
+ assert_equal "NamedExampleA", NamedExampleA.name
878
+ assert_equal "NamedExampleB", NamedExampleB.name
879
+ assert_equal "NamedExampleC", NamedExampleC.name
880
+
881
+ spec_a = describe ExampleA do; end
882
+ spec_b = describe ExampleB, :random_method do; end
883
+
884
+ assert_equal "ExampleA", spec_a.name
885
+ assert_equal "ExampleB::random_method", spec_b.name
886
+ end
887
+
888
+ def test_name_inside_class
889
+ spec_a = nil
890
+ spec_b = nil
891
+ inside_class_example = Class.new Minitest::Spec
892
+ Object.const_set :InsideClassExample, inside_class_example
893
+ inside_class_example.class_eval do
894
+ spec_a = describe "a" do
895
+ spec_b = describe "b" do; end
896
+ end
897
+ end
898
+
899
+ assert_equal "InsideClassExample::a", spec_a.name
900
+ assert_equal "InsideClassExample::a::b", spec_b.name
901
+ ensure
902
+ Object.send :remove_const, :InsideClassExample
903
+ end
904
+
905
+ def test_structure
906
+ x, y, z, * = util_structure
907
+
908
+ assert_equal "top-level thingy", x.to_s
909
+ assert_equal "top-level thingy::inner thingy", y.to_s
910
+ assert_equal "top-level thingy::inner thingy::very inner thingy", z.to_s
911
+
912
+ assert_equal "top-level thingy", x.desc
913
+ assert_equal "inner thingy", y.desc
914
+ assert_equal "very inner thingy", z.desc
915
+
916
+ top_methods = %w[setup teardown test_0001_top-level-it]
917
+ inner_methods1 = %w[setup teardown test_0001_inner-it]
918
+ inner_methods2 = inner_methods1 +
919
+ %w[test_0002_anonymous test_0003_anonymous]
920
+
921
+ assert_defined_methods top_methods, x
922
+ assert_defined_methods inner_methods1, y
923
+ assert_defined_methods inner_methods2, z
924
+ end
925
+
926
+ def test_structure_postfix_it
927
+ z = nil
928
+ y = describe "outer" do
929
+ # NOT here, below the inner-describe!
930
+ # it "inner-it" do end
931
+
932
+ z = describe "inner" do
933
+ it "inner-it" do end
934
+ end
935
+
936
+ # defined AFTER inner describe means we'll try to wipe out the inner-it
937
+ it "inner-it" do end
938
+ end
939
+
940
+ assert_defined_methods %w[test_0001_inner-it], y
941
+ assert_defined_methods %w[test_0001_inner-it], z
942
+ end
943
+
944
+ def test_setup_teardown_behavior
945
+ _, _, z, before_list, after_list = util_structure
946
+
947
+ @tu = z
948
+
949
+ run_tu_with_fresh_reporter
950
+
951
+ size = z.runnable_methods.size
952
+ assert_equal [1, 2, 3] * size, before_list
953
+ assert_equal [3, 2, 1] * size, after_list
954
+ end
955
+
956
+ def test_describe_first_structure
957
+ x1 = x2 = y = z = nil
958
+ x = describe "top-level thingy" do
959
+ y = describe "first thingy" do end
960
+
961
+ x1 = it "top level it" do end
962
+ x2 = it "не латинские &いった α, β, γ, δ, ε hello!!! world" do end
963
+
964
+ z = describe "second thingy" do end
965
+ end
966
+
967
+ test_methods = [
968
+ "test_0001_top level it",
969
+ "test_0002_не латинские &いった α, β, γ, δ, ε hello!!! world",
970
+ ].sort
971
+
972
+ assert_equal test_methods, [x1, x2]
973
+ assert_defined_methods test_methods, x
974
+ assert_defined_methods [], y
975
+ assert_defined_methods [], z
976
+ end
977
+
978
+ def test_structure_subclasses
979
+ z = nil
980
+ x = Class.new Minitest::Spec do
981
+ def xyz; end
982
+ end
983
+ y = Class.new x do
984
+ z = describe("inner") { }
985
+ end
986
+
987
+ assert_respond_to x.new(nil), "xyz"
988
+ assert_respond_to y.new(nil), "xyz"
989
+ assert_respond_to z.new(nil), "xyz"
990
+ end
991
+ end
992
+
993
+ class TestSpecInTestCase < MetaMetaMetaTestCase
994
+ def setup
995
+ super
996
+
997
+ Thread.current[:current_spec] = self
998
+ @tc = self
999
+ @assertion_count = 2
1000
+ end
1001
+
1002
+ def assert_triggered expected, klass = Minitest::Assertion
1003
+ @assertion_count += 1
1004
+
1005
+ e = assert_raises klass do
1006
+ yield
1007
+ end
1008
+
1009
+ msg = e.message.sub(/(---Backtrace---).*/m, "\1")
1010
+ msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
1011
+
1012
+ assert_equal expected, msg
1013
+ end
1014
+
1015
+ def teardown
1016
+ msg = "expected #{@assertion_count} assertions, not #{@tc.assertions}"
1017
+ assert_equal @assertion_count, @tc.assertions, msg
1018
+ end
1019
+
1020
+ def test_expectation
1021
+ @tc.assert_equal true, _(1).must_equal(1)
1022
+ end
1023
+
1024
+ def test_expectation_triggered
1025
+ assert_triggered "Expected: 2\n Actual: 1" do
1026
+ _(1).must_equal 2
1027
+ end
1028
+ end
1029
+
1030
+ include Minitest::Spec::DSL::InstanceMethods
1031
+
1032
+ def test_expectation_with_a_message
1033
+ assert_triggered "woot.\nExpected: 2\n Actual: 1" do
1034
+ _(1).must_equal 2, "woot"
1035
+ end
1036
+ end
1037
+ end
1038
+
1039
+ class ValueMonadTest < Minitest::Test
1040
+ attr_accessor :struct
1041
+
1042
+ def setup
1043
+ @struct = { :_ => "a", :value => "b", :expect => "c" }
1044
+ def @struct.method_missing k # think openstruct
1045
+ self[k]
1046
+ end
1047
+ end
1048
+
1049
+ def test_value_monad_method
1050
+ assert_equal "a", struct._
1051
+ end
1052
+
1053
+ def test_value_monad_value_alias
1054
+ assert_equal "b", struct.value
1055
+ end
1056
+
1057
+ def test_value_monad_expect_alias
1058
+ assert_equal "c", struct.expect
1059
+ end
1060
+ end
1061
+
1062
+ describe Minitest::Spec, :infect_an_assertion do
1063
+ attr_accessor :infect_mock
1064
+
1065
+ before do
1066
+ mock = Object.new
1067
+ mock.singleton_class.attr_accessor :a, :k
1068
+ def mock.assert_infects *args, **kwargs
1069
+ self.a, self.k = args, kwargs
1070
+ end
1071
+
1072
+ self.infect_mock = mock
1073
+ end
1074
+
1075
+ def assert_infects exp, act, msg = nil, foo: nil, bar: nil
1076
+ self.infect_mock.assert_infects exp, act, msg, foo: foo, bar: bar
1077
+ end
1078
+
1079
+ Minitest::Expectations.infect_an_assertion :assert_infects, :must_infect
1080
+ Minitest::Expectations.infect_an_assertion :assert_infects, :must_infect_without_flipping, :dont_flip
1081
+
1082
+ it "infects assertions with kwargs" do
1083
+ _(:act).must_infect :exp, foo: :foo, bar: :bar
1084
+
1085
+ assert_equal [:exp, :act, nil], infect_mock.a
1086
+ assert_equal({foo: :foo, bar: :bar}, infect_mock.k)
1087
+ end
1088
+
1089
+ it "infects assertions with kwargs (dont_flip)" do
1090
+ _(:act).must_infect_without_flipping :exp, foo: :foo, bar: :bar
1091
+
1092
+ assert_equal [:act, :exp, nil], infect_mock.a
1093
+ assert_equal({foo: :foo, bar: :bar}, infect_mock.k)
1094
+ end
1095
+ end