diff options
Diffstat (limited to 'spec/ruby/library/socket/udpsocket')
9 files changed, 58 insertions, 30 deletions
diff --git a/spec/ruby/library/socket/udpsocket/bind_spec.rb b/spec/ruby/library/socket/udpsocket/bind_spec.rb index 08b386e941..974e701e71 100644 --- a/spec/ruby/library/socket/udpsocket/bind_spec.rb +++ b/spec/ruby/library/socket/udpsocket/bind_spec.rb @@ -12,7 +12,7 @@ describe "UDPSocket#bind" do it "binds the socket to a port" do @socket.bind(SocketSpecs.hostname, 0) - @socket.addr[1].should be_kind_of(Integer) + @socket.addr[1].should.is_a?(Integer) end it "raises Errno::EINVAL when already bound" do @@ -20,7 +20,7 @@ describe "UDPSocket#bind" do -> { @socket.bind(SocketSpecs.hostname, @socket.addr[1]) - }.should raise_error(Errno::EINVAL) + }.should.raise(Errno::EINVAL) end it "receives a hostname and a port" do diff --git a/spec/ruby/library/socket/udpsocket/initialize_spec.rb b/spec/ruby/library/socket/udpsocket/initialize_spec.rb index 1d635149f7..c040187400 100644 --- a/spec/ruby/library/socket/udpsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/udpsocket/initialize_spec.rb @@ -7,34 +7,47 @@ describe 'UDPSocket#initialize' do it 'initializes a new UDPSocket' do @socket = UDPSocket.new - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'initializes a new UDPSocket using an Integer' do @socket = UDPSocket.new(Socket::AF_INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'initializes a new UDPSocket using a Symbol' do @socket = UDPSocket.new(:INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'initializes a new UDPSocket using a String' do @socket = UDPSocket.new('INET') - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'sets the socket to binmode' do @socket = UDPSocket.new(:INET) - @socket.binmode?.should be_true + @socket.binmode?.should == true + end + + platform_is_not :windows do + it 'sets the socket to nonblock' do + require 'io/nonblock' + @socket = UDPSocket.new(:INET) + @socket.should.nonblock? + end + end + + it 'sets the socket to close on exec' do + @socket = UDPSocket.new(:INET) + @socket.should.close_on_exec? end it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do -> { UDPSocket.new(666) - }.should raise_error(SystemCallError) { |e| - [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) + }.should.raise(SystemCallError) { |e| + [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should.include?(e.class) } end end diff --git a/spec/ruby/library/socket/udpsocket/local_address_spec.rb b/spec/ruby/library/socket/udpsocket/local_address_spec.rb index 92e4cc10c7..868d2f537e 100644 --- a/spec/ruby/library/socket/udpsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/udpsocket/local_address_spec.rb @@ -28,7 +28,7 @@ describe 'UDPSocket#local_address' do end it 'returns an Addrinfo' do - @sock.local_address.should be_an_instance_of(Addrinfo) + @sock.local_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/udpsocket/new_spec.rb b/spec/ruby/library/socket/udpsocket/new_spec.rb index 6cc0cadbcb..aff111927c 100644 --- a/spec/ruby/library/socket/udpsocket/new_spec.rb +++ b/spec/ruby/library/socket/udpsocket/new_spec.rb @@ -8,27 +8,33 @@ describe 'UDPSocket.new' do it 'without arguments' do @socket = UDPSocket.new - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'using Integer argument' do @socket = UDPSocket.new(Socket::AF_INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'using Symbol argument' do @socket = UDPSocket.new(:INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'using String argument' do @socket = UDPSocket.new('INET') - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) + end + + it "does not use the given block and warns to use UDPSocket::open" do + -> { + @socket = UDPSocket.new { raise } + }.should complain(/warning: UDPSocket::new\(\) does not take block; use UDPSocket::open\(\) instead/) end it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT if unsupported family passed' do - -> { UDPSocket.new(-1) }.should raise_error(SystemCallError) { |e| - [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) + -> { UDPSocket.new(-1) }.should.raise(SystemCallError) { |e| + [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should.include?(e.class) } end end diff --git a/spec/ruby/library/socket/udpsocket/open_spec.rb b/spec/ruby/library/socket/udpsocket/open_spec.rb index e4dbb2ee2a..7c77855372 100644 --- a/spec/ruby/library/socket/udpsocket/open_spec.rb +++ b/spec/ruby/library/socket/udpsocket/open_spec.rb @@ -8,6 +8,6 @@ describe "UDPSocket.open" do it "allows calls to open without arguments" do @socket = UDPSocket.open - @socket.should be_kind_of(UDPSocket) + @socket.should.is_a?(UDPSocket) end end diff --git a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb index 650a061221..460cf2c9a2 100644 --- a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb @@ -16,7 +16,7 @@ describe 'UDPSocket#recvfrom_nonblock' do platform_is_not :windows do describe 'using an unbound socket' do it 'raises IO::WaitReadable' do - -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) + -> { @server.recvfrom_nonblock(1) }.should.raise(IO::WaitReadable) end end end @@ -32,7 +32,7 @@ describe 'UDPSocket#recvfrom_nonblock' do describe 'without any data available' do it 'raises IO::WaitReadable' do - -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) + -> { @server.recvfrom_nonblock(1) }.should.raise(IO::WaitReadable) end it 'returns :wait_readable with exception: false' do @@ -48,7 +48,7 @@ describe 'UDPSocket#recvfrom_nonblock' do it 'returns an Array containing the data and an Array' do IO.select([@server]) - @server.recvfrom_nonblock(1).should be_an_instance_of(Array) + @server.recvfrom_nonblock(1).should.instance_of?(Array) end it 'writes the data to the buffer when one is present' do @@ -58,6 +58,15 @@ describe 'UDPSocket#recvfrom_nonblock' do buffer.should == 'h' end + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + IO.select([@server]) + message, = @server.recvfrom_nonblock(1, 0, buffer) + + message.should.equal?(buffer) + buffer.encoding.should == Encoding::ISO_8859_1 + end + describe 'the returned Array' do before do IO.select([@server]) @@ -69,7 +78,7 @@ describe 'UDPSocket#recvfrom_nonblock' do end it 'contains an Array at index 1' do - @array[1].should be_an_instance_of(Array) + @array[1].should.instance_of?(Array) end end diff --git a/spec/ruby/library/socket/udpsocket/remote_address_spec.rb b/spec/ruby/library/socket/udpsocket/remote_address_spec.rb index 94889ce560..d1310200fc 100644 --- a/spec/ruby/library/socket/udpsocket/remote_address_spec.rb +++ b/spec/ruby/library/socket/udpsocket/remote_address_spec.rb @@ -28,7 +28,7 @@ describe 'UDPSocket#remote_address' do end it 'returns an Addrinfo' do - @sock.remote_address.should be_an_instance_of(Addrinfo) + @sock.remote_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/udpsocket/send_spec.rb b/spec/ruby/library/socket/udpsocket/send_spec.rb index 5d5de684af..63f5b0dcc6 100644 --- a/spec/ruby/library/socket/udpsocket/send_spec.rb +++ b/spec/ruby/library/socket/udpsocket/send_spec.rb @@ -34,7 +34,7 @@ describe "UDPSocket#send" do @msg[0].should == "ad hoc" @msg[1][0].should == "AF_INET" - @msg[1][1].should be_kind_of(Integer) + @msg[1][1].should.is_a?(Integer) @msg[1][3].should == "127.0.0.1" end @@ -46,7 +46,7 @@ describe "UDPSocket#send" do @msg[0].should == "ad hoc" @msg[1][0].should == "AF_INET" - @msg[1][1].should be_kind_of(Integer) + @msg[1][1].should.is_a?(Integer) @msg[1][3].should == "127.0.0.1" end @@ -59,16 +59,16 @@ describe "UDPSocket#send" do @msg[0].should == "connection-based" @msg[1][0].should == "AF_INET" - @msg[1][1].should be_kind_of(Integer) + @msg[1][1].should.is_a?(Integer) @msg[1][3].should == "127.0.0.1" end - it "raises EMSGSIZE if data is too too big" do + it "raises EMSGSIZE if data is too big" do @socket = UDPSocket.open begin -> do @socket.send('1' * 100_000, 0, SocketSpecs.hostname, @port.to_s) - end.should raise_error(Errno::EMSGSIZE) + end.should.raise(Errno::EMSGSIZE) ensure @socket.send("ad hoc", 0, SocketSpecs.hostname, @port) @socket.close @@ -96,7 +96,7 @@ describe 'UDPSocket#send' do describe 'using a disconnected socket' do describe 'without a destination address' do it "raises #{SocketSpecs.dest_addr_req_error}" do - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end @@ -108,7 +108,7 @@ describe 'UDPSocket#send' do it 'does not persist the connection after sending data' do @client.send('hello', 0, @addr.ip_address, @addr.ip_port) - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end diff --git a/spec/ruby/library/socket/udpsocket/write_spec.rb b/spec/ruby/library/socket/udpsocket/write_spec.rb index c971f29b62..d41ee078d8 100644 --- a/spec/ruby/library/socket/udpsocket/write_spec.rb +++ b/spec/ruby/library/socket/udpsocket/write_spec.rb @@ -12,7 +12,7 @@ describe "UDPSocket#write" do -> do s2.write('1' * 100_000) - end.should raise_error(Errno::EMSGSIZE) + end.should.raise(Errno::EMSGSIZE) ensure s1.close if s1 && !s1.closed? s2.close if s2 && !s2.closed? |
