arikui1911-tinytest 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ unless Method.method_defined?(:source_location)
2
+ class TinyTest::TestCase
3
+ def self.method_added(name)
4
+ filename, lineno = caller[0].match(TinyTest::Suite::CALLER_RE).captures
5
+ lineno = Integer(lineno)
6
+ TinyTest::Suite::METHOD_ADDED_RECORDS[[self, name]] = [filename, lineno]
7
+ end
8
+ private_class_method :method_added
9
+ end
10
+
11
+ class TinyTest::Suite
12
+ METHOD_ADDED_RECORDS = {}
13
+
14
+ def method_location(obj, name)
15
+ METHOD_ADDED_RECORDS[[obj.class, name]]
16
+ end
17
+ end
18
+ end
19
+
20
+ unless Object.method_defined?(:define_singleton_method)
21
+ class TinyTest::TestCase
22
+ def bind_testsuite(suite)
23
+ (class << self ; self ; end).class_eval{ define_method(:suite){ suite } }
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,53 @@
1
+ #
2
+ # Distributes under The modified BSD license.
3
+ #
4
+ # Copyright (c) 2009 arikui <http://d.hatena.ne.jp/arikui/>
5
+ # All rights reserved.
6
+ #
7
+
8
+ require 'tinytest'
9
+ require 'optparse'
10
+
11
+ module TinyTest::Unit
12
+ # Add hook which allocate TinyTest::Runner with parsed ARGV and
13
+ # execute Runner#run at exit (Only wehn firstly called).
14
+ def self.autorun
15
+ @autorunner ||= autorunner()
16
+ end
17
+
18
+ # Already set #autorun or not.
19
+ def self.autorun?
20
+ @autorunner ? true : false
21
+ end
22
+
23
+ def self.autorunner
24
+ at_exit{
25
+ runner = parse_options(ARGV)
26
+ runner.run
27
+ }
28
+ end
29
+ private_class_method :autorunner
30
+
31
+ def self.parse_options(argv)
32
+ opts = {}
33
+ o = OptionParser.new
34
+ o.banner = "== TinyTest autorunner ==\n"
35
+ o.banner << "Usage: test-script [options]\n"
36
+ o.on('-n', '--testname=NAME', 'assign testname matcher') do |s|
37
+ opts[:testname] = Regexp.new(s)
38
+ end
39
+ o.on('-t', '--testcase=NAME', 'assign testcase matcher') do |s|
40
+ opts[:testcase] = Regexp.new(s)
41
+ end
42
+ o.on('-I', '--load-path=DIR', 'add to ruby load-path') do |s|
43
+ $LOAD_PATH.push s
44
+ end
45
+ o.on('-v', '--[no-]verbose', 'turn on/off verbose mode') do |b|
46
+ opts[:verbose] = b
47
+ end
48
+ o.parse! argv
49
+ TinyTest::Runner.new(opts)
50
+ end
51
+ private_class_method :parse_options
52
+ end
53
+
@@ -0,0 +1,1251 @@
1
+ require 'test/unit'
2
+ require 'set'
3
+ require 'stringio'
4
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ before = $LOADED_FEATURES.dup
6
+ require 'tinytest'
7
+ after = $LOADED_FEATURES
8
+ feature = (after - before).last
9
+ unless feature.include?('/') || feature.include?('\\')
10
+ # expand feature because $LOADED_FEATURES holds relative path in Ruby 1.8.x
11
+ feature = $LOAD_PATH.map{|d| File.join(d, feature) }.find{|path| File.file?(path) }
12
+ end
13
+ TINYTEST_FEATURE = feature
14
+
15
+ module TestUtil
16
+ def positive_integer_cases(limit)
17
+ [0, 1, TestUtil.sample([*2..limit])]
18
+ end
19
+ module_function :positive_integer_cases
20
+
21
+ def shuffle(collection)
22
+ collection.sort_by{ rand }
23
+ end
24
+ module_function :shuffle
25
+
26
+ def sample(collection)
27
+ TestUtil.shuffle(collection).first
28
+ end
29
+ module_function :sample
30
+
31
+ def start_with?(str, tgt)
32
+ i = str.index(tgt) and i == 0 ? true : false
33
+ end
34
+ module_function :start_with?
35
+ end
36
+
37
+ class TC_AssertError < Test::Unit::TestCase
38
+ def test_superclass
39
+ assert TinyTest::AssertError < Exception
40
+ end
41
+ end
42
+
43
+ class TC_SkipError < Test::Unit::TestCase
44
+ def test_superclass
45
+ assert TinyTest::SkipError < TinyTest::AssertError
46
+ end
47
+ end
48
+
49
+ class TC_Runner < Test::Unit::TestCase
50
+ module MockForRun
51
+ def set(n_assertions, results, benchmark)
52
+ self.n_assertions = n_assertions
53
+ self.results = results
54
+ self.benchmark = benchmark
55
+ end
56
+
57
+ attr_accessor :n_assertions
58
+ attr_accessor :results
59
+ attr_accessor :benchmark
60
+
61
+ def run_suites(suites)
62
+ return n_assertions, results, benchmark
63
+ end
64
+
65
+ def collect_suites
66
+ suite_list
67
+ end
68
+
69
+ def suite_list
70
+ @suite_list ||= []
71
+ end
72
+
73
+ def count_suiteresults_types(results)
74
+ return 1, 2, 3
75
+ end
76
+ end
77
+
78
+ class ReporterMock
79
+ def initialize
80
+ @history = []
81
+ end
82
+
83
+ attr_reader :history
84
+
85
+ def method_missing(name, *args)
86
+ history << [name, *args]
87
+ end
88
+ end
89
+
90
+ BENCH = Object.new
91
+ def BENCH.real
92
+ 6.66
93
+ end
94
+
95
+ def test_run
96
+ results = []
97
+ repo = ReporterMock.new
98
+ runner = TinyTest::Runner.new(:reporter => repo)
99
+ runner.extend(MockForRun).set(666, results, BENCH)
100
+ runner.run
101
+ assert_equal :load_suite, repo.history.shift.first
102
+ assert_equal [:mark_results, results], repo.history.shift
103
+ assert_equal [:running_times, BENCH], repo.history.shift
104
+ assert_equal [:blank], repo.history.shift
105
+ assert_equal [:counts_report, results.size, 666, 1, 2, 3], repo.history.shift
106
+ end
107
+
108
+ def test_run_verbose
109
+ results = []
110
+ repo = ReporterMock.new
111
+ runner = TinyTest::Runner.new(:reporter => repo, :verbose => true)
112
+ runner.extend(MockForRun).set(666, results, BENCH)
113
+ runner.run
114
+ assert_equal :load_suite, repo.history.shift.first
115
+ assert_equal [:mark_results_with_times, results], repo.history.shift
116
+ assert_equal [:running_times, BENCH], repo.history.shift
117
+ assert_equal [:blank], repo.history.shift
118
+ assert_equal [:counts_report, results.size, 666, 1, 2, 3], repo.history.shift
119
+ end
120
+
121
+ def test_run_with_errors
122
+ results = Array.new(5){
123
+ o = Object.new
124
+ def o.success?
125
+ true
126
+ end
127
+ o
128
+ }
129
+ results = Array.new(5){
130
+ o = Object.new
131
+ def o.success?
132
+ false
133
+ end
134
+ o
135
+ }
136
+ results = TestUtil.shuffle(results)
137
+ not_succeededs = results.select{|r| not r.success? }
138
+ repo = ReporterMock.new
139
+ runner = TinyTest::Runner.new(:reporter => repo)
140
+ runner.extend(MockForRun).set(666, results, BENCH)
141
+ runner.run
142
+ assert_equal :load_suite, repo.history.shift.first
143
+ assert_equal [:mark_results, results], repo.history.shift
144
+ assert_equal [:running_times, BENCH], repo.history.shift
145
+ assert_equal [:error_reports, not_succeededs], repo.history.shift
146
+ assert_equal [:counts_report, results.size, 666, 1, 2, 3], repo.history.shift
147
+ end
148
+ end
149
+
150
+ class TC_Runner_private < Test::Unit::TestCase
151
+ def setup
152
+ @runner = TinyTest::Runner.new
153
+ end
154
+
155
+ def test_each_class
156
+ root = Class.new
157
+ sub = Class.new(root)
158
+ subsub = Class.new(sub)
159
+ classes = []
160
+ @runner.instance_eval{ each_class(root){|c| classes << c } }
161
+ assert_equal Set.new([sub, subsub]), Set.new(classes)
162
+ end
163
+
164
+ class SuiteMock
165
+ def count_assertions
166
+ yield()
167
+ 666
168
+ end
169
+
170
+ def execute
171
+ 'execute'
172
+ end
173
+ end
174
+
175
+ def test_private_run_suites
176
+ suites = Array.new(3){ SuiteMock.new }
177
+ n, results, bench = @runner.instance_eval{ run_suites(suites) }
178
+ assert_equal 666 * 3, n
179
+ assert_equal ['execute'] * 3, results
180
+ end
181
+
182
+ def test_private_count_suiteresults_types
183
+ nums = Array.new(4){ TestUtil.sample([*1..10]) }
184
+ results = []
185
+ klass = Struct.new(:char)
186
+ %w[. F E S].zip(nums) do |c, n|
187
+ results.concat Array.new(n){ klass.new(c) }
188
+ end
189
+ results = TestUtil.shuffle(results)
190
+ counts = @runner.instance_eval{ count_suiteresults_types(results) }
191
+ assert_equal nums[1..-1], counts
192
+ end
193
+ end
194
+
195
+ class TC_Runner_private_collect_suites < Test::Unit::TestCase
196
+ module EachClassMock
197
+ def class_list
198
+ @class_list ||= []
199
+ end
200
+
201
+ def each_class(root = nil, &block)
202
+ class_list.each(&block)
203
+ end
204
+ end
205
+
206
+ class ClassMock
207
+ def initialize(name, *methods)
208
+ @name = name
209
+ @public_instance_methods = methods
210
+ unless /./ === :hoge # for 1.8 Symbol-Regexp matching
211
+ @public_instance_methods.map!{|m| m.id2name }
212
+ end
213
+ end
214
+
215
+ attr_accessor :name
216
+
217
+ def public_instance_methods(inherited_too = true)
218
+ @public_instance_methods
219
+ end
220
+
221
+ def new
222
+ self
223
+ end
224
+
225
+ def bind_testsuite(suite)
226
+ end
227
+
228
+ def inspect
229
+ "<#ClassMock:#{name}>"
230
+ end
231
+ end
232
+
233
+ # for ClassMock's 1.8 consideration
234
+ def symbol_set(enum)
235
+ enum = enum.map{|e| e.respond_to?(:intern) ? e.intern : e }
236
+ Set.new(enum)
237
+ end
238
+
239
+ def test_collect_suites
240
+ runner = TinyTest::Runner.new()
241
+ runner.extend(EachClassMock)
242
+ runner.class_list << ClassMock.new("Foo", :test_foo, :test_bar, :not_test_baz)
243
+ suites = runner.instance_eval{ collect_suites() }
244
+ assert_equal symbol_set([:test_foo, :test_bar]), symbol_set(suites.map{|s| s.testname })
245
+ end
246
+
247
+ def test_collect_suites_testname_matcher_re
248
+ runner = TinyTest::Runner.new(:testname => /\Aprefix_/)
249
+ runner.extend(EachClassMock)
250
+ runner.class_list << ClassMock.new("Foo", :test_foo, :prefix_bar, :prefix_baz)
251
+ suites = runner.instance_eval{ collect_suites() }
252
+ assert_equal symbol_set([:prefix_bar, :prefix_baz]), symbol_set(suites.map{|s| s.testname })
253
+ end
254
+
255
+ def test_collect_suites_testname_matcher_proc
256
+ matcher = lambda{|name| TestUtil.start_with?(name.to_s, 'prefix') }
257
+ runner = TinyTest::Runner.new(:testname => matcher)
258
+ runner.extend(EachClassMock)
259
+ runner.class_list << ClassMock.new("Foo", :test_foo, :prefix_bar, :prefix_baz)
260
+ suites = runner.instance_eval{ collect_suites() }
261
+ assert_equal symbol_set([:prefix_bar, :prefix_baz]), symbol_set(suites.map{|s| s.testname })
262
+ end
263
+
264
+ def test_collect_suites_testcase_matcher_re
265
+ runner = TinyTest::Runner.new(:testcase => /\ATC_/)
266
+ runner.extend(EachClassMock)
267
+ runner.class_list << ClassMock.new("TC_Foo", :test_foo_a, :test_foo_b, :not_test_foo_c)
268
+ runner.class_list << ClassMock.new("Bar", :test_bar_a, :test_bar_b, :not_test_bar_c)
269
+ suites = runner.instance_eval{ collect_suites() }
270
+ assert_equal Set.new(["TC_Foo"]), Set.new(suites.map{|s| s.testcase.name })
271
+ assert_equal symbol_set([:test_foo_a, :test_foo_b]), symbol_set(suites.map{|s| s.testname })
272
+ end
273
+
274
+ def test_collect_suites_testcase_matcher_proc
275
+ cm = ClassMock.new("TC_Foo", :test_foo_a, :test_foo_b, :not_test_foo_c)
276
+ matcher = lambda{|tc| tc.equal? cm }
277
+ runner = TinyTest::Runner.new(:testcase => matcher)
278
+ runner.extend(EachClassMock)
279
+ runner.class_list << cm
280
+ runner.class_list << ClassMock.new("Bar", :test_bar_a, :test_bar_b, :not_test_bar_c)
281
+ suites = runner.instance_eval{ collect_suites() }
282
+ assert_equal Set.new(["TC_Foo"]), Set.new(suites.map{|s| s.testcase.name })
283
+ assert_equal symbol_set([:test_foo_a, :test_foo_b]), symbol_set(suites.map{|s| s.testname })
284
+ end
285
+ end
286
+
287
+ class TC_Reporter < Test::Unit::TestCase
288
+ def setup
289
+ @f = StringIO.new
290
+ @r = TinyTest::Reporter.new(@f)
291
+ end
292
+
293
+ def test_blank
294
+ @r.blank
295
+ assert_equal "\n", @f.string
296
+ end
297
+
298
+ def test_load_suite
299
+ @r.load_suite "foo/bar"
300
+ @r.load_suite "foo/bar.rb"
301
+ assert_equal "Loaded suite foo/bar\nStarted\n" * 2, @f.string
302
+ end
303
+
304
+ module BenchmarkMock
305
+ REAL = 1.0
306
+
307
+ def self.real
308
+ REAL
309
+ end
310
+ end
311
+
312
+ class SuiteResultMock
313
+ def char
314
+ '*'
315
+ end
316
+
317
+ def report
318
+ 'REPORT'
319
+ end
320
+
321
+ SUITE = Object.new
322
+ def SUITE.inspect
323
+ 'INSPECTION'
324
+ end
325
+
326
+ def suite
327
+ SUITE
328
+ end
329
+
330
+ def benchmark
331
+ BenchmarkMock
332
+ end
333
+ end
334
+
335
+ include TestUtil
336
+
337
+ def test_mark_results
338
+ nums = positive_integer_cases(10)
339
+ nums.each do |n|
340
+ results = Array.new(n){ SuiteResultMock.new }
341
+ @r.mark_results(results)
342
+ end
343
+ assert_equal nums.map{|n| "#{'*' * n}\n" }.join, @f.string
344
+ end
345
+
346
+ def test_mark_results_with_times_for_0_results
347
+ @r.mark_results_with_times([])
348
+ assert_equal "\n\n", @f.string
349
+ end
350
+
351
+ def test_mark_results_with_times_for_1_result
352
+ @r.mark_results_with_times([SuiteResultMock.new])
353
+ assert_equal "\nINSPECTION: 1.00 sec: *\n\n", @f.string
354
+ end
355
+
356
+ def test_mark_results_with_times_for_results
357
+ n = positive_integer_cases(10).last
358
+ results = Array.new(n){ SuiteResultMock.new }
359
+ @r.mark_results_with_times(results)
360
+ expected = "\n" << "INSPECTION: 1.00 sec: *\n" * n << "\n"
361
+ assert_equal expected, @f.string
362
+ end
363
+
364
+ def test_running_times
365
+ @r.running_times(BenchmarkMock)
366
+ assert_equal "Finished in 1.000000 seconds.\n", @f.string
367
+ end
368
+
369
+ def test_error_reports_for_0_results
370
+ @r.error_reports([])
371
+ assert @f.string.empty?
372
+ end
373
+
374
+ def test_error_reports_for_1_result
375
+ @r.error_reports([SuiteResultMock.new])
376
+ assert_equal "\n 1) REPORT\n\n", @f.string
377
+ end
378
+
379
+ def test_error_reports_for_results
380
+ n = positive_integer_cases(9).last
381
+ results = Array.new(n){ SuiteResultMock.new }
382
+ @r.error_reports(results)
383
+ expected = Array.new(n){|i| "\n #{i.succ}) REPORT\n\n" }.join('')
384
+ assert_equal expected, @f.string
385
+ end
386
+
387
+ def test_counts_report
388
+ @r.counts_report(1, 2, 3, 4, 5)
389
+ expected = "1 tests, 2 assertions, 3 failures, 4 errors, 5 skips\n"
390
+ assert_equal expected, @f.string
391
+ end
392
+ end
393
+
394
+ class MockTestCase
395
+ def self.def_hist_method(name, &body)
396
+ define_method name do |*args|
397
+ history << name
398
+ body.call(*args) if body
399
+ end
400
+ end
401
+
402
+ def history
403
+ @history ||= []
404
+ end
405
+
406
+ attr_accessor :suite
407
+ alias :bind_testsuite :suite=
408
+
409
+ def_hist_method :setup
410
+ def_hist_method :teardown
411
+
412
+ def_hist_method :test_succeed do
413
+ true
414
+ end
415
+
416
+ def_hist_method :test_failure do
417
+ raise TinyTest::AssertError
418
+ end
419
+
420
+ def_hist_method :test_skip do
421
+ raise TinyTest::SkipError
422
+ end
423
+
424
+ def_hist_method :test_error do
425
+ raise
426
+ end
427
+ end
428
+
429
+ class TC_Suite < Test::Unit::TestCase
430
+
431
+ def setup
432
+ @testcase = MockTestCase.new
433
+ end
434
+
435
+ def test_initialize
436
+ suite = TinyTest::Suite.new(@testcase, :testname)
437
+ assert_equal @testcase, suite.testcase
438
+ assert_equal :testname, suite.testname
439
+ end
440
+
441
+ def test_inspect
442
+ suite = TinyTest::Suite.new(@testcase, :testname)
443
+ assert_equal "#{@testcase.class}#testname", suite.inspect
444
+ end
445
+
446
+ def test_execute_success
447
+ suite = TinyTest::Suite.new(@testcase, :test_succeed)
448
+ result = suite.execute
449
+ assert_equal [:setup, :test_succeed, :teardown], @testcase.history
450
+ assert result.success?
451
+ end
452
+
453
+ def test_execute_failure
454
+ suite = TinyTest::Suite.new(@testcase, :test_failure)
455
+ result = suite.execute
456
+ assert_equal [:setup, :test_failure, :teardown], @testcase.history
457
+ assert_equal 'F', result.char
458
+ end
459
+
460
+ def test_execute_error
461
+ suite = TinyTest::Suite.new(@testcase, :test_error)
462
+ result = suite.execute
463
+ assert_equal [:setup, :test_error, :teardown], @testcase.history
464
+ assert_equal 'E', result.char
465
+ end
466
+
467
+ def test_execute_skip
468
+ suite = TinyTest::Suite.new(@testcase, :test_skip)
469
+ result = suite.execute
470
+ assert_equal [:setup, :test_skip, :teardown], @testcase.history
471
+ assert_equal 'S', result.char
472
+ end
473
+ end
474
+
475
+ class TC_Suite_assertioncount < Test::Unit::TestCase
476
+ include TestUtil
477
+
478
+ def setup
479
+ @testcase = MockTestCase.new
480
+ @counter = TinyTest::Suite.new(@testcase, :dummy)
481
+ end
482
+
483
+ def test_out_of_count_assertions_block
484
+ do_count = lambda{|n|
485
+ n.times{ @counter.succ_assertion_count }
486
+ @counter.count_assertions{}
487
+ }
488
+ results = []
489
+ positive_integer_cases(10).each do |n|
490
+ results << do_count.call(n)
491
+ @counter.assertion_count_grouping{ results << do_count.call(n) }
492
+ end
493
+ assert_equal [0], results.uniq
494
+ end
495
+
496
+ def test_count_assertions
497
+ nums = positive_integer_cases(10)
498
+ assert_equal nums, nums.map{|n|
499
+ @counter.count_assertions{ n.times{ @counter.succ_assertion_count } }
500
+ }
501
+ end
502
+
503
+ def test_assertion_count_grouping
504
+ assert_equal 0, @counter.count_assertions{
505
+ @counter.assertion_count_grouping{}
506
+ }
507
+ naturals = positive_integer_cases(10)[1..-1]
508
+ assert_equal [1], naturals.map{|n|
509
+ @counter.count_assertions do
510
+ @counter.assertion_count_grouping do
511
+ n.times{ @counter.succ_assertion_count }
512
+ end
513
+ end
514
+ }.uniq
515
+ end
516
+
517
+ def test_assertion_count_grouping_several
518
+ assert_equal 4, @counter.count_assertions{
519
+ @counter.assertion_count_grouping{ @counter.succ_assertion_count }
520
+ 2.times{ @counter.succ_assertion_count }
521
+ @counter.assertion_count_grouping{ 2.times{ @counter.succ_assertion_count } }
522
+ @counter.assertion_count_grouping{}
523
+ }
524
+ end
525
+ end
526
+
527
+
528
+ class TC_SuiteResult < Test::Unit::TestCase
529
+ Reports = {
530
+ :success => nil,
531
+ :failure => 'Failure',
532
+ :error => 'Error',
533
+ :skip => 'Skip',
534
+ }
535
+
536
+ def setup
537
+ @results = {}
538
+ Reports.each{|k, v| @results[k] = TinyTest::SuiteResult.new(:suite, :benchmark, v) }
539
+ end
540
+
541
+ def test_report
542
+ Reports.each_key do |k|
543
+ assert_equal Reports[k], @results[k].report
544
+ end
545
+ end
546
+
547
+ def test_char
548
+ assert_equal ['.', 'F', 'E', 'S'],
549
+ [:success, :failure, :error, :skip].map{|k| @results[k].char }
550
+ end
551
+
552
+ def test_success?
553
+ others = Reports.keys
554
+ others.delete(:success)
555
+ others = others.map{|k| @results[k].success? }.uniq
556
+ assert_equal [false], others
557
+ assert @results[:success].success?
558
+ end
559
+ end
560
+
561
+ class TC_TestCase < Test::Unit::TestCase
562
+ def setup
563
+ @testcase = TinyTest::TestCase.new
564
+ end
565
+
566
+ def test_respondance_about_setup
567
+ assert_nothing_raised NoMethodError do
568
+ @testcase.setup
569
+ end
570
+ end
571
+
572
+ def test_respondance_about_teardown
573
+ assert_nothing_raised NoMethodError do
574
+ @testcase.teardown
575
+ end
576
+ end
577
+
578
+ def test_suite_attr
579
+ gensym = Object.new
580
+ assert_nothing_raised NoMethodError do
581
+ @testcase.bind_testsuite gensym
582
+ assert_equal gensym, @testcase.suite
583
+ end
584
+ end
585
+ end
586
+
587
+ class TC_TestCase_assertions < Test::Unit::TestCase
588
+ def setup
589
+ @tc = TinyTest::TestCase.new
590
+ @suite = TinyTest::Suite.new(@tc, nil)
591
+ @tc.bind_testsuite(@suite)
592
+ end
593
+
594
+ def if_flunk(message)
595
+ @flunk_message = message
596
+ yield()
597
+ @flunk_message = nil
598
+ end
599
+
600
+ def ex_message(target = TinyTest::AssertError)
601
+ yield()
602
+ flunk @flunk_message
603
+ rescue target => ex
604
+ ex.message
605
+ end
606
+
607
+ def test_assert
608
+ assert_nothing_raised TinyTest::AssertError do
609
+ @tc.assert true
610
+ end
611
+ if_flunk "assert seems to contain bug." do
612
+ assert_equal "Failed assertion, no message given.", ex_message{
613
+ @tc.assert false
614
+ }
615
+ assert_equal 'MESSAGE', ex_message{
616
+ @tc.assert false, 'MESSAGE'
617
+ }
618
+ end
619
+ end
620
+
621
+ def test_refute
622
+ assert_nothing_raised TinyTest::AssertError do
623
+ @tc.refute false
624
+ end
625
+ if_flunk "refute seems to contain bug." do
626
+ assert_equal "Failed refutation, no message given", ex_message{
627
+ @tc.refute true
628
+ }
629
+ assert_equal 'MESSAGE', ex_message{
630
+ @tc.refute true, 'MESSAGE'
631
+ }
632
+ end
633
+ end
634
+
635
+ def test_pass
636
+ assert_nothing_raised TinyTest::AssertError do
637
+ @tc.pass
638
+ end
639
+ end
640
+
641
+ def test_skip
642
+ if_flunk "skip seems to contain bug." do
643
+ assert_equal "Skipped, no message given", ex_message{
644
+ @tc.skip
645
+ }
646
+ assert_equal 'MESSAGE', ex_message{
647
+ @tc.skip 'MESSAGE'
648
+ }
649
+ end
650
+ end
651
+
652
+ def test_assert_block
653
+ assert_nothing_raised TinyTest::AssertError do
654
+ @tc.assert_block{ true }
655
+ end
656
+ if_flunk "assert_block seems to contain bug." do
657
+ default = "Expected block to return a value evaluated as true."
658
+ assert_equal default, ex_message{
659
+ @tc.assert_block{ false }
660
+ }
661
+ assert_equal "MESSAGE.\n#{default}", ex_message{
662
+ @tc.assert_block('MESSAGE'){ false }
663
+ }
664
+ end
665
+ end
666
+
667
+ def test_refute_block
668
+ assert_nothing_raised TinyTest::AssertError do
669
+ @tc.refute_block{ false }
670
+ end
671
+ if_flunk "refute_block seems to contain bug." do
672
+ default = "Expected block to return a value evaluated as false."
673
+ assert_equal default, ex_message{
674
+ @tc.refute_block{ true }
675
+ }
676
+ assert_equal "MESSAGE.\n#{default}", ex_message{
677
+ @tc.refute_block('MESSAGE'){ true }
678
+ }
679
+ end
680
+ end
681
+
682
+ def test_assert_equal
683
+ assert_nothing_raised TinyTest::AssertError do
684
+ @tc.assert_equal 4, 'Ruby'.size
685
+ end
686
+ if_flunk "assert_equal seems to contain bug." do
687
+ default = %Q`Expected "expected", not "actual".`
688
+ assert_equal default, ex_message{
689
+ @tc.assert_equal 'expected', 'actual'
690
+ }
691
+ assert_equal "MESSAGE.\n#{default}", ex_message{
692
+ @tc.assert_equal 'expected', 'actual', 'MESSAGE'
693
+ }
694
+ end
695
+ end
696
+
697
+ def test_refute_equal
698
+ assert_nothing_raised TinyTest::AssertError do
699
+ @tc.refute_equal 4, 'Python'.size
700
+ end
701
+ if_flunk "refute_equal seems to contain bug." do
702
+ val = %w[a b c]
703
+ default = %Q`Expected ["a", "b", "c"] to not be equal to ["a", "b", "c"].`
704
+ assert_equal default, ex_message{
705
+ @tc.refute_equal val, val
706
+ }
707
+ assert_equal "MESSAGE.\n#{default}", ex_message{
708
+ @tc.refute_equal val, val, 'MESSAGE'
709
+ }
710
+ end
711
+ end
712
+
713
+ def test_assert_instance_of
714
+ assert_nothing_raised TinyTest::AssertError do
715
+ @tc.assert_instance_of Array, []
716
+ end
717
+ if_flunk "assert_instance_of seems to contain bug." do
718
+ default = "Expected \"\" to be an instance of Array."
719
+ assert_equal default, ex_message{
720
+ @tc.assert_instance_of Array, ''
721
+ }
722
+ assert_equal "MESSAGE.\n#{default}", ex_message{
723
+ @tc.assert_instance_of Array, '', 'MESSAGE'
724
+ }
725
+ end
726
+ end
727
+
728
+ def test_refute_instance_of
729
+ assert_nothing_raised TinyTest::AssertError do
730
+ @tc.refute_instance_of Hash, []
731
+ end
732
+ if_flunk "refute_instance_of seems to contain bug." do
733
+ default = "Expected \"\" to not be an instance of String."
734
+ assert_equal default, ex_message{
735
+ @tc.refute_instance_of String, ''
736
+ }
737
+ assert_equal "MESSAGE.\n#{default}", ex_message{
738
+ @tc.refute_instance_of String, '', 'MESSAGE'
739
+ }
740
+ end
741
+ end
742
+
743
+ def test_assrt_kind_of
744
+ assert_nothing_raised TinyTest::AssertError do
745
+ @tc.assert_kind_of IO, STDOUT
746
+ end
747
+ if_flunk "assrt_kind_of seems to contain bug." do
748
+ default = "Expected [] to be a kind of Hash."
749
+ assert_equal default, ex_message{
750
+ @tc.assert_kind_of Hash, []
751
+ }
752
+ assert_equal "MESSAGE.\n#{default}", ex_message{
753
+ @tc.assert_kind_of Hash, [], 'MESSAGE'
754
+ }
755
+ end
756
+ end
757
+
758
+ def test_refute_kind_of
759
+ assert_nothing_raised TinyTest::AssertError do
760
+ @tc.refute_kind_of Array, 123
761
+ end
762
+ if_flunk "refute_kind_of seems to contain bug." do
763
+ default = "Expected 123 to not be a kind of Numeric."
764
+ assert_equal default, ex_message{
765
+ @tc.refute_kind_of Numeric, 123
766
+ }
767
+ assert_equal "MESSAGE.\n#{default}", ex_message{
768
+ @tc.refute_kind_of Numeric, 123, 'MESSAGE'
769
+ }
770
+ end
771
+ end
772
+
773
+ def test_assert_match
774
+ assert_nothing_raised TinyTest::AssertError do
775
+ @tc.assert_match /\A=+/, "== headline"
776
+ end
777
+ assert_nothing_raised TinyTest::AssertError do
778
+ @tc.assert_match 'bar', 'foobarbaz'
779
+ end
780
+ if_flunk "assert_match seems to contain bug." do
781
+ default = "Expected /(?!)/ to match \"hoge\"."
782
+ assert_equal default, ex_message{
783
+ @tc.assert_match /(?!)/, 'hoge'
784
+ }
785
+ assert_equal "MESSAGE.\n#{default}", ex_message{
786
+ @tc.assert_match /(?!)/, 'hoge', 'MESSAGE'
787
+ }
788
+ end
789
+ end
790
+
791
+ def test_refute_match
792
+ assert_nothing_raised TinyTest::AssertError do
793
+ @tc.refute_match /(?!)/, 'WRYYYYYYYYYYY!!!'
794
+ end
795
+ assert_nothing_raised TinyTest::AssertError do
796
+ @tc.refute_match 'hoge', 'foobarbaz'
797
+ end
798
+ if_flunk "refute_match seems to contain bug." do
799
+ default = "Expected /^[A-Z]/ to not match \"Hoge\"."
800
+ assert_equal default, ex_message{
801
+ @tc.refute_match /^[A-Z]/, 'Hoge'
802
+ }
803
+ assert_equal "MESSAGE.\n#{default}", ex_message{
804
+ @tc.refute_match /^[A-Z]/, 'Hoge', 'MESSAGE'
805
+ }
806
+ end
807
+ end
808
+
809
+ def test_assert_nil
810
+ assert_nothing_raised TinyTest::AssertError do
811
+ @tc.assert_nil nil
812
+ end
813
+ if_flunk "assert_nil seems to contain bug." do
814
+ default = "Expected 123 to be nil."
815
+ assert_equal default, ex_message{
816
+ @tc.assert_nil 123
817
+ }
818
+ assert_equal "MESSAGE.\n#{default}", ex_message{
819
+ @tc.assert_nil 123, 'MESSAGE'
820
+ }
821
+ end
822
+ end
823
+
824
+ def test_refute_nil
825
+ assert_nothing_raised TinyTest::AssertError do
826
+ @tc.refute_nil false
827
+ end
828
+ if_flunk "refute_nil seems to contain bug." do
829
+ default = "Expected nil to not be nil."
830
+ assert_equal default, ex_message{
831
+ @tc.refute_nil nil
832
+ }
833
+ assert_equal "MESSAGE.\n#{default}", ex_message{
834
+ @tc.refute_nil nil, 'MESSAGE'
835
+ }
836
+ end
837
+ end
838
+
839
+ def test_assert_same
840
+ assert_nothing_raised TinyTest::AssertError do
841
+ @tc.assert_same :hoge, :hoge
842
+ end
843
+ if_flunk "assert_same seems to contain bug." do
844
+ expected, actual = Array.new(2){ Object.new }
845
+ default = sprintf(
846
+ "Expected %s (0x%x) to be the same as %s (0x%x).",
847
+ expected.inspect, expected.object_id,
848
+ actual.inspect, actual.object_id
849
+ )
850
+ assert_equal default, ex_message{
851
+ @tc.assert_same expected, actual
852
+ }
853
+ assert_equal "MESSAGE.\n#{default}", ex_message{
854
+ @tc.assert_same expected, actual, 'MESSAGE'
855
+ }
856
+ end
857
+ end
858
+
859
+ def test_refute_same
860
+ assert_nothing_raised TinyTest::AssertError do
861
+ @tc.refute_same *Array.new(2){ Object.new }
862
+ end
863
+ if_flunk "refute_same seems to contain bug." do
864
+ default = "Expected :hoge to not be the same as :hoge."
865
+ assert_equal default, ex_message{
866
+ @tc.refute_same :hoge, :hoge
867
+ }
868
+ assert_equal "MESSAGE.\n#{default}", ex_message{
869
+ @tc.refute_same :hoge, :hoge, 'MESSAGE'
870
+ }
871
+ end
872
+ end
873
+
874
+ def test_assert_respond_to
875
+ assert_nothing_raised TinyTest::AssertError do
876
+ @tc.assert_respond_to 123, :divmod
877
+ end
878
+ if_flunk "assert_respond_to seems to contain bug." do
879
+ default = "Expected 666 (Fixnum) to respond to encoding."
880
+ assert_equal default, ex_message{
881
+ @tc.assert_respond_to 666, :encoding
882
+ }
883
+ assert_equal "MESSAGE.\n#{default}", ex_message{
884
+ @tc.assert_respond_to 666, :encoding, 'MESSAGE'
885
+ }
886
+ end
887
+ end
888
+
889
+ def test_refute_respond_to
890
+ assert_nothing_raised TinyTest::AssertError do
891
+ @tc.refute_respond_to 666, :encoding
892
+ end
893
+ if_flunk "refute_respond_to seems to contain bug." do
894
+ default = "Expected \"hoge\" to not respond to capitalize."
895
+ assert_equal default, ex_message{
896
+ @tc.refute_respond_to 'hoge', :capitalize
897
+ }
898
+ assert_equal "MESSAGE.\n#{default}", ex_message{
899
+ @tc.refute_respond_to 'hoge', :capitalize, 'MESSAGE'
900
+ }
901
+ end
902
+ end
903
+
904
+ def test_assert_empty
905
+ assert_nothing_raised TinyTest::AssertError do
906
+ @tc.assert_empty []
907
+ end
908
+ assert_raises TinyTest::AssertError do
909
+ @tc.assert_empty 666
910
+ end
911
+ if_flunk "assert_empty seems to contain bug." do
912
+ default = "Expected [1, 2, 3] to be empty."
913
+ assert_equal default, ex_message{
914
+ @tc.assert_empty [1, 2, 3]
915
+ }
916
+ assert_equal "MESSAGE.\n#{default}", ex_message{
917
+ @tc.assert_empty [1, 2, 3], 'MESSAGE'
918
+ }
919
+ end
920
+ end
921
+
922
+ def test_refute_empty
923
+ assert_nothing_raised TinyTest::AssertError do
924
+ @tc.refute_empty 'hoge'
925
+ end
926
+ assert_raises TinyTest::AssertError do
927
+ @tc.refute_empty 666
928
+ end
929
+ if_flunk "refute_empty seems to contain bug." do
930
+ default = "Expected [] to not be empty."
931
+ assert_equal default, ex_message{
932
+ @tc.refute_empty []
933
+ }
934
+ assert_equal "MESSAGE.\n#{default}", ex_message{
935
+ @tc.refute_empty [], 'MESSAGE'
936
+ }
937
+ end
938
+ end
939
+
940
+ def test_assert_includes
941
+ assert_nothing_raised TinyTest::AssertError do
942
+ @tc.assert_includes [1, 2, 3], 2
943
+ end
944
+ assert_raises TinyTest::AssertError do
945
+ @tc.assert_includes 666, 4
946
+ end
947
+ if_flunk "assert_includes seems to contain bug." do
948
+ default = "Expected [1, 2, 3] to include 666."
949
+ assert_equal default, ex_message{
950
+ @tc.assert_includes [1, 2, 3], 666
951
+ }
952
+ assert_equal "MESSAGE.\n#{default}", ex_message{
953
+ @tc.assert_includes [1, 2, 3], 666, 'MESSAGE'
954
+ }
955
+ end
956
+ end
957
+
958
+ def test_refute_includes
959
+ assert_nothing_raised TinyTest::AssertError do
960
+ @tc.refute_includes [1, 2, 3], 666
961
+ end
962
+ assert_raises TinyTest::AssertError do
963
+ @tc.assert_includes 666, 4
964
+ end
965
+ if_flunk "refute_includes seems to contain bug." do
966
+ default = %Q`Expected ["a", "b", "c"] to not include "b".`
967
+ assert_equal default, ex_message{
968
+ @tc.refute_includes %w[a b c], 'b'
969
+ }
970
+ assert_equal "MESSAGE.\n#{default}", ex_message{
971
+ @tc.refute_includes %w[a b c], 'b', 'MESSAGE'
972
+ }
973
+ end
974
+ end
975
+
976
+ def test_assert_in_delta
977
+ assert_nothing_raised TinyTest::AssertError do
978
+ @tc.assert_in_delta 1, 1
979
+ end
980
+ assert_nothing_raised TinyTest::AssertError do
981
+ @tc.assert_in_delta 1, 2, 10
982
+ end
983
+ assert_raises TinyTest::AssertError do
984
+ @tc.assert_in_delta 1, 2
985
+ end
986
+ if_flunk "assert_in_delta seems to contain bug." do
987
+ default = "Expected 1 - 10 (9) to be < %s."
988
+ assert_equal default % '0.001', ex_message{
989
+ @tc.assert_in_delta 1, 10
990
+ }
991
+ assert_equal "MESSAGE.\n#{default % '0.001'}", ex_message{
992
+ @tc.assert_in_delta 1, 10, 'MESSAGE'
993
+ }
994
+ assert_equal default % '5.0', ex_message{
995
+ @tc.assert_in_delta 1, 10, 5
996
+ }
997
+ assert_equal "MESSAGE.\n#{default % '5.0'}", ex_message{
998
+ @tc.assert_in_delta 1, 10, 5, 'MESSAGE'
999
+ }
1000
+ end
1001
+ end
1002
+
1003
+ def test_refute_in_delta
1004
+ assert_nothing_raised TinyTest::AssertError do
1005
+ @tc.refute_in_delta 1, 10
1006
+ end
1007
+ assert_nothing_raised TinyTest::AssertError do
1008
+ @tc.refute_in_delta 1, 2, 0.1
1009
+ end
1010
+ assert_raises TinyTest::AssertError do
1011
+ @tc.refute_in_delta 1, 1
1012
+ end
1013
+ if_flunk "refute_in_delta seems to contain bug." do
1014
+ default = "Expected 1 - 1 (0) to not be < %s."
1015
+ assert_equal default % '0.001', ex_message{
1016
+ @tc.refute_in_delta 1, 1
1017
+ }
1018
+ assert_equal "MESSAGE.\n#{default % '0.001'}", ex_message{
1019
+ @tc.refute_in_delta 1, 1, 'MESSAGE'
1020
+ }
1021
+ assert_equal default % '100.0', ex_message{
1022
+ @tc.refute_in_delta 1, 1, 100
1023
+ }
1024
+ assert_equal "MESSAGE.\n#{default % '100.0'}", ex_message{
1025
+ @tc.refute_in_delta 1, 1, 100, 'MESSAGE'
1026
+ }
1027
+ end
1028
+ end
1029
+
1030
+ def test_assert_in_epsilon
1031
+ assert_nothing_raised TinyTest::AssertError do
1032
+ @tc.assert_in_epsilon 1, 1
1033
+ end
1034
+ assert_nothing_raised TinyTest::AssertError do
1035
+ @tc.assert_in_epsilon 1, 2, 10
1036
+ end
1037
+ assert_raises TinyTest::AssertError do
1038
+ @tc.assert_in_epsilon 1, 2
1039
+ end
1040
+ if_flunk "assert_in_epsilon seems to contain bug." do
1041
+ default = "Expected 1 - 10 (9) to be < %s."
1042
+ assert_equal default % '0.001', ex_message{
1043
+ @tc.assert_in_epsilon 1, 10
1044
+ }
1045
+ assert_equal "MESSAGE.\n#{default % '0.001'}", ex_message{
1046
+ @tc.assert_in_epsilon 1, 10, 'MESSAGE'
1047
+ }
1048
+ end
1049
+ end
1050
+
1051
+ def test_refute_in_epsilon
1052
+ assert_nothing_raised TinyTest::AssertError do
1053
+ @tc.refute_in_epsilon 1, 10
1054
+ end
1055
+ assert_nothing_raised TinyTest::AssertError do
1056
+ @tc.refute_in_epsilon 1, 1.0001, 0.00001
1057
+ end
1058
+ assert_raises TinyTest::AssertError do
1059
+ @tc.refute_in_epsilon 1, 1.0001
1060
+ end
1061
+ if_flunk "refute_in_epsilon seems to contain bug." do
1062
+ default = "Expected 1 - 1 (0) to not be < %s."
1063
+ assert_equal default % '0.001', ex_message{
1064
+ @tc.refute_in_epsilon 1, 1
1065
+ }
1066
+ assert_equal "MESSAGE.\n#{default % '0.001'}", ex_message{
1067
+ @tc.refute_in_epsilon 1, 1, 'MESSAGE'
1068
+ }
1069
+ end
1070
+ end
1071
+
1072
+ def test_assert_operator
1073
+ assert_nothing_raised TinyTest::AssertError do
1074
+ @tc.assert_operator :hoge, :equal?, :hoge
1075
+ end
1076
+ if_flunk "assert_operator seems to contain bug." do
1077
+ default = "Expected :hoge to be == :piyo."
1078
+ assert_equal default, ex_message{
1079
+ @tc.assert_operator :hoge, :==, :piyo
1080
+ }
1081
+ assert_equal "MESSAGE.\n#{default}", ex_message{
1082
+ @tc.assert_operator :hoge, :==, :piyo, 'MESSAGE'
1083
+ }
1084
+ end
1085
+ end
1086
+
1087
+ def test_refute_operator
1088
+ assert_nothing_raised TinyTest::AssertError do
1089
+ @tc.refute_operator 'foo', :equal?, :bar
1090
+ end
1091
+ if_flunk "refute_operator seems to contain bug." do
1092
+ default = "Expected 123 to not be == 123."
1093
+ assert_equal default, ex_message{
1094
+ @tc.refute_operator 123, :==, 123
1095
+ }
1096
+ assert_equal "MESSAGE.\n#{default}", ex_message{
1097
+ @tc.refute_operator 123, :==, 123, 'MESSAGE'
1098
+ }
1099
+ end
1100
+ end
1101
+
1102
+ def test_assert_send
1103
+ assert_nothing_raised TinyTest::AssertError do
1104
+ @tc.assert_send [[1, 2, 3], :include?, 2]
1105
+ end
1106
+ if_flunk "assert_send seems to contain bug." do
1107
+ default = "Expected [1, 2, 3].include?(10) to be evaluated as true."
1108
+ assert_equal default, ex_message{
1109
+ @tc.assert_send [[1, 2, 3], :include?, 10]
1110
+ }
1111
+ assert_equal "MESSAGE.\n#{default}", ex_message{
1112
+ @tc.assert_send [[1, 2, 3], :include?, 10], 'MESSAGE'
1113
+ }
1114
+ end
1115
+ end
1116
+
1117
+ def test_refute_send
1118
+ assert_nothing_raised TinyTest::AssertError do
1119
+ @tc.refute_send [{}, :fetch, :key, nil]
1120
+ end
1121
+ if_flunk "refute_send seems to contain bug." do
1122
+ default = "Expected {:key=>123}.fetch(:key, nil) to be evaluated as false."
1123
+ assert_equal default, ex_message{
1124
+ @tc.refute_send [{:key => 123}, :fetch, :key, nil]
1125
+ }
1126
+ assert_equal "MESSAGE.\n#{default}", ex_message{
1127
+ @tc.refute_send [{:key => 123}, :fetch, :key, nil], 'MESSAGE'
1128
+ }
1129
+ end
1130
+ end
1131
+
1132
+ def test_assert_raises
1133
+ assert_nothing_raised TinyTest::AssertError do
1134
+ @tc.assert_raises(ZeroDivisionError){ 666 / 0 }
1135
+ end
1136
+ assert_raises ArgumentError do
1137
+ @tc.assert_raises{}
1138
+ end
1139
+ assert_raises LocalJumpError do
1140
+ @tc.assert_raises(RuntimeError)
1141
+ end
1142
+ if_flunk "assert_raises seems to contain bug." do
1143
+ msg = "[RuntimeError, ZeroDivisionError] expected but nothing was raised"
1144
+ assert_equal msg, ex_message{
1145
+ @tc.assert_raises([RuntimeError, ZeroDivisionError]){}
1146
+ }
1147
+ assert_match /\AMSG.\n/, ex_message{
1148
+ @tc.assert_raises(RuntimeError, 'MSG'){}
1149
+ }
1150
+ actual = nil
1151
+ actual_message = ex_message{
1152
+ @tc.assert_raises(ZeroDivisionError) do
1153
+ begin
1154
+ raise 'MSG'
1155
+ rescue => ex
1156
+ actual = ex
1157
+ raise ex
1158
+ end
1159
+ end
1160
+ }
1161
+ expected = [
1162
+ "[ZeroDivisionError] expected, but\n",
1163
+ "Class: <RuntimeError>\n",
1164
+ "Message: <MSG>\n",
1165
+ "---Backtrace---\n",
1166
+ ].join('')
1167
+ expected << actual.backtrace.reject{|b| TestUtil.start_with?(b, TINYTEST_FEATURE) }.join("\n") << "\n"
1168
+ expected << "---------------"
1169
+ assert_equal expected, actual_message
1170
+ end
1171
+ end
1172
+
1173
+ def test_refute_raises
1174
+ assert_nothing_raised TinyTest::AssertError do
1175
+ @tc.refute_raises(SystemStackError){ 666 / 0 }
1176
+ end
1177
+ assert_raises ArgumentError do
1178
+ @tc.refute_raises{}
1179
+ end
1180
+ assert_raises LocalJumpError do
1181
+ @tc.refute_raises(RuntimeError)
1182
+ end
1183
+ if_flunk "refute_raises seems to contain bug." do
1184
+ assert_match /\AMSG.\n/, ex_message{
1185
+ @tc.refute_raises(ZeroDivisionError, 'MSG'){ 666 / 0 }
1186
+ }
1187
+ actual = nil
1188
+ actual_message = ex_message{
1189
+ @tc.refute_raises(RuntimeError) do
1190
+ begin
1191
+ raise 'MSG'
1192
+ rescue => ex
1193
+ actual = ex
1194
+ raise ex
1195
+ end
1196
+ end
1197
+ }
1198
+ expected = [
1199
+ "[RuntimeError] not expected, but\n",
1200
+ "Class: <RuntimeError>\n",
1201
+ "Message: <MSG>\n",
1202
+ "---Backtrace---\n",
1203
+ ].join('')
1204
+ expected << actual.backtrace.reject{|b| TestUtil.start_with?(b, TINYTEST_FEATURE) }.join("\n") << "\n"
1205
+ expected << "---------------"
1206
+ assert_equal expected, actual_message
1207
+ end
1208
+ end
1209
+
1210
+ def uncaught_throw_ex_class
1211
+ throw :hoge
1212
+ rescue => ex
1213
+ ex.class
1214
+ else
1215
+ raise Exception, 'must not happen'
1216
+ end
1217
+
1218
+ def test_assert_throws
1219
+ assert_nothing_raised TinyTest::AssertError do
1220
+ @tc.assert_throws(:hoge){ throw :hoge }
1221
+ end
1222
+ assert_raises uncaught_throw_ex_class() do
1223
+ @tc.assert_throws(:hoge){ throw :piyo }
1224
+ end
1225
+ if_flunk "assert_throws seems to contain bug." do
1226
+ default = "Expected :hoge to have been thrown."
1227
+ assert_equal default, ex_message{
1228
+ @tc.assert_throws(:hoge){}
1229
+ }
1230
+ assert_equal "MESSAGE.\n#{default}", ex_message{
1231
+ @tc.assert_throws(:hoge, 'MESSAGE'){}
1232
+ }
1233
+ end
1234
+ end
1235
+
1236
+ def test_refute_throws
1237
+ assert_nothing_raised TinyTest::AssertError do
1238
+ @tc.refute_throws(:hoge){}
1239
+ end
1240
+ if_flunk "refute_throws seems to contain bug." do
1241
+ default = "Expected :hoge to not have been thrown."
1242
+ assert_equal default, ex_message{
1243
+ @tc.refute_throws(:hoge){ throw :hoge }
1244
+ }
1245
+ assert_equal "MESSAGE.\n#{default}", ex_message{
1246
+ @tc.refute_throws(:hoge, 'MESSAGE'){ throw :hoge }
1247
+ }
1248
+ end
1249
+ end
1250
+ end
1251
+