Sha256: 1aaa97765519a9c42c0db86ffbf436bb4b06bfc34c0c1222ccf15392bf4e55b3
Contents?: true
Size: 1.67 KB
Versions: 8
Compression:
Stored size: 1.67 KB
Contents
require 'spec_helper' require 'stringio' describe 'Kernel#warn' do before do @fake_stderr = StringIO.new end it 'writes single message to $stderr if $VERBOSE is true' do old_verbose = $VERBOSE $VERBOSE = true captured_stderr { warn 'this is a warning message' }.should == 'this is a warning message' $VERBOSE = old_verbose end it 'writes multiple messages to $stderr if $VERBOSE is true' do old_verbose = $VERBOSE $VERBOSE = true captured_stderr { warn 'this is a warning message', 'this is another' }.should == "this is a warning message\nthis is another" $VERBOSE = old_verbose end it 'does not write empty message to $stderr if $VERBOSE is true' do old_verbose = $VERBOSE $VERBOSE = true captured_stderr { warn }.should be_nil $VERBOSE = old_verbose end it 'does write message to $stderr if $VERBOSE is false' do old_verbose = $VERBOSE $VERBOSE = false captured_stderr { warn 'this is a warning message' }.should == 'this is a warning message' $VERBOSE = old_verbose end it 'does not write message to $stderr if $VERBOSE is nil' do old_verbose = $VERBOSE $VERBOSE = nil captured_stderr { warn 'this is a warning message' }.should be_nil $VERBOSE = old_verbose end it 'returns a nil value' do old_verbose = $VERBOSE $VERBOSE = true captured_stderr { (warn 'this is a warning message').should be_nil } $VERBOSE = old_verbose end def captured_stderr original_stderr = $stderr $stderr = @fake_stderr yield @fake_stderr.tap(&:rewind).read ensure $stderr = original_stderr end end
Version data entries
8 entries across 8 versions & 1 rubygems