minitest 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest CHANGED
@@ -10,6 +10,6 @@ Autotest.add_hook :initialize do |at|
10
10
  at.add_exception 'coverage'
11
11
  end
12
12
 
13
- require 'autotest/rcov'
14
- Autotest::RCov.command = 'rcov_info'
13
+ # require 'autotest/rcov'
14
+ # Autotest::RCov.command = 'rcov_info'
15
15
 
@@ -1,3 +1,28 @@
1
+ === 1.3.1 / 2009-01-20
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Added miniunit/autorun.rb as replacement for test/unit.rb's autorun.
6
+
7
+ * 16 bug fixes:
8
+
9
+ * 1.9 test fixes.
10
+ * Bug fixes from nobu and akira for really odd scenarios. They run ruby funny.
11
+ * Fixed (assert|refute)_match's argument order.
12
+ * Fixed LocalJumpError in autorun if exception thrown before at_exit.
13
+ * Fixed assert_in_delta (should be >=, not >).
14
+ * Fixed assert_raises to match Modules.
15
+ * Fixed capture_io to not dup IOs.
16
+ * Fixed indentation of capture_io for ruby 1.9 warning.
17
+ * Fixed location to deal better with custom assertions and load paths. (Yuki)
18
+ * Fixed order of (must|wont)_include in MiniTest::Spec.
19
+ * Fixed skip's backtrace.
20
+ * Got arg order wrong in *_match in tests, message wrong as a result.
21
+ * Made describe private. For some reason I thought that an attribute of Kernel.
22
+ * Removed disable_autorun method, added autorun.rb instead.
23
+ * assert_match escapes if passed string for pattern.
24
+ * instance_of? is different from ===, use instance_of.
25
+
1
26
  === 1.3.0 / 2008-10-09
2
27
 
3
28
  * 2 major enhancements:
@@ -3,6 +3,7 @@ History.txt
3
3
  Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
+ lib/minitest/autorun.rb
6
7
  lib/minitest/mock.rb
7
8
  lib/minitest/spec.rb
8
9
  lib/minitest/unit.rb
@@ -0,0 +1,3 @@
1
+ require 'minitest/unit'
2
+
3
+ MiniTest::Unit.autorun
@@ -54,6 +54,7 @@ module Kernel
54
54
 
55
55
  cls.class_eval(&block)
56
56
  end
57
+ private :describe
57
58
  end
58
59
 
59
60
  class MiniTest::Spec < MiniTest::Unit::TestCase
@@ -81,7 +81,7 @@ module MiniTest
81
81
  def assert_in_delta exp, act, delta = 0.001, msg = nil
82
82
  n = (exp - act).abs
83
83
  msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to be < #{delta}" }
84
- assert delta > n, msg
84
+ assert delta >= n, msg
85
85
  end
86
86
 
87
87
  def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
@@ -90,6 +90,8 @@ module MiniTest
90
90
 
91
91
  def assert_includes collection, obj, msg = nil
92
92
  msg = message(msg) { "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}" }
93
+ flip = (obj.respond_to? :include?) && ! (collection.respond_to? :include?) # HACK for specs
94
+ obj, collection = collection, obj if flip
93
95
  assert_respond_to collection, :include?
94
96
  assert collection.include?(obj), msg
95
97
  end
@@ -98,7 +100,7 @@ module MiniTest
98
100
  msg = message(msg) { "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}" }
99
101
  flip = (Module === obj) && ! (Module === cls) # HACK for specs
100
102
  obj, cls = cls, obj if flip
101
- assert cls === obj, msg
103
+ assert obj.instance_of?(cls), msg
102
104
  end
103
105
 
104
106
  def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of
@@ -110,10 +112,10 @@ module MiniTest
110
112
  end
111
113
 
112
114
  def assert_match exp, act, msg = nil
113
- msg = message(msg) { "Expected #{mu_pp(act)} to match #{mu_pp(exp)}" }
115
+ msg = message(msg) { "Expected #{mu_pp(exp)} to match #{mu_pp(act)}" }
114
116
  assert_respond_to act, :"=~"
115
- (exp = /#{exp}/) if String === exp && String === act
116
- assert act =~ exp, msg
117
+ exp = /#{Regexp.escape(exp)}/ if String === exp && String === act
118
+ assert exp =~ act, msg
117
119
  end
118
120
 
119
121
  def assert_nil obj, msg = nil
@@ -133,7 +135,10 @@ module MiniTest
133
135
  yield
134
136
  should_raise = true
135
137
  rescue Exception => e
136
- assert_includes(exp, e.class, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
138
+ assert(exp.any? { |ex|
139
+ ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
140
+ }, exception_details(e, "#{mu_pp(exp)} exception expected, not"))
141
+
137
142
  return e
138
143
  end
139
144
 
@@ -185,7 +190,7 @@ module MiniTest
185
190
  def capture_io
186
191
  require 'stringio'
187
192
 
188
- orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
193
+ orig_stdout, orig_stderr = $stdout, $stderr
189
194
  captured_stdout, captured_stderr = StringIO.new, StringIO.new
190
195
  $stdout, $stderr = captured_stdout, captured_stderr
191
196
 
@@ -252,6 +257,8 @@ module MiniTest
252
257
 
253
258
  def refute_includes collection, obj, msg = nil
254
259
  msg = message(msg) { "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}" }
260
+ flip = (obj.respond_to? :include?) && ! (collection.respond_to? :include?) # HACK for specs
261
+ obj, collection = collection, obj if flip
255
262
  assert_respond_to collection, :include?
256
263
  refute collection.include?(obj), msg
257
264
  end
@@ -260,7 +267,7 @@ module MiniTest
260
267
  msg = message(msg) { "Expected #{mu_pp(obj)} to not be an instance of #{cls}" }
261
268
  flip = (Module === obj) && ! (Module === cls) # HACK for specs
262
269
  obj, cls = cls, obj if flip
263
- refute cls === obj, msg
270
+ refute obj.instance_of?(cls), msg
264
271
  end
265
272
 
266
273
  def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of
@@ -271,8 +278,10 @@ module MiniTest
271
278
  end
272
279
 
273
280
  def refute_match exp, act, msg = nil
274
- msg = message(msg) { "Expected #{mu_pp(act)} to not match #{mu_pp(exp)}" }
275
- refute act =~ exp, msg
281
+ msg = message(msg) { "Expected #{mu_pp(exp)} to not match #{mu_pp(act)}" }
282
+ assert_respond_to act, :"=~"
283
+ exp = /#{Regexp.escape(exp)}/ if String === exp && String === act
284
+ refute exp =~ act, msg
276
285
  end
277
286
 
278
287
  def refute_nil obj, msg = nil
@@ -297,14 +306,14 @@ module MiniTest
297
306
  refute exp.equal?(act), msg
298
307
  end
299
308
 
300
- def skip msg = nil
309
+ def skip msg = nil, bt = caller
301
310
  msg ||= "Skipped, no message given"
302
- raise MiniTest::Skip, msg
311
+ raise MiniTest::Skip, msg, bt
303
312
  end
304
313
  end
305
314
 
306
315
  class Unit
307
- VERSION = "1.3.0"
316
+ VERSION = "1.3.1"
308
317
 
309
318
  attr_accessor :report, :failures, :errors, :skips
310
319
  attr_accessor :test_count, :assertion_count
@@ -314,6 +323,7 @@ module MiniTest
314
323
 
315
324
  def self.autorun
316
325
  at_exit {
326
+ next if $! # don't run if there was an exception
317
327
  exit_code = MiniTest::Unit.new.run(ARGV)
318
328
  exit false if exit_code && exit_code != 0
319
329
  } unless @@installed_at_exit
@@ -325,9 +335,12 @@ module MiniTest
325
335
  end
326
336
 
327
337
  def location e
328
- e.backtrace.find { |s|
329
- s !~ /in .(assert|refute|flunk|pass|fail|raise)/
330
- }.sub(/:in .*$/, '')
338
+ last_before_assertion = ""
339
+ e.backtrace.reverse_each do |s|
340
+ break if s =~ /in .(assert|refute|flunk|pass|fail|raise)/
341
+ last_before_assertion = s
342
+ end
343
+ last_before_assertion.sub(/:in .*$/, '')
331
344
  end
332
345
 
333
346
  def puke klass, meth, e
@@ -4,7 +4,7 @@ MiniTest::Unit.autorun
4
4
 
5
5
  describe MiniTest::Spec do
6
6
  before do
7
- @assertion_count = 5
7
+ @assertion_count = 4
8
8
  end
9
9
 
10
10
  after do
@@ -59,7 +59,7 @@ describe MiniTest::Spec do
59
59
  end
60
60
 
61
61
  it "needs to verify kinds of objects" do
62
- @assertion_count = 7
62
+ @assertion_count = 6
63
63
 
64
64
  (6 * 7).must_be_kind_of(Fixnum).must_equal true
65
65
  (6 * 7).must_be_kind_of(Numeric).must_equal true
@@ -67,7 +67,8 @@ describe MiniTest::Spec do
67
67
  end
68
68
 
69
69
  it "needs to verify regexp matches" do
70
- @assertion_count = 7
70
+ @assertion_count = 6
71
+
71
72
  "blah".must_match(/\w+/).must_equal true
72
73
  proc { "blah".must_match(/\d+/) }.must_raise MiniTest::Assertion
73
74
  end
@@ -83,14 +84,14 @@ describe MiniTest::Spec do
83
84
  end
84
85
 
85
86
  it "needs to catch an expected exception" do
86
- @assertion_count = 4
87
+ @assertion_count = 2
87
88
 
88
89
  proc { raise "blah" }.must_raise RuntimeError
89
90
  proc { raise MiniTest::Assertion }.must_raise MiniTest::Assertion
90
91
  end
91
92
 
92
93
  it "needs to catch an unexpected exception" do
93
- @assertion_count = 4
94
+ @assertion_count = 2
94
95
 
95
96
  proc {
96
97
  proc { raise MiniTest::Assertion }.must_raise(RuntimeError)
@@ -98,13 +99,13 @@ describe MiniTest::Spec do
98
99
  end
99
100
 
100
101
  it "needs raise if an expected exception is not raised" do
101
- @assertion_count = 3
102
+ @assertion_count = 2
102
103
 
103
104
  proc { proc { 42 }.must_raise(RuntimeError) }.must_raise MiniTest::Assertion
104
105
  end
105
106
 
106
107
  it "needs to be able to catch a MiniTest::Assertion exception" do
107
- @assertion_count = 3
108
+ @assertion_count = 2
108
109
 
109
110
  proc { 1.wont_equal 1 }.must_raise MiniTest::Assertion
110
111
  end
@@ -120,7 +121,7 @@ describe MiniTest::Spec do
120
121
  end
121
122
 
122
123
  it "needs to verify throw" do
123
- @assertion_count = 8
124
+ @assertion_count = 6
124
125
 
125
126
  proc { throw :blah }.must_throw(:blah).must_equal true
126
127
  proc { proc { }.must_throw(:blah) }.must_raise MiniTest::Assertion
@@ -133,6 +134,7 @@ describe MiniTest::Spec do
133
134
  end
134
135
 
135
136
  it "needs to verify mismatch" do
137
+ @assertion_count = 6
136
138
  "blah".wont_match(/\d+/).must_equal false
137
139
  proc { "blah".wont_match(/\w+/) }.must_raise MiniTest::Assertion
138
140
  end
@@ -146,4 +148,16 @@ describe MiniTest::Spec do
146
148
  1.wont_be_same_as(2).must_equal false
147
149
  proc { 1.wont_be_same_as 1 }.must_raise MiniTest::Assertion
148
150
  end
151
+
152
+ it "needs to be sensible about must_include order" do
153
+ @assertion_count = 6
154
+ [1, 2, 3].must_include(2).must_equal true
155
+ proc { [1, 2, 3].must_include 5 }.must_raise MiniTest::Assertion
156
+ end
157
+
158
+ it "needs to be sensible about wont_include order" do
159
+ @assertion_count = 6
160
+ [1, 2, 3].wont_include(5).must_equal false
161
+ proc { [1, 2, 3].wont_include 2 }.must_raise MiniTest::Assertion
162
+ end
149
163
  end
@@ -1,10 +1,13 @@
1
1
  require 'stringio'
2
+ require 'pathname'
2
3
  require 'minitest/unit'
3
4
 
4
5
  MiniTest::Unit.autorun
5
6
 
6
- class TestMiniTest < MiniTest::Unit::TestCase
7
+ module M; end
8
+ class E < StandardError; include M; end
7
9
 
10
+ class TestMiniTest < MiniTest::Unit::TestCase
8
11
  def setup
9
12
  srand 42
10
13
  MiniTest::Unit::TestCase.reset
@@ -19,22 +22,26 @@ class TestMiniTest < MiniTest::Unit::TestCase
19
22
  Object.send :remove_const, :ATestCase if defined? ATestCase
20
23
  end
21
24
 
22
- BT_MIDDLE = ["./lib/mini/test.rb:165:in `run_test_suites'",
23
- "./lib/mini/test.rb:161:in `each'",
24
- "./lib/mini/test.rb:161:in `run_test_suites'",
25
- "./lib/mini/test.rb:158:in `each'",
26
- "./lib/mini/test.rb:158:in `run_test_suites'",
27
- "./lib/mini/test.rb:139:in `run'",
28
- "./lib/mini/test.rb:106:in `run'"]
25
+ pwd = Pathname.new(File.expand_path(Dir.pwd))
26
+ basedir = Pathname.new(File.expand_path(MiniTest::MINI_DIR)) + 'mini'
27
+ basedir = basedir.relative_path_from(pwd).to_s
28
+ MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}"
29
+ BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:165:in `run_test_suites'",
30
+ "#{MINITEST_BASE_DIR}/test.rb:161:in `each'",
31
+ "#{MINITEST_BASE_DIR}/test.rb:161:in `run_test_suites'",
32
+ "#{MINITEST_BASE_DIR}/test.rb:158:in `each'",
33
+ "#{MINITEST_BASE_DIR}/test.rb:158:in `run_test_suites'",
34
+ "#{MINITEST_BASE_DIR}/test.rb:139:in `run'",
35
+ "#{MINITEST_BASE_DIR}/test.rb:106:in `run'"]
29
36
 
30
37
  def test_filter_backtrace
31
38
  # this is a semi-lame mix of relative paths.
32
39
  # I cheated by making the autotest parts not have ./
33
40
  bt = (["lib/autotest.rb:571:in `add_exception'",
34
41
  "test/test_autotest.rb:62:in `test_add_exception'",
35
- "./lib/mini/test.rb:165:in `__send__'"] +
42
+ "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
36
43
  BT_MIDDLE +
37
- ["./lib/mini/test.rb:29",
44
+ ["#{MINITEST_BASE_DIR}/test.rb:29",
38
45
  "test/test_autotest.rb:422"])
39
46
  bt = util_expand_bt bt
40
47
 
@@ -56,18 +63,18 @@ class TestMiniTest < MiniTest::Unit::TestCase
56
63
  end
57
64
 
58
65
  def test_filter_backtrace_all_unit
59
- bt = (["./lib/mini/test.rb:165:in `__send__'"] +
66
+ bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
60
67
  BT_MIDDLE +
61
- ["./lib/mini/test.rb:29"])
68
+ ["#{MINITEST_BASE_DIR}/test.rb:29"])
62
69
  ex = bt.clone
63
70
  fu = MiniTest::filter_backtrace(bt)
64
71
  assert_equal ex, fu
65
72
  end
66
73
 
67
74
  def test_filter_backtrace_unit_starts
68
- bt = (["./lib/mini/test.rb:165:in `__send__'"] +
75
+ bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
69
76
  BT_MIDDLE +
70
- ["./lib/mini/test.rb:29",
77
+ ["#{MINITEST_BASE_DIR}/mini/test.rb:29",
71
78
  "-e:1"])
72
79
 
73
80
  bt = util_expand_bt bt
@@ -83,6 +90,7 @@ class TestMiniTest < MiniTest::Unit::TestCase
83
90
  assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
84
91
  assert_equal 1, @tu.failures
85
92
  assert_match(/^Failure.*Oh no!/m, @tu.report.first)
93
+ assert_match("method_name(SomeClass) [unhappy]", @tu.report.first)
86
94
  end
87
95
 
88
96
  def test_class_puke_with_failure_and_flunk_in_backtrace
@@ -95,6 +103,72 @@ class TestMiniTest < MiniTest::Unit::TestCase
95
103
  refute @tu.report.any?{|line| line =~ /in .flunk/}
96
104
  end
97
105
 
106
+ def test_class_puke_with_assertion_failed_and_long_backtrace
107
+ bt = (["test/test_some_class.rb:615:in `method_name'",
108
+ "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
109
+ "test/test_some_class.rb:615:in `each'",
110
+ "test/test_some_class.rb:614:in `test_method_name'",
111
+ "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
112
+ BT_MIDDLE +
113
+ ["#{MINITEST_BASE_DIR}/test.rb:29"])
114
+ bt = util_expand_bt bt
115
+
116
+ ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first
117
+
118
+ exception = MiniTest::Assertion.new "Oh no!"
119
+ exception.set_backtrace bt
120
+ assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception)
121
+ assert_equal 1, @tu.failures
122
+ assert_match(/^Failure.*Oh no!/m, @tu.report.first)
123
+ assert_match("test_method_name(TestSomeClass) [#{ex_location}]", @tu.report.first)
124
+ end
125
+
126
+ def test_class_puke_with_assertion_failed_and_user_defined_assertions
127
+ bt = (["lib/test/my/util.rb:16:in `another_method_name'",
128
+ "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
129
+ "lib/test/my/util.rb:15:in `block in assert_something'",
130
+ "lib/test/my/util.rb:14:in `each'",
131
+ "lib/test/my/util.rb:14:in `assert_something'",
132
+ "test/test_some_class.rb:615:in `each'",
133
+ "test/test_some_class.rb:614:in `test_method_name'",
134
+ "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
135
+ BT_MIDDLE +
136
+ ["#{MINITEST_BASE_DIR}/test.rb:29"])
137
+ bt = util_expand_bt bt
138
+
139
+ ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first
140
+
141
+ exception = MiniTest::Assertion.new "Oh no!"
142
+ exception.set_backtrace bt
143
+ assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception)
144
+ assert_equal 1, @tu.failures
145
+ assert_match(/^Failure.*Oh no!/m, @tu.report.first)
146
+ assert_match("test_method_name(TestSomeClass) [#{ex_location}]", @tu.report.first)
147
+ end
148
+
149
+ def test_class_puke_with_flunk_and_user_defined_assertions
150
+ bt = (["lib/test/my/util.rb:16:in `flunk'",
151
+ "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
152
+ "lib/test/my/util.rb:15:in `block in assert_something'",
153
+ "lib/test/my/util.rb:14:in `each'",
154
+ "lib/test/my/util.rb:14:in `assert_something'",
155
+ "test/test_some_class.rb:615:in `each'",
156
+ "test/test_some_class.rb:614:in `test_method_name'",
157
+ "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
158
+ BT_MIDDLE +
159
+ ["#{MINITEST_BASE_DIR}/test.rb:29"])
160
+ bt = util_expand_bt bt
161
+
162
+ ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first
163
+
164
+ exception = MiniTest::Assertion.new "Oh no!"
165
+ exception.set_backtrace bt
166
+ assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception)
167
+ assert_equal 1, @tu.failures
168
+ assert_match(/^Failure.*Oh no!/m, @tu.report.first)
169
+ assert_match("test_method_name(TestSomeClass) [#{ex_location}]", @tu.report.first)
170
+ end
171
+
98
172
  def test_class_puke_with_non_failure_exception
99
173
  exception = Exception.new("Oh no again!")
100
174
  assert_equal 'E', @tu.puke('SomeClass', 'method_name', exception)
@@ -242,10 +316,10 @@ Finished in 0.00
242
316
  "
243
317
  output = @output.string.sub(/Finished in .*/, "Finished in 0.00")
244
318
  output.sub!(/Loaded suite .*/, 'Loaded suite blah')
245
- output.sub!(/[\w\/\.]+:\d+/, 'FILE:LINE')
319
+ output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE:LINE:')
320
+ output.sub!(/\[(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+\]/o, '[FILE:LINE]')
246
321
  assert_equal(expected, output)
247
- end
248
-
322
+ end
249
323
  def test_run_failing_filtered
250
324
  tc = Class.new(MiniTest::Unit::TestCase) do
251
325
  def test_something
@@ -420,7 +494,7 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
420
494
  end
421
495
 
422
496
  def test_assert_includes_triggered
423
- @assertion_count = 4
497
+ @assertion_count = 3
424
498
 
425
499
  e = @tc.assert_raises MiniTest::Assertion do
426
500
  @tc.assert_includes [true], false
@@ -452,13 +526,34 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
452
526
 
453
527
  def test_assert_match
454
528
  @assertion_count = 2
455
- @tc.assert_match "blah blah blah", /\w+/
529
+ @tc.assert_match(/\w+/, "blah blah blah")
530
+ end
531
+
532
+ def test_assert_match_object
533
+ @assertion_count = 2
534
+
535
+ pattern = Object.new
536
+ def pattern.=~(other) true end
537
+
538
+ @tc.assert_match pattern, 5
539
+ end
540
+
541
+ def test_assert_match_object_triggered
542
+ @assertion_count = 2
543
+
544
+ pattern = Object.new
545
+ def pattern.=~(other) false end
546
+ def pattern.inspect; "<<Object>>" end
547
+
548
+ util_assert_triggered 'Expected <<Object>> to match 5.' do
549
+ @tc.assert_match pattern, 5
550
+ end
456
551
  end
457
552
 
458
553
  def test_assert_match_triggered
459
554
  @assertion_count = 2
460
555
  util_assert_triggered 'Expected /\d+/ to match "blah blah blah".' do
461
- @tc.assert_match "blah blah blah", /\d+/
556
+ @tc.assert_match(/\d+/, "blah blah blah")
462
557
  end
463
558
  end
464
559
 
@@ -483,31 +578,35 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
483
578
  end
484
579
 
485
580
  def test_assert_raises
486
- @assertion_count = 2
487
-
488
581
  @tc.assert_raises RuntimeError do
489
582
  raise "blah"
490
583
  end
491
584
  end
492
585
 
493
- def test_assert_raises_triggered_different
494
- @assertion_count = 2
586
+ def test_assert_raises_module
587
+ @tc.assert_raises M do
588
+ raise E
589
+ end
590
+ end
495
591
 
592
+ def test_assert_raises_triggered_different
496
593
  e = assert_raises MiniTest::Assertion do
497
594
  @tc.assert_raises RuntimeError do
498
595
  raise SyntaxError, "icky"
499
596
  end
500
597
  end
501
598
 
502
- expected = "<[RuntimeError]> exception expected, not
599
+ expected = "[RuntimeError] exception expected, not
503
600
  Class: <SyntaxError>
504
601
  Message: <\"icky\">
505
602
  ---Backtrace---
506
603
  FILE:LINE:in `test_assert_raises_triggered_different'
507
- ---------------.
508
- Expected [RuntimeError] to include SyntaxError."
604
+ ---------------"
605
+
606
+ actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
607
+ actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/
509
608
 
510
- assert_equal expected, expected.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
609
+ assert_equal expected, actual
511
610
  end
512
611
 
513
612
  def test_assert_raises_triggered_none
@@ -522,6 +621,26 @@ Expected [RuntimeError] to include SyntaxError."
522
621
  assert_equal expected, e.message
523
622
  end
524
623
 
624
+ def test_assert_raises_triggered_subclass
625
+ e = assert_raises MiniTest::Assertion do
626
+ @tc.assert_raises StandardError do
627
+ raise E
628
+ end
629
+ end
630
+
631
+ expected = "[StandardError] exception expected, not
632
+ Class: <E>
633
+ Message: <\"E\">
634
+ ---Backtrace---
635
+ FILE:LINE:in `test_assert_raises_triggered_subclass'
636
+ ---------------"
637
+
638
+ actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
639
+ actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/
640
+
641
+ assert_equal expected, actual
642
+ end
643
+
525
644
  def test_assert_respond_to
526
645
  @tc.assert_respond_to "blah", :empty?
527
646
  end
@@ -727,7 +846,7 @@ Expected [RuntimeError] to include SyntaxError."
727
846
  end
728
847
 
729
848
  def test_refute_includes_triggered
730
- @assertion_count = 4
849
+ @assertion_count = 3
731
850
 
732
851
  e = @tc.assert_raises MiniTest::Assertion do
733
852
  @tc.refute_includes [true], true
@@ -758,12 +877,43 @@ Expected [RuntimeError] to include SyntaxError."
758
877
  end
759
878
 
760
879
  def test_refute_match
761
- @tc.refute_match "blah blah blah", /\d+/
880
+ @assertion_count = 2
881
+ @tc.refute_match(/\d+/, "blah blah blah")
882
+ end
883
+
884
+ def test_refute_match_object
885
+ @assertion_count = 2
886
+ @tc.refute_match Object.new, 5 # default #=~ returns false
887
+ end
888
+
889
+ def test_assert_object_triggered
890
+ @assertion_count = 2
891
+
892
+ pattern = Object.new
893
+ def pattern.=~(other) false end
894
+ def pattern.inspect; "<<Object>>" end
895
+
896
+ util_assert_triggered 'Expected <<Object>> to match 5.' do
897
+ @tc.assert_match pattern, 5
898
+ end
899
+ end
900
+
901
+ def test_refute_match_object_triggered
902
+ @assertion_count = 2
903
+
904
+ pattern = Object.new
905
+ def pattern.=~(other) true end
906
+ def pattern.inspect; "<<Object>>" end
907
+
908
+ util_assert_triggered 'Expected <<Object>> to not match 5.' do
909
+ @tc.refute_match pattern, 5
910
+ end
762
911
  end
763
912
 
764
913
  def test_refute_match_triggered
914
+ @assertion_count = 2
765
915
  util_assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do
766
- @tc.refute_match "blah blah blah", /\w+/
916
+ @tc.refute_match(/\w+/, "blah blah blah")
767
917
  end
768
918
  end
769
919
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-09 00:00:00 -07:00
12
+ date: 2009-01-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.8.0
23
+ version: 1.8.2
24
24
  version:
25
25
  description: minitest/unit is a small and fast replacement for ruby's huge and slow test/unit. This is meant to be clean and easy to use both as a regular test writer and for language implementors that need a minimal set of methods to bootstrap a working unit test suite. mini/spec is a functionally complete spec engine. mini/mock, by Steven Baker, is a beautifully tiny mock object framework. (This package was called miniunit once upon a time)
26
26
  email:
@@ -39,6 +39,7 @@ files:
39
39
  - Manifest.txt
40
40
  - README.txt
41
41
  - Rakefile
42
+ - lib/minitest/autorun.rb
42
43
  - lib/minitest/mock.rb
43
44
  - lib/minitest/spec.rb
44
45
  - lib/minitest/unit.rb
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  requirements: []
69
70
 
70
71
  rubyforge_project: bfts
71
- rubygems_version: 1.3.0
72
+ rubygems_version: 1.3.1
72
73
  signing_key:
73
74
  specification_version: 2
74
75
  summary: minitest/unit is a small and fast replacement for ruby's huge and slow test/unit