diff options
-rw-r--r-- | test/envutil.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/envutil.rb b/test/envutil.rb index 89332b35..05d6fe27 100644 --- a/test/envutil.rb +++ b/test/envutil.rb @@ -92,6 +92,18 @@ module EnvUtil end module_function :invoke_ruby + def verbose_warning + class << (stderr = "".dup) + alias write << + end + stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true + yield stderr + return $stderr + ensure + stderr, $stderr, $VERBOSE = $stderr, stderr, verbose + end + module_function :verbose_warning + def suppress_warning verbose, $VERBOSE = $VERBOSE, nil yield @@ -220,6 +232,17 @@ eom raise marshal_error if marshal_error end + def assert_warning(pat, msg = nil) + stderr = EnvUtil.verbose_warning { + yield + } + if Regexp === pat + assert_match pat, stderr, msg + else + assert_equal pat, stderr, msg + end + end + def message msg = nil, ending = ".", &default proc { msg = msg.call.chomp(".") if Proc === msg |