diff options
Diffstat (limited to 'spec/ruby/library/socket/basicsocket/send_spec.rb')
| -rw-r--r-- | spec/ruby/library/socket/basicsocket/send_spec.rb | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/spec/ruby/library/socket/basicsocket/send_spec.rb b/spec/ruby/library/socket/basicsocket/send_spec.rb index 041ee46998..a2c2ee8de9 100644 --- a/spec/ruby/library/socket/basicsocket/send_spec.rb +++ b/spec/ruby/library/socket/basicsocket/send_spec.rb @@ -9,36 +9,36 @@ describe "BasicSocket#send" do end after :each do - @server.closed?.should be_false - @socket.closed?.should be_false + @server.closed?.should == false + @socket.closed?.should == false @server.close @socket.close end - it "sends a message to another socket and returns the number of bytes sent" do - data = "" - t = Thread.new do - client = @server.accept - loop do - got = client.recv(5) - break if got.empty? - data << got - end - client.close - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - @socket.send('hello', 0).should == 5 - @socket.shutdown(1) # indicate, that we are done sending - @socket.recv(10) - - t.join - data.should == 'hello' - end - - platform_is_not :solaris, :windows do + it "sends a message to another socket and returns the number of bytes sent" do + data = +"" + t = Thread.new do + client = @server.accept + loop do + got = client.recv(5) + break if got.nil? || got.empty? + data << got + end + client.close + end + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil + + @socket.send('hello', 0).should == 5 + @socket.shutdown(1) # indicate, that we are done sending + @socket.recv(10) + + t.join + data.should == 'hello' + end + + platform_is_not :windows do it "accepts flags to specify unusual sending behaviour" do data = nil peek_data = nil @@ -50,7 +50,7 @@ describe "BasicSocket#send" do client.close end Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + t.status.should_not == nil @socket.send('helloU', Socket::MSG_PEEK | Socket::MSG_OOB).should == 6 @socket.shutdown # indicate, that we are done sending @@ -62,25 +62,25 @@ describe "BasicSocket#send" do end it "accepts a sockaddr as recipient address" do - data = "" - t = Thread.new do - client = @server.accept - loop do - got = client.recv(5) - break if got.empty? - data << got - end - client.close - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - sockaddr = Socket.pack_sockaddr_in(@port, "127.0.0.1") - @socket.send('hello', 0, sockaddr).should == 5 - @socket.shutdown # indicate, that we are done sending - - t.join - data.should == 'hello' + data = +"" + t = Thread.new do + client = @server.accept + loop do + got = client.recv(5) + break if got.nil? || got.empty? + data << got + end + client.close + end + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil + + sockaddr = Socket.pack_sockaddr_in(@port, "127.0.0.1") + @socket.send('hello', 0, sockaddr).should == 5 + @socket.shutdown # indicate, that we are done sending + + t.join + data.should == 'hello' end end @@ -99,9 +99,17 @@ describe 'BasicSocket#send' do @server.close end + describe 'with an object implementing #to_str' do + it 'returns the amount of sent bytes' do + data = mock('message') + data.should_receive(:to_str).and_return('hello') + @client.send(data, 0, @server.getsockname).should == 5 + end + end + describe 'without a destination address' do it "raises #{SocketSpecs.dest_addr_req_error}" do - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end @@ -113,7 +121,7 @@ describe 'BasicSocket#send' do it 'does not persist the connection after writing to the socket' do @client.send('hello', 0, @server.getsockname) - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end |
