summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/option/new_spec.rb
blob: b2c76fb24d46a75a418f2e78c190d3fbcdca1606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'

describe "Socket::Option.new" do
  it "should accept integers" do
    so = Socket::Option.new(Socket::AF_INET, Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, [0].pack('i'))
    so.family.should == Socket::AF_INET
    so.level.should == Socket::SOL_SOCKET
    so.optname.should == Socket::SO_KEEPALIVE
  end

  it "should accept symbols" do
    so = Socket::Option.new(:AF_INET, :SOL_SOCKET, :SO_KEEPALIVE, [0].pack('i'))
    so.family.should == Socket::AF_INET
    so.level.should == Socket::SOL_SOCKET
    so.optname.should == Socket::SO_KEEPALIVE

    so = Socket::Option.new(:INET, :SOCKET, :KEEPALIVE, [0].pack('i'))
    so.family.should == Socket::AF_INET
    so.level.should == Socket::SOL_SOCKET
    so.optname.should == Socket::SO_KEEPALIVE
  end

  it "should raise error on unknown family" do
    lambda { Socket::Option.new(:INET4, :SOCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError)
  end

  it "should raise error on unknown level" do
    lambda { Socket::Option.new(:INET, :ROCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError)
  end

  it "should raise error on unknown option name" do
    lambda { Socket::Option.new(:INET, :SOCKET, :ALIVE, [0].pack('i')) }.should raise_error(SocketError)
  end
end