File: pseudo_io_spec.rb

package info (click to toggle)
ruby-passenger 3.0.13debian-1%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,920 kB
  • sloc: cpp: 99,104; ruby: 18,098; ansic: 9,846; sh: 8,632; python: 141; makefile: 30
file content (60 lines) | stat: -rw-r--r-- 1,954 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'stringio'
require 'phusion_passenger/message_channel'

module PhusionPassenger

shared_examples_for "a pseudo stderr created by #report_app_init_status" do
	before :each do
		@sink = StringIO.new
		@temp_channel = MessageChannel.new(StringIO.new)
	end
	
	after :each do
		File.unlink("output.tmp") rescue nil
	end
	
	it "redirects everything written to the pseudo STDERR/$stderr to the sink" do
		report_app_init_status(@temp_channel, @sink) do
			STDERR.puts "Something went wrong!"
			$stderr.puts "Something went wrong again!"
			raise StandardError, ":-(" if @raise_error
		end
		@sink.string.should =~ /Something went wrong!/
		@sink.string.should =~ /Something went wrong again!/
	end
	
	it "redirects reopen operations on the pseudo stderr to the sink" do
		@sink.should_receive(:reopen).with("output.tmp", "w")
		report_app_init_status(@temp_channel, @sink) do
			STDERR.reopen("output.tmp", "w")
			raise StandardError, ":-(" if @raise_error
		end
	end
	
	specify "after the function has finished, every operation on the old pseudo stderr object will still be redirected to the sink" do
		pseudo_stderr = nil
		report_app_init_status(@temp_channel, @sink) do
			pseudo_stderr = STDERR
			raise StandardError, ":-(" if @raise_error
		end
		
		pseudo_stderr.puts "hello world"
		@sink.string.should =~ /hello world/
		
		@sink.should_receive(:reopen).with("output.tmp", "w")
		pseudo_stderr.reopen("output.tmp", "w")
	end
	
	specify "after the function has finished, every output operation on the old pseudo stderr object will not be buffered" do
		pseudo_stderr = nil
		report_app_init_status(@temp_channel, @sink) do
			pseudo_stderr = STDERR
			pseudo_stderr.instance_variable_get(:@buffer).should_not be_nil
			raise StandardError, ":-(" if @raise_error
		end
		pseudo_stderr.instance_variable_get(:@buffer).should be_nil
	end
end

end # module PhusionPassenger