minitest 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,13 @@
1
+ === 1.7.0 / 2010-07-15
2
+
3
+ * 5 minor enhancements:
4
+
5
+ * Added assert_output (mapped to must_output).
6
+ * Added assert_silent (mapped to must_be_silent).
7
+ * Added examples to readme (Mike Dalessio)
8
+ * Added options output at the top of the run, for fatal run debugging (tenderlove)
9
+ * Spec's describe method returns created class
10
+
1
11
  === 1.6.0 / 2010-03-27
2
12
 
3
13
  * 10 minor enhancements:
data/README.txt CHANGED
@@ -26,6 +26,97 @@ mini/mock, by Steven Baker, is a beautifully tiny mock object framework.
26
26
 
27
27
  See design_rationale.rb to see how specs and tests work in minitest.
28
28
 
29
+ == SYNOPSIS:
30
+
31
+ Given that you'd like to test the following class:
32
+
33
+ class Meme
34
+ def i_can_has_cheezburger?
35
+ "OHAI!"
36
+ end
37
+
38
+ def does_it_blend?
39
+ "YES!"
40
+ end
41
+ end
42
+
43
+
44
+ === Unit tests
45
+
46
+ require 'minitest/unit'
47
+ MiniTest::Unit.autorun
48
+
49
+ class TestMeme < MiniTest::Unit::TestCase
50
+ def setup
51
+ @meme = Meme.new
52
+ end
53
+
54
+ def test_that_kitty_can_eat
55
+ assert_equal "OHAI!", @meme.i_can_has_cheezburger?
56
+ end
57
+
58
+ def test_that_it_doesnt_not_blend
59
+ refute_match /^no/i, @meme.does_it_blend?
60
+ end
61
+ end
62
+
63
+ === Specs
64
+
65
+ require 'minitest/spec'
66
+ MiniTest::Unit.autorun
67
+
68
+ describe Meme do
69
+ before do
70
+ @meme = Meme.new
71
+ end
72
+
73
+ describe "when asked about cheeseburgers" do
74
+ it "should respond positively" do
75
+ @meme.i_can_has_cheezburger?.must_equal "OHAI!"
76
+ end
77
+ end
78
+
79
+ describe "when asked about blending possibilities" do
80
+ it "won't say no" do
81
+ @meme.does_it_blend?.wont_match /^no/i
82
+ end
83
+ end
84
+ end
85
+
86
+ === Mocks
87
+
88
+ class MemeAsker
89
+ def initialize(meme)
90
+ @meme = meme
91
+ end
92
+
93
+ def ask(question)
94
+ method = question.tr(" ","_") + "?"
95
+ @meme.send(method)
96
+ end
97
+ end
98
+
99
+ require 'minitest/spec'
100
+ require 'minitest/mock'
101
+ MiniTest::Unit.autorun
102
+
103
+ describe MemeAsker do
104
+ before do
105
+ @meme = MiniTest::Mock.new
106
+ @meme_asker = MemeAsker.new @meme
107
+ end
108
+
109
+ describe "#ask" do
110
+ describe "when passed an unpunctuated question" do
111
+ it "should invoke the appropriate predicate method on the meme" do
112
+ @meme.expect :does_it_blend?, :return_value
113
+ @meme_asker.ask "does it blend"
114
+ @meme.verify
115
+ end
116
+ end
117
+ end
118
+ end
119
+
29
120
  == REQUIREMENTS:
30
121
 
31
122
  + Ruby 1.8, maybe even 1.6 or lower. No magic is involved.
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ Hoe.spec 'minitest' do
11
11
  developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
12
12
 
13
13
  self.rubyforge_name = "bfts"
14
+ self.testlib = :minitest
14
15
  end
15
16
 
16
17
  def loc dir
@@ -49,7 +49,7 @@ Object.infect_with_assertions(:must, :wont,
49
49
  /_in_/ => '_be_within_',
50
50
  /_operator/ => '_be',
51
51
  /_includes/ => '_include',
52
- /(must|wont)_(.*_of|nil|empty)/ => '\1_be_\2',
52
+ /(must|wont)_(.*_of|nil|silent|empty)/ => '\1_be_\2',
53
53
  /must_raises/ => 'must_raise')
54
54
 
55
55
  class Object
@@ -78,6 +78,7 @@ module Kernel
78
78
  stack.push cls
79
79
  cls.class_eval(&block)
80
80
  stack.pop
81
+ cls
81
82
  end
82
83
  private :describe
83
84
  end
@@ -196,6 +197,10 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
196
197
  # :method: must_be_same_as
197
198
  # See MiniTest::Assertions#assert_same
198
199
 
200
+ ##
201
+ # :method: must_be_silent
202
+ # See MiniTest::Assertions#assert_silent
203
+
199
204
  ##
200
205
  # :method: must_be_within_delta
201
206
  # See MiniTest::Assertions#assert_in_delta
@@ -216,6 +221,10 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
216
221
  # :method: must_match
217
222
  # See MiniTest::Assertions#assert_match
218
223
 
224
+ ##
225
+ # :method: must_output
226
+ # See MiniTest::Assertions#assert_output
227
+
219
228
  ##
220
229
  # :method: must_raise
221
230
  # See MiniTest::Assertions#assert_raises
@@ -264,6 +273,10 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
264
273
  # :method: wont_be_within_delta
265
274
  # See MiniTest::Assertions#refute_in_delta
266
275
 
276
+ ##
277
+ # :method: wont_be_within_delta
278
+ # See MiniTest::Assertions#refute_in_delta
279
+
267
280
  ##
268
281
  # :method: wont_be_within_epsilon
269
282
  # See MiniTest::Assertions#refute_in_epsilon
@@ -188,6 +188,24 @@ module MiniTest
188
188
  assert o1.__send__(op, o2), msg
189
189
  end
190
190
 
191
+ ##
192
+ # Fails if stdout or stderr do not output the expected results.
193
+ # Pass in nil if you don't care about that streams output. Pass in
194
+ # "" if you require it to be silent.
195
+ #
196
+ # See also: #assert_silent
197
+
198
+ def assert_output stdout = nil, stderr = nil
199
+ out, err = capture_io do
200
+ yield
201
+ end
202
+
203
+ x = assert_equal stdout, out, "In stdout" if stdout
204
+ y = assert_equal stderr, err, "In stderr" if stderr
205
+
206
+ (!stdout || x) && (!stderr || y)
207
+ end
208
+
191
209
  ##
192
210
  # Fails unless the block raises one of +exp+
193
211
 
@@ -245,6 +263,17 @@ module MiniTest
245
263
  assert recv.__send__(msg, *args), m
246
264
  end
247
265
 
266
+ ##
267
+ # Fails if the block outputs anything to stderr or stdout.
268
+ #
269
+ # See also: #assert_output
270
+
271
+ def assert_silent
272
+ assert_output "", "" do
273
+ yield
274
+ end
275
+ end
276
+
248
277
  ##
249
278
  # Fails unless the block throws +sym+
250
279
 
@@ -468,7 +497,7 @@ module MiniTest
468
497
  end
469
498
 
470
499
  class Unit
471
- VERSION = "1.6.0" # :nodoc:
500
+ VERSION = "1.7.0" # :nodoc:
472
501
 
473
502
  attr_accessor :report, :failures, :errors, :skips # :nodoc:
474
503
  attr_accessor :test_count, :assertion_count # :nodoc:
@@ -582,6 +611,12 @@ module MiniTest
582
611
 
583
612
  srand seed
584
613
 
614
+ help = ["--seed", seed]
615
+ help.push "--verbose" if @verbose
616
+ help.push("--name", options[:filter].inspect) if options[:filter]
617
+
618
+ @@out.puts "Test run options: #{help.join(" ")}"
619
+ @@out.puts
585
620
  @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
586
621
 
587
622
  start = Time.now
@@ -600,10 +635,6 @@ module MiniTest
600
635
 
601
636
  @@out.puts
602
637
 
603
- help = ["--seed", seed]
604
- help.push "--verbose" if @verbose
605
- help.push("--name", options[:filter].inspect) if options[:filter]
606
-
607
638
  @@out.puts "Test run options: #{help.join(" ")}"
608
639
 
609
640
  return failures + errors if @test_count > 0 # or return nil...
@@ -29,18 +29,22 @@ describe MiniTest::Spec do
29
29
  must_be_kind_of
30
30
  must_be_nil
31
31
  must_be_same_as
32
+ must_be_silent
32
33
  must_be_within_delta
33
34
  must_be_within_epsilon
34
35
  must_equal
35
36
  must_include
36
37
  must_match
38
+ must_output
37
39
  must_raise
38
40
  must_respond_to
39
41
  must_send
40
42
  must_throw)
41
43
 
44
+ bad = %w[not raise throw send output be_silent]
45
+
42
46
  expected_wonts = expected_musts.map { |m| m.sub(/^must/, 'wont') }
43
- expected_wonts.reject! { |m| m =~ /wont_(not|raise|throw|send)/ }
47
+ expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union bad}/ }
44
48
 
45
49
  musts.must_equal expected_musts
46
50
  wonts.must_equal expected_wonts
@@ -152,6 +156,32 @@ describe MiniTest::Spec do
152
156
  proc { 1.wont_be_same_as 1 }.must_raise MiniTest::Assertion
153
157
  end
154
158
 
159
+ it "needs to verify output in stdout" do
160
+ proc { print "blah" }.must_output("blah").must_equal true
161
+
162
+ proc {
163
+ proc { print "xxx" }.must_output("blah")
164
+ }.must_raise MiniTest::Assertion
165
+ end
166
+
167
+ it "needs to verify output in stderr" do
168
+ proc { $stderr.print "blah" }.must_output(nil, "blah").must_equal true
169
+
170
+ proc {
171
+ proc { $stderr.print "xxx" }.must_output(nil, "blah")
172
+ }.must_raise MiniTest::Assertion
173
+ end
174
+
175
+ it "needs to ensure silence" do
176
+ @assertion_count = 5
177
+
178
+ proc { }.must_be_silent.must_equal true
179
+
180
+ proc {
181
+ proc { print "xxx" }.must_be_silent
182
+ }.must_raise MiniTest::Assertion
183
+ end
184
+
155
185
  it "needs to be sensible about must_include order" do
156
186
  @assertion_count = 6
157
187
  [1, 2, 3].must_include(2).must_equal true
@@ -164,3 +194,26 @@ describe MiniTest::Spec do
164
194
  proc { [1, 2, 3].wont_include 2 }.must_raise MiniTest::Assertion
165
195
  end
166
196
  end
197
+
198
+ class TestMeta < MiniTest::Unit::TestCase
199
+ def test_structure
200
+ x = y = nil
201
+ x = describe "top-level thingy" do
202
+ before {}
203
+ after {}
204
+
205
+ it "top-level-it" do end
206
+
207
+ y = describe "inner thingy" do
208
+ before {}
209
+ it "inner-it" do end
210
+ end
211
+ end
212
+
213
+ top_methods = %w(setup teardown test_0001_top_level_it)
214
+ inner_methods = %w(setup test_0001_inner_it)
215
+
216
+ assert_equal top_methods, x.instance_methods(false).sort.map { |o| o.to_s }
217
+ assert_equal inner_methods, y.instance_methods(false).sort.map{|o| o.to_s }
218
+ end
219
+ end
@@ -8,20 +8,6 @@ module M; end
8
8
  class E < StandardError; include M; end
9
9
 
10
10
  class TestMiniTest < MiniTest::Unit::TestCase
11
- def setup
12
- srand 42
13
- MiniTest::Unit::TestCase.reset
14
- @tu = MiniTest::Unit.new
15
- @output = StringIO.new("")
16
- MiniTest::Unit.output = @output
17
- assert_equal [0, 0], @tu.run_test_suites
18
- end
19
-
20
- def teardown
21
- MiniTest::Unit.output = $stdout
22
- Object.send :remove_const, :ATestCase if defined? ATestCase
23
- end
24
-
25
11
  pwd = Pathname.new(File.expand_path(Dir.pwd))
26
12
  basedir = Pathname.new(File.expand_path(MiniTest::MINI_DIR)) + 'mini'
27
13
  basedir = basedir.relative_path_from(pwd).to_s
@@ -34,54 +20,37 @@ class TestMiniTest < MiniTest::Unit::TestCase
34
20
  "#{MINITEST_BASE_DIR}/test.rb:139:in `run'",
35
21
  "#{MINITEST_BASE_DIR}/test.rb:106:in `run'"]
36
22
 
37
- def test_filter_backtrace
38
- # this is a semi-lame mix of relative paths.
39
- # I cheated by making the autotest parts not have ./
40
- bt = (["lib/autotest.rb:571:in `add_exception'",
41
- "test/test_autotest.rb:62:in `test_add_exception'",
42
- "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
43
- BT_MIDDLE +
44
- ["#{MINITEST_BASE_DIR}/test.rb:29",
45
- "test/test_autotest.rb:422"])
46
- bt = util_expand_bt bt
47
-
48
- ex = ["lib/autotest.rb:571:in `add_exception'",
49
- "test/test_autotest.rb:62:in `test_add_exception'"]
50
- ex = util_expand_bt ex
23
+ def assert_report expected = nil
24
+ expected ||= "Test run options: --seed 42
51
25
 
52
- fu = MiniTest::filter_backtrace(bt)
26
+ Loaded suite blah
27
+ Started
28
+ .
29
+ Finished in 0.00
53
30
 
54
- assert_equal ex, fu
55
- end
31
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
56
32
 
57
- def util_expand_bt bt
58
- if RUBY_VERSION =~ /^1\.9/ then
59
- bt.map { |f| (f =~ /^\./) ? File.expand_path(f) : f }
60
- else
61
- bt
62
- end
33
+ Test run options: --seed 42
34
+ "
35
+ output = @output.string.sub(/Finished in .*/, "Finished in 0.00")
36
+ output.sub!(/Loaded suite .*/, 'Loaded suite blah')
37
+ output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE:LINE:')
38
+ output.sub!(/\[(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+\]/o, '[FILE:LINE]')
39
+ assert_equal(expected, output)
63
40
  end
64
41
 
65
- def test_filter_backtrace_all_unit
66
- bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
67
- BT_MIDDLE +
68
- ["#{MINITEST_BASE_DIR}/test.rb:29"])
69
- ex = bt.clone
70
- fu = MiniTest::filter_backtrace(bt)
71
- assert_equal ex, fu
42
+ def setup
43
+ srand 42
44
+ MiniTest::Unit::TestCase.reset
45
+ @tu = MiniTest::Unit.new
46
+ @output = StringIO.new("")
47
+ MiniTest::Unit.output = @output
48
+ assert_equal [0, 0], @tu.run_test_suites
72
49
  end
73
50
 
74
- def test_filter_backtrace_unit_starts
75
- bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
76
- BT_MIDDLE +
77
- ["#{MINITEST_BASE_DIR}/mini/test.rb:29",
78
- "-e:1"])
79
-
80
- bt = util_expand_bt bt
81
-
82
- ex = ["-e:1"]
83
- fu = MiniTest::filter_backtrace(bt)
84
- assert_equal ex, fu
51
+ def teardown
52
+ MiniTest::Unit.output = $stdout
53
+ Object.send :remove_const, :ATestCase if defined? ATestCase
85
54
  end
86
55
 
87
56
  def test_class_puke_with_assertion_failed
@@ -93,16 +62,6 @@ class TestMiniTest < MiniTest::Unit::TestCase
93
62
  assert_match("method_name(SomeClass) [unhappy]", @tu.report.first)
94
63
  end
95
64
 
96
- def test_class_puke_with_failure_and_flunk_in_backtrace
97
- exception = begin
98
- MiniTest::Unit::TestCase.new('fake tc').flunk
99
- rescue MiniTest::Assertion => failure
100
- failure
101
- end
102
- assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
103
- refute @tu.report.any?{|line| line =~ /in .flunk/}
104
- end
105
-
106
65
  def test_class_puke_with_assertion_failed_and_long_backtrace
107
66
  bt = (["test/test_some_class.rb:615:in `method_name'",
108
67
  "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
@@ -146,6 +105,16 @@ class TestMiniTest < MiniTest::Unit::TestCase
146
105
  assert_match("test_method_name(TestSomeClass) [#{ex_location}]", @tu.report.first)
147
106
  end
148
107
 
108
+ def test_class_puke_with_failure_and_flunk_in_backtrace
109
+ exception = begin
110
+ MiniTest::Unit::TestCase.new('fake tc').flunk
111
+ rescue MiniTest::Assertion => failure
112
+ failure
113
+ end
114
+ assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
115
+ refute @tu.report.any?{|line| line =~ /in .flunk/}
116
+ end
117
+
149
118
  def test_class_puke_with_flunk_and_user_defined_assertions
150
119
  bt = (["lib/test/my/util.rb:16:in `flunk'",
151
120
  "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
@@ -188,35 +157,46 @@ class TestMiniTest < MiniTest::Unit::TestCase
188
157
  assert_equal [1, 1], @tu.run_test_suites
189
158
  end
190
159
 
191
- def test_run_failing # TODO: add error test
192
- tc = Class.new(MiniTest::Unit::TestCase) do
193
- def test_something
194
- assert true
195
- end
160
+ def test_filter_backtrace
161
+ # this is a semi-lame mix of relative paths.
162
+ # I cheated by making the autotest parts not have ./
163
+ bt = (["lib/autotest.rb:571:in `add_exception'",
164
+ "test/test_autotest.rb:62:in `test_add_exception'",
165
+ "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
166
+ BT_MIDDLE +
167
+ ["#{MINITEST_BASE_DIR}/test.rb:29",
168
+ "test/test_autotest.rb:422"])
169
+ bt = util_expand_bt bt
196
170
 
197
- def test_failure
198
- assert false
199
- end
200
- end
171
+ ex = ["lib/autotest.rb:571:in `add_exception'",
172
+ "test/test_autotest.rb:62:in `test_add_exception'"]
173
+ ex = util_expand_bt ex
201
174
 
202
- Object.const_set(:ATestCase, tc)
175
+ fu = MiniTest::filter_backtrace(bt)
203
176
 
204
- @tu.run %w[-s 42]
177
+ assert_equal ex, fu
178
+ end
205
179
 
206
- expected = "Loaded suite blah
207
- Started
208
- F.
209
- Finished in 0.00
180
+ def test_filter_backtrace_all_unit
181
+ bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
182
+ BT_MIDDLE +
183
+ ["#{MINITEST_BASE_DIR}/test.rb:29"])
184
+ ex = bt.clone
185
+ fu = MiniTest::filter_backtrace(bt)
186
+ assert_equal ex, fu
187
+ end
210
188
 
211
- 1) Failure:
212
- test_failure(ATestCase) [FILE:LINE]:
213
- Failed assertion, no message given.
189
+ def test_filter_backtrace_unit_starts
190
+ bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
191
+ BT_MIDDLE +
192
+ ["#{MINITEST_BASE_DIR}/mini/test.rb:29",
193
+ "-e:1"])
214
194
 
215
- 2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
195
+ bt = util_expand_bt bt
216
196
 
217
- Test run options: --seed 42
218
- "
219
- util_assert_report expected
197
+ ex = ["-e:1"]
198
+ fu = MiniTest::filter_backtrace(bt)
199
+ assert_equal ex, fu
220
200
  end
221
201
 
222
202
  def test_run_error
@@ -234,7 +214,9 @@ Test run options: --seed 42
234
214
 
235
215
  @tu.run %w[-s 42]
236
216
 
237
- expected = "Loaded suite blah
217
+ expected = "Test run options: --seed 42
218
+
219
+ Loaded suite blah
238
220
  Started
239
221
  E.
240
222
  Finished in 0.00
@@ -248,7 +230,7 @@ RuntimeError: unhandled exception
248
230
 
249
231
  Test run options: --seed 42
250
232
  "
251
- util_assert_report expected
233
+ assert_report expected
252
234
  end
253
235
 
254
236
  def test_run_error_teardown
@@ -266,7 +248,9 @@ Test run options: --seed 42
266
248
 
267
249
  @tu.run %w[-s 42]
268
250
 
269
- expected = "Loaded suite blah
251
+ expected = "Test run options: --seed 42
252
+
253
+ Loaded suite blah
270
254
  Started
271
255
  E
272
256
  Finished in 0.00
@@ -280,17 +264,17 @@ RuntimeError: unhandled exception
280
264
 
281
265
  Test run options: --seed 42
282
266
  "
283
- util_assert_report expected
267
+ assert_report expected
284
268
  end
285
269
 
286
- def test_run_skip
270
+ def test_run_failing # TODO: add error test
287
271
  tc = Class.new(MiniTest::Unit::TestCase) do
288
272
  def test_something
289
273
  assert true
290
274
  end
291
275
 
292
- def test_skip
293
- skip "not yet"
276
+ def test_failure
277
+ assert false
294
278
  end
295
279
  end
296
280
 
@@ -298,37 +282,22 @@ Test run options: --seed 42
298
282
 
299
283
  @tu.run %w[-s 42]
300
284
 
301
- expected = "Loaded suite blah
302
- Started
303
- S.
304
- Finished in 0.00
285
+ expected = "Test run options: --seed 42
305
286
 
306
- 1) Skipped:
307
- test_skip(ATestCase) [FILE:LINE]:
308
- not yet
309
-
310
- 2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
311
-
312
- Test run options: --seed 42
313
- "
314
- util_assert_report expected
315
- end
316
-
317
- def util_assert_report expected = nil
318
- expected ||= "Loaded suite blah
287
+ Loaded suite blah
319
288
  Started
320
- .
289
+ F.
321
290
  Finished in 0.00
322
291
 
323
- 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
292
+ 1) Failure:
293
+ test_failure(ATestCase) [FILE:LINE]:
294
+ Failed assertion, no message given.
295
+
296
+ 2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
324
297
 
325
298
  Test run options: --seed 42
326
299
  "
327
- output = @output.string.sub(/Finished in .*/, "Finished in 0.00")
328
- output.sub!(/Loaded suite .*/, 'Loaded suite blah')
329
- output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE:LINE:')
330
- output.sub!(/\[(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+\]/o, '[FILE:LINE]')
331
- assert_equal(expected, output)
300
+ assert_report expected
332
301
  end
333
302
 
334
303
  def test_run_failing_filtered
@@ -346,7 +315,9 @@ Test run options: --seed 42
346
315
 
347
316
  @tu.run %w[-n /something/ -s 42]
348
317
 
349
- expected = "Loaded suite blah
318
+ expected = "Test run options: --seed 42 --name \"/something/\"
319
+
320
+ Loaded suite blah
350
321
  Started
351
322
  .
352
323
  Finished in 0.00
@@ -355,7 +326,7 @@ Finished in 0.00
355
326
 
356
327
  Test run options: --seed 42 --name \"/something/\"
357
328
  "
358
- util_assert_report expected
329
+ assert_report expected
359
330
  end
360
331
 
361
332
  def test_run_passing
@@ -369,7 +340,48 @@ Test run options: --seed 42 --name \"/something/\"
369
340
 
370
341
  @tu.run %w[-s 42]
371
342
 
372
- util_assert_report
343
+ assert_report
344
+ end
345
+
346
+ def test_run_skip
347
+ tc = Class.new(MiniTest::Unit::TestCase) do
348
+ def test_something
349
+ assert true
350
+ end
351
+
352
+ def test_skip
353
+ skip "not yet"
354
+ end
355
+ end
356
+
357
+ Object.const_set(:ATestCase, tc)
358
+
359
+ @tu.run %w[-s 42]
360
+
361
+ expected = "Test run options: --seed 42
362
+
363
+ Loaded suite blah
364
+ Started
365
+ S.
366
+ Finished in 0.00
367
+
368
+ 1) Skipped:
369
+ test_skip(ATestCase) [FILE:LINE]:
370
+ not yet
371
+
372
+ 2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
373
+
374
+ Test run options: --seed 42
375
+ "
376
+ assert_report expected
377
+ end
378
+
379
+ def util_expand_bt bt
380
+ if RUBY_VERSION =~ /^1\.9/ then
381
+ bt.map { |f| (f =~ /^\./) ? File.expand_path(f) : f }
382
+ else
383
+ bt
384
+ end
373
385
  end
374
386
  end
375
387
 
@@ -388,39 +400,6 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
388
400
  Object.send :remove_const, :ATestCase if defined? ATestCase
389
401
  end
390
402
 
391
- def test_class_inherited
392
- @assertion_count = 0
393
-
394
- Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))
395
-
396
- assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
397
- end
398
-
399
- def test_class_test_suites
400
- @assertion_count = 0
401
-
402
- Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))
403
-
404
- assert_equal 1, MiniTest::Unit::TestCase.test_suites.size
405
- assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
406
- end
407
-
408
- def test_class_asserts_match_refutes
409
- @assertion_count = 0
410
-
411
- methods = MiniTest::Assertions.public_instance_methods
412
- methods.map! { |m| m.to_s } if Symbol === methods.first
413
-
414
- ignores = %w(assert_block assert_no_match assert_not_equal assert_not_nil
415
- assert_not_same assert_nothing_thrown assert_raise
416
- assert_nothing_raised assert_raises assert_throws assert_send)
417
- asserts = methods.grep(/^assert/).sort - ignores
418
- refutes = methods.grep(/^refute/).sort - ignores
419
-
420
- assert_empty refutes.map { |n| n.sub(/^refute/, 'assert') } - asserts
421
- assert_empty asserts.map { |n| n.sub(/^assert/, 'refute') } - refutes
422
- end
423
-
424
403
  def test_assert
425
404
  @assertion_count = 2
426
405
 
@@ -597,6 +576,60 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
597
576
  end
598
577
  end
599
578
 
579
+ def test_assert_output_both
580
+ @assertion_count = 2
581
+
582
+ @tc.assert_output "yay", "blah" do
583
+ print "yay"
584
+ $stderr.print "blah"
585
+ end
586
+ end
587
+
588
+ def test_assert_output_err
589
+ @tc.assert_output nil, "blah" do
590
+ $stderr.print "blah"
591
+ end
592
+ end
593
+
594
+ def test_assert_output_neither
595
+ @assertion_count = 0
596
+
597
+ @tc.assert_output do
598
+ # do nothing
599
+ end
600
+ end
601
+
602
+ def test_assert_output_out
603
+ @tc.assert_output "blah" do
604
+ print "blah"
605
+ end
606
+ end
607
+
608
+ def test_assert_output_triggered_both
609
+ util_assert_triggered "In stdout.\nExpected \"yay\", not \"boo\"." do
610
+ @tc.assert_output "yay", "blah" do
611
+ print "boo"
612
+ $stderr.print "blah blah"
613
+ end
614
+ end
615
+ end
616
+
617
+ def test_assert_output_triggered_err
618
+ util_assert_triggered "In stderr.\nExpected \"blah\", not \"blah blah\"." do
619
+ @tc.assert_output nil, "blah" do
620
+ $stderr.print "blah blah"
621
+ end
622
+ end
623
+ end
624
+
625
+ def test_assert_output_triggered_out
626
+ util_assert_triggered "In stdout.\nExpected \"blah\", not \"blah blah\"." do
627
+ @tc.assert_output "blah" do
628
+ print "blah blah"
629
+ end
630
+ end
631
+ end
632
+
600
633
  def test_assert_raises
601
634
  @tc.assert_raises RuntimeError do
602
635
  raise "blah"
@@ -738,6 +771,32 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
738
771
  end
739
772
  end
740
773
 
774
+ def test_assert_silent
775
+ @assertion_count = 2
776
+
777
+ @tc.assert_silent do
778
+ # do nothing
779
+ end
780
+ end
781
+
782
+ def test_assert_silent_triggered_err
783
+ @assertion_count = 2
784
+
785
+ util_assert_triggered "In stderr.\nExpected \"\", not \"blah blah\"." do
786
+ @tc.assert_silent do
787
+ $stderr.print "blah blah"
788
+ end
789
+ end
790
+ end
791
+
792
+ def test_assert_silent_triggered_out
793
+ util_assert_triggered "In stdout.\nExpected \"\", not \"blah blah\"." do
794
+ @tc.assert_silent do
795
+ print "blah blah"
796
+ end
797
+ end
798
+ end
799
+
741
800
  def test_assert_throws
742
801
  @tc.assert_throws(:blah) do
743
802
  throw :blah
@@ -772,6 +831,41 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
772
831
  assert_equal "bye!\n", err
773
832
  end
774
833
 
834
+ def test_class_asserts_match_refutes
835
+ @assertion_count = 0
836
+
837
+ methods = MiniTest::Assertions.public_instance_methods
838
+ methods.map! { |m| m.to_s } if Symbol === methods.first
839
+
840
+ ignores = %w(assert_block assert_no_match assert_not_equal
841
+ assert_not_nil assert_not_same assert_nothing_raised
842
+ assert_nothing_thrown assert_output assert_raise
843
+ assert_raises assert_send assert_silent assert_throws)
844
+
845
+ asserts = methods.grep(/^assert/).sort - ignores
846
+ refutes = methods.grep(/^refute/).sort - ignores
847
+
848
+ assert_empty refutes.map { |n| n.sub(/^refute/, 'assert') } - asserts
849
+ assert_empty asserts.map { |n| n.sub(/^assert/, 'refute') } - refutes
850
+ end
851
+
852
+ def test_class_inherited
853
+ @assertion_count = 0
854
+
855
+ Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))
856
+
857
+ assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
858
+ end
859
+
860
+ def test_class_test_suites
861
+ @assertion_count = 0
862
+
863
+ Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))
864
+
865
+ assert_equal 1, MiniTest::Unit::TestCase.test_suites.size
866
+ assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
867
+ end
868
+
775
869
  def test_flunk
776
870
  util_assert_triggered 'Epic Fail!' do
777
871
  @tc.flunk
@@ -796,34 +890,6 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
796
890
  @tc.pass
797
891
  end
798
892
 
799
- def test_test_methods_sorted
800
- @assertion_count = 0
801
-
802
- sample_test_case = Class.new(MiniTest::Unit::TestCase) do
803
- def self.test_order; :sorted end
804
- def test_test3; assert "does not matter" end
805
- def test_test2; assert "does not matter" end
806
- def test_test1; assert "does not matter" end
807
- end
808
-
809
- expected = %w(test_test1 test_test2 test_test3)
810
- assert_equal expected, sample_test_case.test_methods
811
- end
812
-
813
- def test_test_methods_random
814
- @assertion_count = 0
815
-
816
- sample_test_case = Class.new(MiniTest::Unit::TestCase) do
817
- def test_test1; assert "does not matter" end
818
- def test_test2; assert "does not matter" end
819
- def test_test3; assert "does not matter" end
820
- end
821
-
822
- srand 42
823
- expected = %w(test_test2 test_test1 test_test3)
824
- assert_equal expected, sample_test_case.test_methods
825
- end
826
-
827
893
  def test_refute
828
894
  @assertion_count = 2
829
895
 
@@ -922,18 +988,6 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
922
988
  @tc.refute_match Object.new, 5 # default #=~ returns false
923
989
  end
924
990
 
925
- def test_assert_object_triggered
926
- @assertion_count = 2
927
-
928
- pattern = Object.new
929
- def pattern.=~(other) false end
930
- def pattern.inspect; "<<Object>>" end
931
-
932
- util_assert_triggered 'Expected <<Object>> to match 5.' do
933
- @tc.assert_match pattern, 5
934
- end
935
- end
936
-
937
991
  def test_refute_match_object_triggered
938
992
  @assertion_count = 2
939
993
 
@@ -1001,6 +1055,34 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
1001
1055
  end
1002
1056
  end
1003
1057
 
1058
+ def test_test_methods_random
1059
+ @assertion_count = 0
1060
+
1061
+ sample_test_case = Class.new(MiniTest::Unit::TestCase) do
1062
+ def test_test1; assert "does not matter" end
1063
+ def test_test2; assert "does not matter" end
1064
+ def test_test3; assert "does not matter" end
1065
+ end
1066
+
1067
+ srand 42
1068
+ expected = %w(test_test2 test_test1 test_test3)
1069
+ assert_equal expected, sample_test_case.test_methods
1070
+ end
1071
+
1072
+ def test_test_methods_sorted
1073
+ @assertion_count = 0
1074
+
1075
+ sample_test_case = Class.new(MiniTest::Unit::TestCase) do
1076
+ def self.test_order; :sorted end
1077
+ def test_test3; assert "does not matter" end
1078
+ def test_test2; assert "does not matter" end
1079
+ def test_test1; assert "does not matter" end
1080
+ end
1081
+
1082
+ expected = %w(test_test1 test_test2 test_test3)
1083
+ assert_equal expected, sample_test_case.test_methods
1084
+ end
1085
+
1004
1086
  def util_assert_triggered expected, klass = MiniTest::Assertion
1005
1087
  e = assert_raises(klass) do
1006
1088
  yield
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 6
8
+ - 7
8
9
  - 0
9
- version: 1.6.0
10
+ version: 1.7.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ryan Davis
@@ -35,49 +36,55 @@ cert_chain:
35
36
  FBHgymkyj/AOSqKRIpXPhjC6
36
37
  -----END CERTIFICATE-----
37
38
 
38
- date: 2010-03-27 00:00:00 -07:00
39
+ date: 2010-07-15 00:00:00 -07:00
39
40
  default_executable:
40
41
  dependencies:
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rubyforge
43
44
  prerelease: false
44
45
  requirement: &id001 !ruby/object:Gem::Requirement
46
+ none: false
45
47
  requirements:
46
48
  - - ">="
47
49
  - !ruby/object:Gem::Version
50
+ hash: 7
48
51
  segments:
49
52
  - 2
50
53
  - 0
51
- - 3
52
- version: 2.0.3
54
+ - 4
55
+ version: 2.0.4
53
56
  type: :development
54
57
  version_requirements: *id001
55
58
  - !ruby/object:Gem::Dependency
56
59
  name: minitest
57
60
  prerelease: false
58
61
  requirement: &id002 !ruby/object:Gem::Requirement
62
+ none: false
59
63
  requirements:
60
64
  - - ">="
61
65
  - !ruby/object:Gem::Version
66
+ hash: 15
62
67
  segments:
63
68
  - 1
64
- - 5
69
+ - 6
65
70
  - 0
66
- version: 1.5.0
71
+ version: 1.6.0
67
72
  type: :development
68
73
  version_requirements: *id002
69
74
  - !ruby/object:Gem::Dependency
70
75
  name: hoe
71
76
  prerelease: false
72
77
  requirement: &id003 !ruby/object:Gem::Requirement
78
+ none: false
73
79
  requirements:
74
80
  - - ">="
75
81
  - !ruby/object:Gem::Version
82
+ hash: 21
76
83
  segments:
77
84
  - 2
78
85
  - 6
79
- - 0
80
- version: 2.6.0
86
+ - 1
87
+ version: 2.6.1
81
88
  type: :development
82
89
  version_requirements: *id003
83
90
  description: |-
@@ -126,23 +133,27 @@ rdoc_options:
126
133
  require_paths:
127
134
  - lib
128
135
  required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
129
137
  requirements:
130
138
  - - ">="
131
139
  - !ruby/object:Gem::Version
140
+ hash: 3
132
141
  segments:
133
142
  - 0
134
143
  version: "0"
135
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
136
146
  requirements:
137
147
  - - ">="
138
148
  - !ruby/object:Gem::Version
149
+ hash: 3
139
150
  segments:
140
151
  - 0
141
152
  version: "0"
142
153
  requirements: []
143
154
 
144
155
  rubyforge_project: bfts
145
- rubygems_version: 1.3.6
156
+ rubygems_version: 1.3.7
146
157
  signing_key:
147
158
  specification_version: 3
148
159
  summary: minitest/unit is a small and fast replacement for ruby's huge and slow test/unit
metadata.gz.sig CHANGED
Binary file