summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/socket/getservbyport_spec.rb
blob: 9be2ac527e21db71cc0102432b062320b31b3e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require_relative '../spec_helper'

describe 'Socket.getservbyport' do
  platform_is_not :windows do
    it 'returns the service name as a String' do
      Socket.getservbyport(514).should == 'shell'
    end
  end

  platform_is :windows do
    it 'returns the service name as a String' do
      Socket.getservbyport(514).should == 'cmd'
    end
  end

  it 'returns the service name when using a custom protocol name' do
    Socket.getservbyport(514, 'udp').should == 'syslog'
  end

  it 'raises SocketError for an unknown port number' do
    lambda { Socket.getservbyport(0) }.should raise_error(SocketError)
  end
end