Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions core/file/socket_spec.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
require_relative '../../spec_helper'
require_relative '../../shared/file/socket'
require 'socket'

describe "File.socket?" do
it_behaves_like :file_socket, :socket?, File
end

describe "File.socket?" do
it "returns false if file does not exist" do
File.socket?("I_am_a_bogus_file").should == false
end

it "returns false if the file is not a socket" do
filename = tmp("i_exist")
touch(filename)

File.socket?(filename).should == false

rm_r filename
end
end

platform_is_not :windows do
describe "File.socket?" do
before :each do
# We need a really short name here.
# On Linux the path length is limited to 107, see unix(7).
@name = tmp("s")
@server = UNIXServer.new @name
end

after :each do
@server.close
rm_r @name
end

it "returns true if the file is a socket" do
File.socket?(@name).should == true
end
end
end
4 changes: 4 additions & 0 deletions core/filetest/socket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

describe "FileTest.socket?" do
it_behaves_like :file_socket, :socket?, FileTest

it "returns false if file does not exist" do
FileTest.socket?("I_am_a_bogus_file").should == false
end
end
16 changes: 7 additions & 9 deletions library/socket/addrinfo/afamily_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
end
end

with_feature :unix_socket do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "returns Socket::AF_UNIX" do
@addrinfo.afamily.should == Socket::AF_UNIX
end
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "returns Socket::AF_UNIX" do
@addrinfo.afamily.should == Socket::AF_UNIX
end
end
end
48 changes: 23 additions & 25 deletions library/socket/addrinfo/family_addrinfo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,36 @@
end
end

with_feature :unix_socket do
describe 'with a UNIX Addrinfo' do
before do
@source = Addrinfo.unix('cats')
end
describe 'with a UNIX Addrinfo' do
before do
@source = Addrinfo.unix('cats')
end

it 'raises ArgumentError if more than 1 argument is given' do
-> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError)
end
it 'raises ArgumentError if more than 1 argument is given' do
-> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError)
end

it 'returns an Addrinfo when a UNIX socket path is given' do
addr = @source.family_addrinfo('dogs')
it 'returns an Addrinfo when a UNIX socket path is given' do
addr = @source.family_addrinfo('dogs')

addr.should be_an_instance_of(Addrinfo)
end
addr.should be_an_instance_of(Addrinfo)
end

describe 'the returned Addrinfo' do
before do
@addr = @source.family_addrinfo('dogs')
end
describe 'the returned Addrinfo' do
before do
@addr = @source.family_addrinfo('dogs')
end

it 'uses AF_UNIX as the address family' do
@addr.afamily.should == Socket::AF_UNIX
end
it 'uses AF_UNIX as the address family' do
@addr.afamily.should == Socket::AF_UNIX
end

it 'uses PF_UNIX as the protocol family' do
@addr.pfamily.should == Socket::PF_UNIX
end
it 'uses PF_UNIX as the protocol family' do
@addr.pfamily.should == Socket::PF_UNIX
end

it 'uses the given socket path' do
@addr.unix_path.should == 'dogs'
end
it 'uses the given socket path' do
@addr.unix_path.should == 'dogs'
end
end
end
Expand Down
20 changes: 9 additions & 11 deletions library/socket/addrinfo/getnameinfo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@

platform_is :linux do
platform_is_not :android do
with_feature :unix_socket do
describe 'using a UNIX Addrinfo' do
before do
@addr = Addrinfo.unix('cats')
@host = Socket.gethostname
end
describe 'using a UNIX Addrinfo' do
before do
@addr = Addrinfo.unix('cats')
@host = Socket.gethostname
end

it 'returns the hostname and UNIX socket path' do
host, path = @addr.getnameinfo
it 'returns the hostname and UNIX socket path' do
host, path = @addr.getnameinfo

host.should == @host
path.should == 'cats'
end
host.should == @host
path.should == 'cats'
end
end
end
Expand Down
26 changes: 12 additions & 14 deletions library/socket/addrinfo/initialize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,23 +569,21 @@
end
end

with_feature :unix_socket do
describe 'using separate arguments for a Unix socket' do
before do
@sockaddr = Socket.pack_sockaddr_un('socket')
end
describe 'using separate arguments for a Unix socket' do
before do
@sockaddr = Socket.pack_sockaddr_un('socket')
end

it 'returns an Addrinfo with the correct unix path' do
Addrinfo.new(@sockaddr).unix_path.should == 'socket'
end
it 'returns an Addrinfo with the correct unix path' do
Addrinfo.new(@sockaddr).unix_path.should == 'socket'
end

it 'returns an Addrinfo with the correct protocol family' do
Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC
end
it 'returns an Addrinfo with the correct protocol family' do
Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC
end

it 'returns an Addrinfo with the correct address family' do
Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX
end
it 'returns an Addrinfo with the correct address family' do
Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX
end
end
end
18 changes: 8 additions & 10 deletions library/socket/addrinfo/inspect_sockaddr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@
end
end

with_feature :unix_socket do
describe 'using a UNIX path' do
it 'returns a String containing the UNIX path' do
addr = Addrinfo.unix('/foo/bar')
describe 'using a UNIX path' do
it 'returns a String containing the UNIX path' do
addr = Addrinfo.unix('/foo/bar')

addr.inspect_sockaddr.should == '/foo/bar'
end
addr.inspect_sockaddr.should == '/foo/bar'
end

it 'returns a String containing the UNIX path when using a relative path' do
addr = Addrinfo.unix('foo')
it 'returns a String containing the UNIX path when using a relative path' do
addr = Addrinfo.unix('foo')

addr.inspect_sockaddr.should == 'UNIX foo'
end
addr.inspect_sockaddr.should == 'UNIX foo'
end
end
end
26 changes: 12 additions & 14 deletions library/socket/addrinfo/inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,23 @@
end
end

with_feature :unix_socket do
describe 'using a UNIX Addrinfo' do
it 'returns a String' do
addr = Addrinfo.unix('/foo')
describe 'using a UNIX Addrinfo' do
it 'returns a String' do
addr = Addrinfo.unix('/foo')

addr.inspect.should == '#<Addrinfo: /foo SOCK_STREAM>'
end
addr.inspect.should == '#<Addrinfo: /foo SOCK_STREAM>'
end

it 'returns a String when using a relative UNIX path' do
addr = Addrinfo.unix('foo')
it 'returns a String when using a relative UNIX path' do
addr = Addrinfo.unix('foo')

addr.inspect.should == '#<Addrinfo: UNIX foo SOCK_STREAM>'
end
addr.inspect.should == '#<Addrinfo: UNIX foo SOCK_STREAM>'
end

it 'returns a String when using a DGRAM socket' do
addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM)
it 'returns a String when using a DGRAM socket' do
addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM)

addr.inspect.should == '#<Addrinfo: /foo SOCK_DGRAM>'
end
addr.inspect.should == '#<Addrinfo: /foo SOCK_DGRAM>'
end
end
end
14 changes: 6 additions & 8 deletions library/socket/addrinfo/ip_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
end
end

with_feature :unix_socket do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "raises an exception" do
-> { @addrinfo.ip_address }.should raise_error(SocketError)
end
it "raises an exception" do
-> { @addrinfo.ip_address }.should raise_error(SocketError)
end
end

Expand Down
14 changes: 6 additions & 8 deletions library/socket/addrinfo/ip_port_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
end
end

with_feature :unix_socket do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "raises an exception" do
-> { @addrinfo.ip_port }.should raise_error(SocketError)
end
it "raises an exception" do
-> { @addrinfo.ip_port }.should raise_error(SocketError)
end
end
end
14 changes: 6 additions & 8 deletions library/socket/addrinfo/ip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
end
end

with_feature :unix_socket do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "returns false" do
@addrinfo.ip?.should be_false
end
it "returns false" do
@addrinfo.ip?.should be_false
end
end
end
Expand Down
14 changes: 6 additions & 8 deletions library/socket/addrinfo/ip_unpack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
end
end

with_feature :unix_socket do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "raises an exception" do
-> { @addrinfo.ip_unpack }.should raise_error(SocketError)
end
it "raises an exception" do
-> { @addrinfo.ip_unpack }.should raise_error(SocketError)
end
end
end
14 changes: 6 additions & 8 deletions library/socket/addrinfo/ipv4_loopback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
end
end

with_feature :unix_socket do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "returns false" do
@addrinfo.ipv4_loopback?.should be_false
end
it "returns false" do
@addrinfo.ipv4_loopback?.should be_false
end
end
end
14 changes: 6 additions & 8 deletions library/socket/addrinfo/ipv4_multicast_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
Addrinfo.ip('::1').should_not.ipv4_multicast?
end

with_feature :unix_socket do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end

it "returns false" do
@addrinfo.ipv4_multicast?.should be_false
end
it "returns false" do
@addrinfo.ipv4_multicast?.should be_false
end
end
end
Loading