1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/library/socket/socket/udp_server_recv_spec.rb
eregon 8552ee87b6 Pass the Array from select() to Socket.udp_server_recv
* As mentioned in the documentation.
* Use Array#size instead of #count, it's more common.
* Use :unset, it clarifies things if the specs fails.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-05 09:50:11 +00:00

35 lines
715 B
Ruby

require_relative '../spec_helper'
describe 'Socket.udp_server_recv' do
before do
@server = Socket.new(:INET, :DGRAM)
@client = Socket.new(:INET, :DGRAM)
@server.bind(Socket.sockaddr_in(0, '127.0.0.1'))
@client.connect(@server.getsockname)
end
after do
@client.close
@server.close
end
it 'yields the message and a Socket::UDPSource' do
msg = :unset
src = :unset
@client.write('hello')
readable, _, _ = IO.select([@server])
readable.size.should == 1
Socket.udp_server_recv(readable) do |message, source|
msg = message
src = source
break
end
msg.should == 'hello'
src.should be_an_instance_of(Socket::UDPSource)
end
end