minitest 3.4.0 → 3.5.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,9 @@
1
+ === 3.5.0 / 2012-09-21
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Added #capture_subprocess_io. (route)
6
+
1
7
  === 3.4.0 / 2012-09-05
2
8
 
3
9
  * 2 minor enhancements:
@@ -307,6 +307,8 @@ module MiniTest
307
307
  # "" if you require it to be silent. Pass in a regexp if you want
308
308
  # to pattern match.
309
309
  #
310
+ # NOTE: this uses #capture_io, not #capture_subprocess_io.
311
+ #
310
312
  # See also: #assert_silent
311
313
 
312
314
  def assert_output stdout = nil, stderr = nil
@@ -439,10 +441,16 @@ module MiniTest
439
441
  # Captures $stdout and $stderr into strings:
440
442
  #
441
443
  # out, err = capture_io do
444
+ # puts "Some info"
442
445
  # warn "You did a bad thing"
443
446
  # end
444
447
  #
448
+ # assert_match %r%info%, out
445
449
  # assert_match %r%bad%, err
450
+ #
451
+ # NOTE: For efficiency, this method uses StringIO and does not
452
+ # capture IO for subprocesses. Use #capture_subprocess_io for
453
+ # that.
446
454
 
447
455
  def capture_io
448
456
  require 'stringio'
@@ -459,6 +467,42 @@ module MiniTest
459
467
  $stderr = orig_stderr
460
468
  end
461
469
 
470
+ ##
471
+ # Captures $stdout and $stderr into strings, using Tempfile to
472
+ # ensure that subprocess IO is captured as well.
473
+ #
474
+ # out, err = capture_subprocess_io do
475
+ # system "echo Some info"
476
+ # system "echo You did a bad thing 1>&2"
477
+ # end
478
+ #
479
+ # assert_match %r%info%, out
480
+ # assert_match %r%bad%, err
481
+ #
482
+ # NOTE: This method is approximately 10x slower than #capture_io so
483
+ # only use it when you need to test the output of a subprocess.
484
+
485
+ def capture_subprocess_io
486
+ require 'tempfile'
487
+
488
+ captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
489
+ orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
490
+ $stdout.reopen captured_stdout
491
+ $stderr.reopen captured_stderr
492
+
493
+ yield
494
+
495
+ $stdout.rewind
496
+ $stderr.rewind
497
+
498
+ return captured_stdout.read, captured_stderr.read
499
+ ensure
500
+ captured_stdout.unlink
501
+ captured_stderr.unlink
502
+ $stdout.reopen orig_stdout
503
+ $stderr.reopen orig_stderr
504
+ end
505
+
462
506
  ##
463
507
  # Returns details for exception +e+
464
508
 
@@ -652,7 +696,7 @@ module MiniTest
652
696
  end
653
697
 
654
698
  class Unit # :nodoc:
655
- VERSION = "3.4.0" # :nodoc:
699
+ VERSION = "3.5.0" # :nodoc:
656
700
 
657
701
  attr_accessor :report, :failures, :errors, :skips # :nodoc:
658
702
  attr_accessor :test_count, :assertion_count # :nodoc:
@@ -1174,6 +1174,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1174
1174
 
1175
1175
  orig_verbose = $VERBOSE
1176
1176
  $VERBOSE = false
1177
+
1177
1178
  out, err = capture_io do
1178
1179
  puts 'hi'
1179
1180
  warn 'bye!'
@@ -1185,6 +1186,23 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1185
1186
  $VERBOSE = orig_verbose
1186
1187
  end
1187
1188
 
1189
+ def test_capture_subprocess_io
1190
+ @assertion_count = 0
1191
+
1192
+ orig_verbose = $VERBOSE
1193
+ $VERBOSE = false
1194
+
1195
+ out, err = capture_subprocess_io do
1196
+ system("echo 'hi'")
1197
+ system("echo 'bye!' 1>&2")
1198
+ end
1199
+
1200
+ assert_equal "hi\n", out
1201
+ assert_equal "bye!\n", err
1202
+ ensure
1203
+ $VERBOSE = orig_verbose
1204
+ end
1205
+
1188
1206
  def test_class_asserts_match_refutes
1189
1207
  @assertion_count = 0
1190
1208
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 3.4.0
10
+ version: 3.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2012-09-05 00:00:00 Z
39
+ date: 2012-09-21 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
metadata.gz.sig CHANGED
Binary file