miniunit 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,147 @@
1
+ require 'mini/spec'
2
+
3
+ Mini::Test.autorun
4
+
5
+ describe Mini::Spec do
6
+ before do
7
+ @assertion_count = 5
8
+ end
9
+
10
+ after do
11
+ self._assertions.must_equal @assertion_count
12
+ end
13
+
14
+ it "needs to have all methods named well" do
15
+ @assertion_count = 2
16
+
17
+ methods = Object.public_instance_methods.find_all { |n| n =~ /^must|^wont/ }
18
+ methods.map! { |m| m.to_s } if Symbol === methods.first
19
+
20
+ musts, wonts = methods.sort.partition { |m| m =~ /^must/ }
21
+
22
+ expected_musts = %w(must_be
23
+ must_be_close_to
24
+ must_be_empty
25
+ must_be_instance_of
26
+ must_be_kind_of
27
+ must_be_nil
28
+ must_be_same_as
29
+ must_be_within_delta
30
+ must_be_within_epsilon
31
+ must_equal
32
+ must_include
33
+ must_match
34
+ must_raise
35
+ must_respond_to
36
+ must_throw)
37
+
38
+ expected_wonts = expected_musts.map { |m| m.sub(/^must/, 'wont') }
39
+ expected_wonts.reject! { |m| m =~ /wont_(not|raise|throw)/ }
40
+
41
+ musts.must_equal expected_musts
42
+ wonts.must_equal expected_wonts
43
+ end
44
+
45
+ it "needs to verify equality" do
46
+ (6 * 7).must_equal(42).must_equal true
47
+ proc { (6 * 9).must_equal(42) }.must_raise Mini::Assertion
48
+ end
49
+
50
+ it "needs to verify floats within a delta" do
51
+ (6.0 * 7).must_be_close_to(42.0).must_equal true
52
+ proc { 42.002.must_be_close_to 42.0 }.must_raise Mini::Assertion
53
+ end
54
+
55
+ it "needs to verify types of objects" do
56
+ (6 * 7).must_be_instance_of(Fixnum).must_equal true
57
+ proc { (6 * 7).must_be_instance_of String }.must_raise Mini::Assertion
58
+ end
59
+
60
+ it "needs to verify kinds of objects" do
61
+ @assertion_count = 7
62
+
63
+ (6 * 7).must_be_kind_of(Fixnum).must_equal true
64
+ (6 * 7).must_be_kind_of(Numeric).must_equal true
65
+ proc { (6 * 7).must_be_kind_of String }.must_raise Mini::Assertion
66
+ end
67
+
68
+ it "needs to verify regexp matches" do
69
+ "blah".must_match(/\w+/).must_equal true
70
+ proc { "blah".must_match(/\d+/) }.must_raise Mini::Assertion
71
+ end
72
+
73
+ it "needs to verify nil" do
74
+ nil.must_be_nil.must_equal true
75
+ proc { 42.must_be_nil }.must_raise Mini::Assertion
76
+ end
77
+
78
+ it "needs to verify using any operator" do
79
+ 41.must_be(:<, 42).must_equal true
80
+ proc { 42.must_be(:<, 41) }.must_raise Mini::Assertion
81
+ end
82
+
83
+ it "needs to catch an expected exception" do
84
+ @assertion_count = 4
85
+
86
+ proc { raise "blah" }.must_raise RuntimeError
87
+ proc { raise Mini::Assertion }.must_raise Mini::Assertion
88
+ end
89
+
90
+ it "needs to catch an unexpected exception" do
91
+ @assertion_count = 4
92
+
93
+ proc {
94
+ proc { raise Mini::Assertion }.must_raise(RuntimeError)
95
+ }.must_raise Mini::Assertion
96
+ end
97
+
98
+ it "needs raise if an expected exception is not raised" do
99
+ @assertion_count = 3
100
+
101
+ proc { proc { 42 }.must_raise(RuntimeError) }.must_raise Mini::Assertion
102
+ end
103
+
104
+ it "needs to be able to catch a Mini::Assertion exception" do
105
+ @assertion_count = 3
106
+
107
+ proc { 1.wont_equal 1 }.must_raise Mini::Assertion
108
+ end
109
+
110
+ it "needs to verify using respond_to" do
111
+ 42.must_respond_to(:+).must_equal true
112
+ proc { 42.must_respond_to(:clear) }.must_raise Mini::Assertion
113
+ end
114
+
115
+ it "needs to verify identity" do
116
+ 1.must_be_same_as(1).must_equal true
117
+ proc { 1.must_be_same_as 2 }.must_raise Mini::Assertion
118
+ end
119
+
120
+ it "needs to verify throw" do
121
+ @assertion_count = 8
122
+
123
+ proc { throw :blah }.must_throw(:blah).must_equal true
124
+ proc { proc { }.must_throw(:blah) }.must_raise Mini::Assertion
125
+ proc { proc { throw :xxx }.must_throw(:blah) }.must_raise Mini::Assertion
126
+ end
127
+
128
+ it "needs to verify inequality" do
129
+ 42.wont_equal(6 * 9).must_equal false
130
+ proc { 1.wont_equal 1 }.must_raise Mini::Assertion
131
+ end
132
+
133
+ it "needs to verify mismatch" do
134
+ "blah".wont_match(/\d+/).must_equal false
135
+ proc { "blah".wont_match(/\w+/) }.must_raise Mini::Assertion
136
+ end
137
+
138
+ it "needs to verify non-nil" do
139
+ 42.wont_be_nil.must_equal false
140
+ proc { nil.wont_be_nil }.must_raise Mini::Assertion
141
+ end
142
+
143
+ it "needs to verify non-identity" do
144
+ 1.wont_be_same_as(2).must_equal false
145
+ proc { 1.wont_be_same_as 1 }.must_raise Mini::Assertion
146
+ end
147
+ end
@@ -0,0 +1,682 @@
1
+ require 'stringio'
2
+ require 'mini/test'
3
+
4
+ Mini::Test.autorun
5
+
6
+ class Mini::Test
7
+ attr_accessor :test_count
8
+ attr_accessor :assertion_count
9
+ end
10
+
11
+ class TestMiniTest < Mini::Test::TestCase
12
+
13
+ def setup
14
+ Mini::Test::TestCase.reset
15
+ @tu = Mini::Test.new
16
+ @output = StringIO.new("")
17
+ Mini::Test.output = @output
18
+ assert_equal [0, 0], @tu.run_test_suites
19
+ end
20
+
21
+ def teardown
22
+ Mini::Test.output = $stdout
23
+ end
24
+
25
+ BT_MIDDLE = ["./lib/mini/test.rb:165:in `run_test_suites'",
26
+ "./lib/mini/test.rb:161:in `each'",
27
+ "./lib/mini/test.rb:161:in `run_test_suites'",
28
+ "./lib/mini/test.rb:158:in `each'",
29
+ "./lib/mini/test.rb:158:in `run_test_suites'",
30
+ "./lib/mini/test.rb:139:in `run'",
31
+ "./lib/mini/test.rb:106:in `run'"]
32
+
33
+ def test_filter_backtrace
34
+ # this is a semi-lame mix of relative paths.
35
+ # I cheated by making the autotest parts not have ./
36
+ bt = (["lib/autotest.rb:571:in `add_exception'",
37
+ "test/test_autotest.rb:62:in `test_add_exception'",
38
+ "./lib/mini/test.rb:165:in `__send__'"] +
39
+ BT_MIDDLE +
40
+ ["./lib/mini/test.rb:29",
41
+ "test/test_autotest.rb:422"])
42
+ ex = ["lib/autotest.rb:571:in `add_exception'",
43
+ "test/test_autotest.rb:62:in `test_add_exception'"]
44
+ fu = Mini::filter_backtrace(bt)
45
+
46
+ assert_equal ex, fu
47
+ end
48
+
49
+ def test_filter_backtrace_all_unit
50
+ bt = (["./lib/mini/test.rb:165:in `__send__'"] +
51
+ BT_MIDDLE +
52
+ ["./lib/mini/test.rb:29"])
53
+ ex = bt.clone
54
+ fu = Mini::filter_backtrace(bt)
55
+ assert_equal ex, fu
56
+ end
57
+
58
+ def test_filter_backtrace_unit_starts
59
+ bt = (["./lib/mini/test.rb:165:in `__send__'"] +
60
+ BT_MIDDLE +
61
+ ["./lib/mini/test.rb:29",
62
+ "-e:1"])
63
+ ex = ["-e:1"]
64
+ fu = Mini::filter_backtrace(bt)
65
+ assert_equal ex, fu
66
+ end
67
+
68
+ def test_class_puke_with_assertion_failed
69
+ exception = Mini::Assertion.new "Oh no!"
70
+ exception.set_backtrace ["unhappy"]
71
+ assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
72
+ assert_equal 1, @tu.failures
73
+ assert_match(/^Failure.*Oh no!/m, @tu.report.first)
74
+ end
75
+
76
+ def test_class_puke_with_failure_and_flunk_in_backtrace
77
+ exception = begin
78
+ Mini::Test::TestCase.new('fake tc').flunk
79
+ rescue Mini::Assertion => failure
80
+ failure
81
+ end
82
+ assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
83
+ refute @tu.report.any?{|line| line =~ /in .flunk/}
84
+ end
85
+
86
+ def test_class_puke_with_non_failure_exception
87
+ exception = Exception.new("Oh no again!")
88
+ assert_equal 'E', @tu.puke('SomeClass', 'method_name', exception)
89
+ assert_equal 1, @tu.errors
90
+ assert_match(/^Exception.*Oh no again!/m, @tu.report.first)
91
+ end
92
+
93
+ def test_class_run_test_suites
94
+ create_a_test_case_named("ATestCase")
95
+ assert_equal [1, 1], @tu.run_test_suites
96
+ end
97
+
98
+ def test_run_failing # TODO: add error test
99
+ create_a_test_case_named("FailingTest", :failing => true)
100
+ @tu.run([])
101
+
102
+ util_assert_counts(2, 2, ["Failure:
103
+ test_failure(TestMiniTest::FailingTest) [(eval):5]:
104
+ Failed assertion, no message given.
105
+ "])
106
+
107
+ expected = "Loaded suite blah
108
+ Started
109
+ F.
110
+ Finished in 0.00
111
+
112
+ 1) Failure:
113
+ test_failure(TestMiniTest::FailingTest) [(eval):5]:
114
+ Failed assertion, no message given.
115
+
116
+ 2 tests, 2 assertions, 1 failures, 0 errors
117
+ "
118
+ util_assert_report expected
119
+ end
120
+
121
+ def util_assert_counts(assertions, count, expected = [])
122
+ assert_equal(expected, @tu.report)
123
+
124
+ assert_equal assertions, @tu.assertion_count
125
+ assert_equal count, @tu.test_count
126
+ end
127
+
128
+ def util_assert_report expected = nil
129
+ expected ||= "Loaded suite blah
130
+ Started
131
+ .
132
+ Finished in 0.00
133
+
134
+ 1 tests, 1 assertions, 0 failures, 0 errors
135
+ "
136
+ output = @output.string.sub(/Finished in .*/, "Finished in 0.00")
137
+ output.sub!(/Loaded suite .*/, 'Loaded suite blah')
138
+ assert_equal(expected, output)
139
+ end
140
+
141
+ def test_run_failing_filtered
142
+ create_a_test_case_named("FailingTest2", :failing => true)
143
+ @tu.run(%w(-n /something/))
144
+
145
+ util_assert_counts(1, 1)
146
+ util_assert_report
147
+ end
148
+
149
+ def test_run_passing
150
+ create_a_test_case_named("PassingTest")
151
+ @tu.run([])
152
+
153
+ util_assert_counts(1, 1)
154
+ util_assert_report
155
+ end
156
+
157
+ # TODO: nuke
158
+ def create_a_test_case_named(name, options = {})
159
+ eval <<-CODE
160
+ class #{name} < Mini::Test::TestCase
161
+ def test_something
162
+ assert true
163
+ end
164
+ #{if options[:failing]; "def test_failure; assert false; end"; end}
165
+ end
166
+ CODE
167
+ end
168
+ end
169
+
170
+ class TestMiniTestTestCase < Mini::Test::TestCase
171
+ def setup
172
+ util_test_suites.clear
173
+ @tc = Mini::Test::TestCase.new 'fake tc'
174
+ @zomg = "zomg ponies!"
175
+ @assertion_count = 1
176
+ end
177
+
178
+ def teardown
179
+ assert_equal @assertion_count, @tc._assertions, "expected #{@assertion_count} assertions to be fired during the test, not #{@tc._assertions}" if @tc._assertions
180
+ Object.send :remove_const, :ATestCase if defined? ATestCase
181
+ end
182
+
183
+ def test_class_inherited
184
+ @assertion_count = 0
185
+
186
+ util_test_case
187
+ assert util_test_suites[ATestCase]
188
+ end
189
+
190
+ def test_class_test_suites
191
+ @assertion_count = 0
192
+
193
+ util_test_case
194
+ assert_equal 1, Mini::Test::TestCase.test_suites.size
195
+ assert_equal [ATestCase], Mini::Test::TestCase.test_suites
196
+ end
197
+
198
+ def test_class_asserts_match_refutes
199
+ @assertion_count = 0
200
+
201
+ methods = Mini::Assertions.public_instance_methods
202
+ methods.map! { |m| m.to_s } if Symbol === methods.first
203
+
204
+ ignores = %w(assert_block assert_no_match assert_not_equal assert_not_nil
205
+ assert_not_same assert_nothing_thrown assert_raise
206
+ assert_nothing_raised assert_raises assert_throws)
207
+ asserts = methods.grep(/^assert/).sort - ignores
208
+ refutes = methods.grep(/^refute/).sort - ignores
209
+
210
+ assert_empty refutes.map { |n| n.sub(/^refute/, 'assert') } - asserts
211
+ assert_empty asserts.map { |n| n.sub(/^assert/, 'refute') } - refutes
212
+ end
213
+
214
+ def test_assert
215
+ @assertion_count = 2
216
+
217
+ @tc.assert_equal true, @tc.assert(true), "returns true on success"
218
+ end
219
+
220
+ def test_assert__triggered
221
+ util_assert_triggered "Failed assertion, no message given." do
222
+ @tc.assert false
223
+ end
224
+ end
225
+
226
+ def test_assert__triggered_message
227
+ util_assert_triggered @zomg do
228
+ @tc.assert false, @zomg
229
+ end
230
+ end
231
+
232
+ def test_assert_block
233
+ @tc.assert_block do
234
+ true
235
+ end
236
+ end
237
+
238
+ def test_assert_block_triggered
239
+ util_assert_triggered 'Expected block to return true value.' do
240
+ @tc.assert_block do
241
+ false
242
+ end
243
+ end
244
+ end
245
+
246
+ def test_assert_empty
247
+ @assertion_count = 2
248
+
249
+ @tc.assert_empty []
250
+ end
251
+
252
+ def test_assert_empty_triggered
253
+ @assertion_count = 2
254
+
255
+ util_assert_triggered "Expected [1] to be empty." do
256
+ @tc.assert_empty [1]
257
+ end
258
+ end
259
+
260
+ def test_assert_equal
261
+ @tc.assert_equal 1, 1
262
+ end
263
+
264
+ def test_assert_equal_different
265
+ util_assert_triggered "Expected 1, not 2." do
266
+ @tc.assert_equal 1, 2
267
+ end
268
+ end
269
+
270
+ def test_assert_in_delta
271
+ @tc.assert_in_delta 0.0, 1.0 / 1000, 0.1
272
+ end
273
+
274
+ def test_assert_in_delta_triggered
275
+ util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to be < 1.0e-06.' do
276
+ @tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
277
+ end
278
+ end
279
+
280
+ def test_assert_in_epsilon
281
+ @assertion_count = 8
282
+
283
+ @tc.assert_in_epsilon 10000, 9991
284
+ @tc.assert_in_epsilon 9991, 10000
285
+ @tc.assert_in_epsilon 1.0, 1.001
286
+ @tc.assert_in_epsilon 1.001, 1.0
287
+
288
+ @tc.assert_in_epsilon 10000, 9999.1, 0.0001
289
+ @tc.assert_in_epsilon 9999.1, 10000, 0.0001
290
+ @tc.assert_in_epsilon 1.0, 1.0001, 0.0001
291
+ @tc.assert_in_epsilon 1.0001, 1.0, 0.0001
292
+ end
293
+
294
+ def test_assert_in_epsilon_triggered
295
+ util_assert_triggered 'Expected 10000 - 9990 (10) to be < 9.99.' do
296
+ @tc.assert_in_epsilon 10000, 9990
297
+ end
298
+ end
299
+
300
+ def test_assert_includes
301
+ @assertion_count = 2
302
+
303
+ @tc.assert_includes [true], true
304
+ end
305
+
306
+ def test_assert_includes_triggered
307
+ @assertion_count = 4
308
+
309
+ e = @tc.assert_raises Mini::Assertion do
310
+ @tc.assert_includes [true], false
311
+ end
312
+
313
+ expected = "Expected [true] to include false."
314
+ assert_equal expected, e.message
315
+ end
316
+
317
+ def test_assert_instance_of
318
+ @tc.assert_instance_of String, "blah"
319
+ end
320
+
321
+ def test_assert_instance_of_triggered
322
+ util_assert_triggered 'Expected "blah" to be an instance of Array.' do
323
+ @tc.assert_instance_of Array, "blah"
324
+ end
325
+ end
326
+
327
+ def test_assert_kind_of
328
+ @tc.assert_kind_of String, "blah"
329
+ end
330
+
331
+ def test_assert_kind_of_triggered
332
+ util_assert_triggered 'Expected "blah" to be a kind of Array.' do
333
+ @tc.assert_kind_of Array, "blah"
334
+ end
335
+ end
336
+
337
+ def test_assert_match
338
+ @tc.assert_match "blah blah blah", /\w+/
339
+ end
340
+
341
+ def test_assert_match_triggered
342
+ util_assert_triggered 'Expected /\d+/ to match "blah blah blah".' do
343
+ @tc.assert_match "blah blah blah", /\d+/
344
+ end
345
+ end
346
+
347
+ def test_assert_nil
348
+ @tc.assert_nil nil
349
+ end
350
+
351
+ def test_assert_nil_triggered
352
+ util_assert_triggered 'Expected 42 to be nil.' do
353
+ @tc.assert_nil 42
354
+ end
355
+ end
356
+
357
+ def test_assert_operator
358
+ @tc.assert_operator 2, :>, 1
359
+ end
360
+
361
+ def test_assert_operator_triggered
362
+ util_assert_triggered "Expected 2 to be < 1." do
363
+ @tc.assert_operator 2, :<, 1
364
+ end
365
+ end
366
+
367
+ def test_assert_raises
368
+ @assertion_count = 2
369
+
370
+ @tc.assert_raises RuntimeError do
371
+ raise "blah"
372
+ end
373
+ end
374
+
375
+ def test_assert_raises_triggered_different
376
+ @assertion_count = 2
377
+
378
+ e = assert_raises Mini::Assertion do
379
+ @tc.assert_raises RuntimeError do
380
+ raise SyntaxError, "icky"
381
+ end
382
+ end
383
+
384
+ expected = "Expected [RuntimeError] to include SyntaxError."
385
+
386
+ assert_equal expected, e.message
387
+ end
388
+
389
+ def test_assert_raises_triggered_none
390
+ e = assert_raises Mini::Assertion do
391
+ @tc.assert_raises Mini::Assertion do
392
+ # do nothing
393
+ end
394
+ end
395
+
396
+ expected = "Mini::Assertion expected but nothing was raised."
397
+
398
+ assert_equal expected, e.message
399
+ end
400
+
401
+ def test_assert_respond_to
402
+ @tc.assert_respond_to "blah", :empty?
403
+ end
404
+
405
+ def test_assert_respond_to_triggered
406
+ util_assert_triggered 'Expected "blah" to respond to rawr!.' do
407
+ @tc.assert_respond_to "blah", :rawr!
408
+ end
409
+ end
410
+
411
+ def test_assert_same
412
+ @assertion_count = 3
413
+
414
+ o = "blah"
415
+ @tc.assert_same 1, 1
416
+ @tc.assert_same :blah, :blah
417
+ @tc.assert_same o, o
418
+ end
419
+
420
+ def test_assert_same_triggered
421
+ @assertion_count = 2
422
+
423
+ util_assert_triggered 'Expected 2 to be the same as 1.' do
424
+ @tc.assert_same 1, 2
425
+ end
426
+
427
+ util_assert_triggered 'Expected "blah" to be the same as "blah".' do
428
+ s1 = "blah"
429
+ s2 = "blah"
430
+ @tc.assert_same s1, s2
431
+ end
432
+ end
433
+
434
+ def test_assert_throws
435
+ @tc.assert_throws(:blah) do
436
+ throw :blah
437
+ end
438
+ end
439
+
440
+ def test_assert_throws_different
441
+ util_assert_triggered 'Expected :blah to have been thrown, not :not_blah.' do
442
+ @tc.assert_throws(:blah) do
443
+ throw :not_blah
444
+ end
445
+ end
446
+ end
447
+
448
+ def test_assert_throws_unthrown
449
+ util_assert_triggered 'Expected :blah to have been thrown.' do
450
+ @tc.assert_throws(:blah) do
451
+ # do nothing
452
+ end
453
+ end
454
+ end
455
+
456
+ def test_capture_io
457
+ @assertion_count = 0
458
+
459
+ out, err = capture_io do
460
+ puts 'hi'
461
+ warn 'bye!'
462
+ end
463
+
464
+ assert_equal "hi\n", out
465
+ assert_equal "bye!\n", err
466
+ end
467
+
468
+ def test_message
469
+ @assertion_count = 0
470
+
471
+ assert_equal "blah2.", @tc.message(nil, "blah2")
472
+ assert_equal "blah2.", @tc.message("", "blah2")
473
+ assert_equal "blah1.\nblah2.", @tc.message("blah1", "blah2")
474
+ end
475
+
476
+ def test_flunk
477
+ util_assert_triggered 'Epic Fail!' do
478
+ @tc.flunk
479
+ end
480
+ end
481
+
482
+ def test_flunk_message
483
+ util_assert_triggered @zomg do
484
+ @tc.flunk @zomg
485
+ end
486
+ end
487
+
488
+ def test_pass
489
+ @tc.pass
490
+ end
491
+
492
+ def test_test_methods
493
+ @assertion_count = 0
494
+
495
+ # TODO: remove
496
+ sample_test_case = util_test_case
497
+ sample_test_case.instance_eval do
498
+ define_method :test_one_test do
499
+ assert "does not matter"
500
+ end
501
+ end
502
+ assert_equal(%w(test_one_test), sample_test_case.test_methods)
503
+ end
504
+
505
+ def test_refute
506
+ @assertion_count = 2
507
+
508
+ @tc.assert_equal false, @tc.refute(false), "returns false on success"
509
+ end
510
+
511
+ def test_refute_empty
512
+ @assertion_count = 2
513
+
514
+ @tc.refute_empty [1]
515
+ end
516
+
517
+ def test_refute_empty_triggered
518
+ @assertion_count = 2
519
+
520
+ util_assert_triggered "Expected [] to not be empty." do
521
+ @tc.refute_empty []
522
+ end
523
+ end
524
+
525
+ def test_refute_equal
526
+ @tc.refute_equal "blah", "yay"
527
+ end
528
+
529
+ def test_refute_equal_triggered
530
+ util_assert_triggered 'Expected "blah" to not be equal to "blah".' do
531
+ @tc.refute_equal "blah", "blah"
532
+ end
533
+ end
534
+
535
+ def test_refute_in_delta
536
+ @tc.refute_in_delta 0.0, 1.0 / 1000, 0.000001
537
+ end
538
+
539
+ def test_refute_in_delta_triggered
540
+ util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to not be < 0.1.' do
541
+ @tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
542
+ end
543
+ end
544
+
545
+ def test_refute_in_epsilon
546
+ @tc.refute_in_epsilon 10000, 9990
547
+ end
548
+
549
+ def test_refute_in_epsilon_triggered
550
+ util_assert_triggered 'Expected 10000 - 9991 (9) to not be < 10.0.' do
551
+ @tc.refute_in_epsilon 10000, 9991
552
+ fail
553
+ end
554
+ end
555
+
556
+ def test_refute_includes
557
+ @assertion_count = 2
558
+
559
+ @tc.refute_includes [true], false
560
+ end
561
+
562
+ def test_refute_includes_triggered
563
+ @assertion_count = 4
564
+
565
+ e = @tc.assert_raises Mini::Assertion do
566
+ @tc.refute_includes [true], true
567
+ end
568
+
569
+ expected = "Expected [true] to not include true."
570
+ assert_equal expected, e.message
571
+ end
572
+
573
+ def test_refute_instance_of
574
+ @tc.refute_instance_of Array, "blah"
575
+ end
576
+
577
+ def test_refute_instance_of_triggered
578
+ util_assert_triggered 'Expected "blah" to not be an instance of String.' do
579
+ @tc.refute_instance_of String, "blah"
580
+ end
581
+ end
582
+
583
+ def test_refute_kind_of
584
+ @tc.refute_kind_of Array, "blah"
585
+ end
586
+
587
+ def test_refute_kind_of_triggered
588
+ util_assert_triggered 'Expected "blah" to not be a kind of String.' do
589
+ @tc.refute_kind_of String, "blah"
590
+ end
591
+ end
592
+
593
+ def test_refute_match
594
+ @tc.refute_match "blah blah blah", /\d+/
595
+ end
596
+
597
+ def test_refute_match_triggered
598
+ util_assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do
599
+ @tc.refute_match "blah blah blah", /\w+/
600
+ end
601
+ end
602
+
603
+ def test_refute_nil
604
+ @tc.refute_nil 42
605
+ end
606
+
607
+ def test_refute_nil_triggered
608
+ util_assert_triggered 'Expected nil to not be nil.' do
609
+ @tc.refute_nil nil
610
+ end
611
+ end
612
+
613
+ def test_refute_operator
614
+ @tc.refute_operator 2, :<, 1
615
+ end
616
+
617
+ def test_refute_operator_triggered
618
+ util_assert_triggered "Expected 2 to not be > 1." do
619
+ @tc.refute_operator 2, :>, 1
620
+ end
621
+ end
622
+
623
+ def test_refute_respond_to
624
+ @tc.refute_respond_to "blah", :rawr!
625
+ end
626
+
627
+ def test_refute_respond_to_triggered
628
+ util_assert_triggered 'Expected "blah" to not respond to empty?.' do
629
+ @tc.refute_respond_to "blah", :empty?
630
+ end
631
+ end
632
+
633
+ def test_refute_same
634
+ @tc.refute_same 1, 2
635
+ end
636
+
637
+ # TODO: "with id <id>" crap from assertions.rb
638
+ def test_refute_same_triggered
639
+ util_assert_triggered 'Expected 1 to not be the same as 1.' do
640
+ @tc.refute_same 1, 1
641
+ end
642
+ end
643
+
644
+ def util_assert_triggered expected
645
+ e = assert_raises(Mini::Assertion) do
646
+ yield
647
+ end
648
+
649
+ assert_equal expected, e.message.sub(/(---Backtrace---).*/m, '\1')
650
+ end
651
+
652
+ def util_test_suites
653
+ Mini::Test::TestCase.__send__(:class_variable_get, :@@test_suites)
654
+ end
655
+
656
+ # TODO: remove
657
+ def util_test_case
658
+ Object.const_set(:ATestCase, Class.new(Mini::Test::TestCase))
659
+ end
660
+
661
+ if ENV['DEPRECATED'] then
662
+ require 'test/unit/assertions'
663
+ def test_assert_nothing_raised
664
+ @tc.assert_nothing_raised do
665
+ # do nothing
666
+ end
667
+ end
668
+
669
+ def test_assert_nothing_raised_triggered
670
+ expected = 'Exception raised:
671
+ Class: <RuntimeError>
672
+ Message: <"oops!">
673
+ ---Backtrace---'
674
+
675
+ util_assert_triggered expected do
676
+ @tc.assert_nothing_raised do
677
+ raise "oops!"
678
+ end
679
+ end
680
+ end
681
+ end
682
+ end