Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
/ proteus Public archive

Commit 99f712a

Browse files
committed
Add helper method to silence streams
1 parent c346b06 commit 99f712a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec/spec_helper.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
$LOAD_PATH << File.join('../lib')
22

33
require 'proteus'
4+
5+
def quietly
6+
streams = STDOUT, STDERR
7+
on_hold = streams.collect { |stream| stream.dup }
8+
streams.each do |stream|
9+
stream.reopen(null_stream)
10+
stream.sync = true
11+
end
12+
yield
13+
ensure
14+
streams.each_with_index do |stream, i|
15+
stream.reopen(on_hold[i])
16+
end
17+
end
18+
19+
def null_stream
20+
if RUBY_PLATFORM =~ /mswin/
21+
'NUL:'
22+
else
23+
'/dev/null'
24+
end
25+
end

0 commit comments

Comments
 (0)