summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/unixserver
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/socket/unixserver')
-rw-r--r--spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb58
-rw-r--r--spec/ruby/library/socket/unixserver/accept_spec.rb58
-rw-r--r--spec/ruby/library/socket/unixserver/for_fd_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixserver/initialize_spec.rb28
-rw-r--r--spec/ruby/library/socket/unixserver/listen_spec.rb21
-rw-r--r--spec/ruby/library/socket/unixserver/new_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixserver/open_spec.rb3
-rw-r--r--spec/ruby/library/socket/unixserver/shared/new.rb3
-rw-r--r--spec/ruby/library/socket/unixserver/sysaccept_spec.rb52
9 files changed, 220 insertions, 7 deletions
diff --git a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
index 27603aeabd..3ebe38a090 100644
--- a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
+++ b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXServer#accept_nonblock" do
@@ -34,3 +34,59 @@ describe "UNIXServer#accept_nonblock" do
end
end
end
+
+with_feature :unix_socket do
+ describe 'UNIXServer#accept_nonblock' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close
+ rm_r(@path)
+ end
+
+ describe 'without a client' do
+ it 'raises IO::WaitReadable' do
+ lambda { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
+ end
+ end
+
+ describe 'with a client' do
+ before do
+ @client = UNIXSocket.new(@path)
+ end
+
+ after do
+ @client.close
+ @socket.close if @socket
+ end
+
+ describe 'without any data' do
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept_nonblock
+ @socket.should be_an_instance_of(UNIXSocket)
+ end
+ end
+
+ describe 'with data available' do
+ before do
+ @client.write('hello')
+ end
+
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept_nonblock
+ @socket.should be_an_instance_of(UNIXSocket)
+ end
+
+ describe 'the returned UNIXSocket' do
+ it 'can read the data written' do
+ @socket = @server.accept_nonblock
+ @socket.recv(5).should == 'hello'
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixserver/accept_spec.rb b/spec/ruby/library/socket/unixserver/accept_spec.rb
index 3c34fce59a..a1570f7013 100644
--- a/spec/ruby/library/socket/unixserver/accept_spec.rb
+++ b/spec/ruby/library/socket/unixserver/accept_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
platform_is_not :windows do
@@ -59,3 +59,59 @@ platform_is_not :windows do
end
end
end
+
+with_feature :unix_socket do
+ describe 'UNIXServer#accept' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close
+ rm_r(@path)
+ end
+
+ describe 'without a client' do
+ it 'blocks the calling thread' do
+ lambda { @server.accept }.should block_caller
+ end
+ end
+
+ describe 'with a client' do
+ before do
+ @client = UNIXSocket.new(@path)
+ end
+
+ after do
+ @client.close
+ @socket.close if @socket
+ end
+
+ describe 'without any data' do
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept
+ @socket.should be_an_instance_of(UNIXSocket)
+ end
+ end
+
+ describe 'with data available' do
+ before do
+ @client.write('hello')
+ end
+
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept
+ @socket.should be_an_instance_of(UNIXSocket)
+ end
+
+ describe 'the returned UNIXSocket' do
+ it 'can read the data written' do
+ @socket = @server.accept
+ @socket.recv(5).should == 'hello'
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixserver/for_fd_spec.rb b/spec/ruby/library/socket/unixserver/for_fd_spec.rb
index 9f243c50a8..4f3816ad37 100644
--- a/spec/ruby/library/socket/unixserver/for_fd_spec.rb
+++ b/spec/ruby/library/socket/unixserver/for_fd_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
platform_is_not :windows do
diff --git a/spec/ruby/library/socket/unixserver/initialize_spec.rb b/spec/ruby/library/socket/unixserver/initialize_spec.rb
new file mode 100644
index 0000000000..cb186ceb76
--- /dev/null
+++ b/spec/ruby/library/socket/unixserver/initialize_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+with_feature :unix_socket do
+ describe 'UNIXServer#initialize' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close if @server
+ rm_r @path
+ end
+
+ it 'returns a new UNIXServer' do
+ @server.should be_an_instance_of(UNIXServer)
+ end
+
+ it 'sets the socket to binmode' do
+ @server.binmode?.should be_true
+ end
+
+ it 'raises Errno::EADDRINUSE when the socket is already in use' do
+ lambda { UNIXServer.new(@path) }.should raise_error(Errno::EADDRINUSE)
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixserver/listen_spec.rb b/spec/ruby/library/socket/unixserver/listen_spec.rb
new file mode 100644
index 0000000000..b90b3bbb09
--- /dev/null
+++ b/spec/ruby/library/socket/unixserver/listen_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+with_feature :unix_socket do
+ describe 'UNIXServer#listen' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close
+
+ rm_r(@path)
+ end
+
+ it 'returns 0' do
+ @server.listen(1).should == 0
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixserver/new_spec.rb b/spec/ruby/library/socket/unixserver/new_spec.rb
index 0523054952..f831f40bc6 100644
--- a/spec/ruby/library/socket/unixserver/new_spec.rb
+++ b/spec/ruby/library/socket/unixserver/new_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative 'shared/new'
describe "UNIXServer.new" do
diff --git a/spec/ruby/library/socket/unixserver/open_spec.rb b/spec/ruby/library/socket/unixserver/open_spec.rb
index 3bbfff42e5..f2506d9f6f 100644
--- a/spec/ruby/library/socket/unixserver/open_spec.rb
+++ b/spec/ruby/library/socket/unixserver/open_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
require_relative 'shared/new'
describe "UNIXServer.open" do
diff --git a/spec/ruby/library/socket/unixserver/shared/new.rb b/spec/ruby/library/socket/unixserver/shared/new.rb
index e19a1582b6..35395826c9 100644
--- a/spec/ruby/library/socket/unixserver/shared/new.rb
+++ b/spec/ruby/library/socket/unixserver/shared/new.rb
@@ -1,6 +1,5 @@
-require_relative '../../../../spec_helper'
+require_relative '../../spec_helper'
require_relative '../../fixtures/classes'
-require 'tempfile'
describe :unixserver_new, shared: true do
platform_is_not :windows do
diff --git a/spec/ruby/library/socket/unixserver/sysaccept_spec.rb b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb
new file mode 100644
index 0000000000..864913af82
--- /dev/null
+++ b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb
@@ -0,0 +1,52 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+with_feature :unix_socket do
+ describe 'UNIXServer#sysaccept' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close
+
+ rm_r(@path)
+ end
+
+ describe 'without a client' do
+ it 'blocks the calling thread' do
+ lambda { @server.sysaccept }.should block_caller
+ end
+ end
+
+ describe 'with a client' do
+ before do
+ @client = UNIXSocket.new(@path)
+ end
+
+ after do
+ Socket.for_fd(@fd).close if @fd
+ @client.close
+ end
+
+ describe 'without any data' do
+ it 'returns a Fixnum' do
+ @fd = @server.sysaccept
+ @fd.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe 'with data available' do
+ before do
+ @client.write('hello')
+ end
+
+ it 'returns a Fixnum' do
+ @fd = @server.sysaccept
+ @fd.should be_an_instance_of(Fixnum)
+ end
+ end
+ end
+ end
+end