Sha256: 3ce6f4c168f3f90ce88ca71b1cfe45232f5fd93449e057e8f03faf054bf0cf66

Contents?: true

Size: 1.72 KB

Versions: 31

Compression:

Stored size: 1.72 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
PhusionPassenger.require_passenger_lib 'utils/unseekable_socket'

module PhusionPassenger

describe Utils::UnseekableSocket do
	class MyException < StandardError
	end
	
	class MySocket
		def write(data)
		end
		
		def gets
		end
		
		def sync=(value)
		end
	end
	
	before :each do
		@socket  = MySocket.new
		@wrapper = Utils::UnseekableSocket.wrap(@socket)
	end
	
	def catch_exception
		yield
		return nil
	rescue MyException => e
		return e
	end
	
	it "delegates method calls to the wrapped socket" do
		@socket.should_receive(:write).with("some data")
		@socket.should_receive(:gets)
		@wrapper.write("some data")
		@wrapper.gets
	end
	
	it "annotates exceptions so that we can identify its source" do
		@wrapper.source_of_exception?(MyException.new("foo")).should be_false
		
		@socket.should_receive(:write).at_least(:once).and_raise(MyException.new("an error"))
		@wrapper2 = Utils::UnseekableSocket.wrap(@socket)
		e1 = catch_exception { @wrapper.write("hello") }
		
		@wrapper.source_of_exception?(e1).should be_true
		@wrapper2.source_of_exception?(e1).should be_true
		
		@socket2 = MySocket.new
		@socket2.should_receive(:write).at_least(:once).and_raise(MyException.new("an error"))
		@wrapper.wrap(@socket2)
		@wrapper2.wrap(@socket2)
		e2 = catch_exception { @wrapper.write("hello") }
		
		@wrapper.source_of_exception?(e1).should be_false
		@wrapper2.source_of_exception?(e1).should be_false
		@wrapper.source_of_exception?(e2).should be_true
		@wrapper2.source_of_exception?(e2).should be_true
		
		Utils::UnseekableSocket.new.source_of_exception?(e1).should be_false
		Utils::UnseekableSocket.new.source_of_exception?(e2).should be_false
	end
end

end # module PhusionPassenger

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
passenger-4.0.60 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.59 test/ruby/utils/unseekable_socket_spec.rb
passenger-5.0.0.beta3 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.58 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.57 test/ruby/utils/unseekable_socket_spec.rb
passenger-5.0.0.beta2 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.56 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.55 test/ruby/utils/unseekable_socket_spec.rb
passenger-5.0.0.beta1 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.53 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.52 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.51 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.50 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.49 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.48 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.46 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.45 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.44 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.43 test/ruby/utils/unseekable_socket_spec.rb
passenger-4.0.42 test/ruby/utils/unseekable_socket_spec.rb