1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/rubyspec/library/socket/basicsocket/getpeername_spec.rb
eregon 2bdce358e6 Update to ruby/spec@cd1b911
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-15 12:48:52 +00:00

26 lines
798 B
Ruby

require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::BasicSocket#getpeername" do
before :each do
@server = TCPServer.new("127.0.0.1", 0)
@port = @server.addr[1]
@client = TCPSocket.new("127.0.0.1", @port)
end
after :each do
@server.close unless @server.closed?
@client.close unless @client.closed?
end
it "returns the sockaddr of the other end of the connection" do
server_sockaddr = Socket.pack_sockaddr_in(@port, "127.0.0.1")
@client.getpeername.should == server_sockaddr
end
# Catch general exceptions to prevent NotImplementedError
it "raises an error if socket's not connected" do
lambda { @server.getpeername }.should raise_error(Exception)
end
end