diff options
Diffstat (limited to 'spec/ruby/library/socket/socket')
7 files changed, 29 insertions, 6 deletions
diff --git a/spec/ruby/library/socket/socket/bind_spec.rb b/spec/ruby/library/socket/socket/bind_spec.rb index 0349df84a6..4465a3dafa 100644 --- a/spec/ruby/library/socket/socket/bind_spec.rb +++ b/spec/ruby/library/socket/socket/bind_spec.rb @@ -33,6 +33,7 @@ describe "Socket#bind on SOCK_DGRAM socket" do platform_is_not :windows, :cygwin do as_user do + break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil it "raises Errno::EACCES when the current user does not have permission to bind" do sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1") -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES) @@ -74,6 +75,7 @@ describe "Socket#bind on SOCK_STREAM socket" do platform_is_not :windows, :cygwin do as_user do + break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil it "raises Errno::EACCES when the current user does not have permission to bind" do sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1") -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES) @@ -113,6 +115,8 @@ describe 'Socket#bind' do platform_is_not :windows do as_user do + break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil + it 'raises Errno::EACCES when the user is not allowed to bind to the port' do sockaddr1 = Socket.pack_sockaddr_in(1, ip_address) diff --git a/spec/ruby/library/socket/socket/getnameinfo_spec.rb b/spec/ruby/library/socket/socket/getnameinfo_spec.rb index b406348aa8..4f13bf484d 100644 --- a/spec/ruby/library/socket/socket/getnameinfo_spec.rb +++ b/spec/ruby/library/socket/socket/getnameinfo_spec.rb @@ -70,7 +70,7 @@ describe 'Socket.getnameinfo' do it 'raises SocketError or TypeError when using an invalid String' do -> { Socket.getnameinfo('cats') }.should raise_error(Exception) { |e| - [SocketError, TypeError].should include(e.class) + (e.is_a?(SocketError) || e.is_a?(TypeError)).should == true } end diff --git a/spec/ruby/library/socket/socket/new_spec.rb b/spec/ruby/library/socket/socket/new_spec.rb deleted file mode 100644 index b2ec607f6a..0000000000 --- a/spec/ruby/library/socket/socket/new_spec.rb +++ /dev/null @@ -1,2 +0,0 @@ -require_relative '../spec_helper' -require_relative '../fixtures/classes' diff --git a/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb index 63d4724453..ef2a2d4ba9 100644 --- a/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb +++ b/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb @@ -2,6 +2,6 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/pack_sockaddr' -describe "Socket#pack_sockaddr_in" do +describe "Socket.pack_sockaddr_in" do it_behaves_like :socket_pack_sockaddr_in, :pack_sockaddr_in end diff --git a/spec/ruby/library/socket/socket/pair_spec.rb b/spec/ruby/library/socket/socket/pair_spec.rb index 292eacd38d..8dd470a95e 100644 --- a/spec/ruby/library/socket/socket/pair_spec.rb +++ b/spec/ruby/library/socket/socket/pair_spec.rb @@ -2,6 +2,6 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/socketpair' -describe "Socket#pair" do +describe "Socket.pair" do it_behaves_like :socket_socketpair, :pair end diff --git a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb index 94f58ac49f..5596f91bb8 100644 --- a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb @@ -52,6 +52,27 @@ describe 'Socket#recvfrom_nonblock' do end end + it "allows an output buffer as third argument" do + @client.write('hello') + + IO.select([@server]) + buffer = +'' + message, = @server.recvfrom_nonblock(5, 0, buffer) + + message.should.equal?(buffer) + buffer.should == 'hello' + end + + it "preserves the encoding of the given buffer" do + @client.write('hello') + + IO.select([@server]) + buffer = ''.encode(Encoding::ISO_8859_1) + @server.recvfrom_nonblock(5, 0, buffer) + + buffer.encoding.should == Encoding::ISO_8859_1 + end + describe 'the returned data' do it 'is the same as the sent data' do 5.times do diff --git a/spec/ruby/library/socket/socket/socketpair_spec.rb b/spec/ruby/library/socket/socket/socketpair_spec.rb index 5b8311124e..551c376d49 100644 --- a/spec/ruby/library/socket/socket/socketpair_spec.rb +++ b/spec/ruby/library/socket/socket/socketpair_spec.rb @@ -2,6 +2,6 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/socketpair' -describe "Socket#socketpair" do +describe "Socket.socketpair" do it_behaves_like :socket_socketpair, :socketpair end |