diff options
Diffstat (limited to 'spec/ruby/library/socket/unixsocket')
14 files changed, 80 insertions, 60 deletions
diff --git a/spec/ruby/library/socket/unixsocket/addr_spec.rb b/spec/ruby/library/socket/unixsocket/addr_spec.rb index e8431bea16..d93e061312 100644 --- a/spec/ruby/library/socket/unixsocket/addr_spec.rb +++ b/spec/ruby/library/socket/unixsocket/addr_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#addr" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#addr" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) diff --git a/spec/ruby/library/socket/unixsocket/initialize_spec.rb b/spec/ruby/library/socket/unixsocket/initialize_spec.rb index 13b6972f03..bf7896ab0e 100644 --- a/spec/ruby/library/socket/unixsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/unixsocket/initialize_spec.rb @@ -33,6 +33,16 @@ with_feature :unix_socket do it 'sets the socket to binmode' do @socket.binmode?.should be_true end + + it 'sets the socket to nonblock' do + require 'io/nonblock' + @socket.should.nonblock? + end + + it 'sets the socket to close on exec' do + @socket.should.close_on_exec? + end + end end end diff --git a/spec/ruby/library/socket/unixsocket/inspect_spec.rb b/spec/ruby/library/socket/unixsocket/inspect_spec.rb index d2e3cabbd3..a542ba6db5 100644 --- a/spec/ruby/library/socket/unixsocket/inspect_spec.rb +++ b/spec/ruby/library/socket/unixsocket/inspect_spec.rb @@ -1,8 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#inspect" do - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#inspect" do it "returns sockets fd for unnamed sockets" do begin s1, s2 = UNIXSocket.socketpair diff --git a/spec/ruby/library/socket/unixsocket/local_address_spec.rb b/spec/ruby/library/socket/unixsocket/local_address_spec.rb index cbf315f9f4..734253e7f5 100644 --- a/spec/ruby/library/socket/unixsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/unixsocket/local_address_spec.rb @@ -46,9 +46,7 @@ with_feature :unix_socket do end end end -end -with_feature :unix_socket do describe 'UNIXSocket#local_address with a UNIX socket pair' do before :each do @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) diff --git a/spec/ruby/library/socket/unixsocket/new_spec.rb b/spec/ruby/library/socket/unixsocket/new_spec.rb index 05a6b3eda2..6d8ea6dcfe 100644 --- a/spec/ruby/library/socket/unixsocket/new_spec.rb +++ b/spec/ruby/library/socket/unixsocket/new_spec.rb @@ -1,6 +1,14 @@ require_relative '../spec_helper' require_relative 'shared/new' -describe "UNIXSocket.new" do - it_behaves_like :unixsocket_new, :new +with_feature :unix_socket do + describe "UNIXSocket.new" do + it_behaves_like :unixsocket_new, :new + + it "does not use the given block and warns to use UNIXSocket::open" do + -> { + @client = UNIXSocket.new(@path) { raise } + }.should complain(/warning: UNIXSocket::new\(\) does not take block; use UNIXSocket::open\(\) instead/) + end + end end diff --git a/spec/ruby/library/socket/unixsocket/open_spec.rb b/spec/ruby/library/socket/unixsocket/open_spec.rb index 99ad151bb8..61def30abb 100644 --- a/spec/ruby/library/socket/unixsocket/open_spec.rb +++ b/spec/ruby/library/socket/unixsocket/open_spec.rb @@ -2,12 +2,12 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/new' -describe "UNIXSocket.open" do - it_behaves_like :unixsocket_new, :open -end +with_feature :unix_socket do + describe "UNIXSocket.open" do + it_behaves_like :unixsocket_new, :open + end -describe "UNIXSocket.open" do - platform_is_not :windows do + describe "UNIXSocket.open" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) diff --git a/spec/ruby/library/socket/unixsocket/pair_spec.rb b/spec/ruby/library/socket/unixsocket/pair_spec.rb index 845ff76ecc..d80b60894d 100644 --- a/spec/ruby/library/socket/unixsocket/pair_spec.rb +++ b/spec/ruby/library/socket/unixsocket/pair_spec.rb @@ -2,10 +2,9 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' -describe "UNIXSocket#pair" do - platform_is_not :windows do - - it_should_behave_like "partially closable sockets" +with_feature :unix_socket do + describe "UNIXSocket.pair" do + it_should_behave_like :partially_closable_sockets before :each do @s1, @s2 = UNIXSocket.pair diff --git a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb index 78a64fe6be..ef7d0f0b2a 100644 --- a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb +++ b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb @@ -2,9 +2,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' -platform_is_not :windows do +with_feature :unix_socket do describe "UNIXSocket partial closability" do - before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -19,7 +18,6 @@ platform_is_not :windows do SocketSpecs.rm_socket @path end - it_should_behave_like "partially closable sockets" - + it_should_behave_like :partially_closable_sockets end end diff --git a/spec/ruby/library/socket/unixsocket/path_spec.rb b/spec/ruby/library/socket/unixsocket/path_spec.rb index 317ffc0975..a608378e4f 100644 --- a/spec/ruby/library/socket/unixsocket/path_spec.rb +++ b/spec/ruby/library/socket/unixsocket/path_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#path" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#path" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -24,5 +23,4 @@ describe "UNIXSocket#path" do @client.path.should == "" end end - end diff --git a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb index 0b6b1ccf04..72bc96b1fe 100644 --- a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb +++ b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#peeraddr" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#peeraddr" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -26,5 +25,4 @@ describe "UNIXSocket#peeraddr" do }.should raise_error(Errno::ENOTCONN) end end - end diff --git a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb index 533f02a0fa..1dbc4538e3 100644 --- a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb +++ b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#recv_io" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#recv_io" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -41,9 +40,7 @@ describe "UNIXSocket#recv_io" do @io.should be_an_instance_of(File) end end -end -with_feature :unix_socket do describe 'UNIXSocket#recv_io' do before do @file = File.open('/dev/null', 'w') diff --git a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb index c0e1cf670b..d849fdc302 100644 --- a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb +++ b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb @@ -1,8 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#recvfrom" do - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#recvfrom" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -31,6 +31,29 @@ describe "UNIXSocket#recvfrom" do sock.close end + it "allows an output buffer as third argument" do + buffer = +'' + + @client.send("foobar", 0) + sock = @server.accept + message, = sock.recvfrom(6, 0, buffer) + sock.close + + message.should.equal?(buffer) + buffer.should == "foobar" + end + + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + + @client.send("foobar", 0) + sock = @server.accept + sock.recvfrom(6, 0, buffer) + sock.close + + buffer.encoding.should == Encoding::ISO_8859_1 + end + it "uses different message options" do @client.send("foobar", Socket::MSG_PEEK) sock = @server.accept @@ -42,10 +65,7 @@ describe "UNIXSocket#recvfrom" do sock.close end end -end - -with_feature :unix_socket do describe 'UNIXSocket#recvfrom' do describe 'using a socket pair' do before do diff --git a/spec/ruby/library/socket/unixsocket/send_io_spec.rb b/spec/ruby/library/socket/unixsocket/send_io_spec.rb index a2a7d26539..80f3550c6d 100644 --- a/spec/ruby/library/socket/unixsocket/send_io_spec.rb +++ b/spec/ruby/library/socket/unixsocket/send_io_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#send_io" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#send_io" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -32,9 +31,7 @@ describe "UNIXSocket#send_io" do @io.read.should == File.read(@send_io_path) end end -end -with_feature :unix_socket do describe 'UNIXSocket#send_io' do before do @file = File.open('/dev/null', 'w') diff --git a/spec/ruby/library/socket/unixsocket/shared/new.rb b/spec/ruby/library/socket/unixsocket/shared/new.rb index bfb7ed3886..f075b03c5e 100644 --- a/spec/ruby/library/socket/unixsocket/shared/new.rb +++ b/spec/ruby/library/socket/unixsocket/shared/new.rb @@ -2,23 +2,21 @@ require_relative '../../spec_helper' require_relative '../../fixtures/classes' describe :unixsocket_new, shared: true do - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + end - after :each do - @client.close if @client - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @client.close if @client + @server.close + SocketSpecs.rm_socket @path + end - it "opens a unix socket on the specified file" do - @client = UNIXSocket.send(@method, @path) + it "opens a unix socket on the specified file" do + @client = UNIXSocket.send(@method, @path) - @client.addr[0].should == "AF_UNIX" - @client.should_not.closed? - end + @client.addr[0].should == "AF_UNIX" + @client.should_not.closed? end end |