<NME> spec_helper.rb
<BEF> require "rubygems"
require "bundler/setup"

module Specs
  ALLOW_SLOW_MAILBOXES = true # TODO: Remove hax.
end

require "celluloid/rspec"
require "celluloid/io"

Dir[*Specs::INCLUDE_PATHS].map { |f| require f }

def with_tcp_server
  server = Celluloid::IO::TCPServer.new(example_addr, example_port)
  yield server
ensure
  server.close
end

def with_connected_sockets
  with_tcp_server do |server|
    # FIXME: client isn't actually a Celluloid::IO::TCPSocket yet
    client = TCPSocket.new(example_addr, example_port)
    peer = server.accept

    begin

<MSG> Initial client support (punting on non-blocking)

<DFF> @@ -25,15 +25,17 @@ end
 
 def with_tcp_server
   server = Celluloid::IO::TCPServer.new(example_addr, example_port)
-  yield server
-ensure
-  server.close
+  begin
+    yield server
+  ensure
+    server.close
+  end
 end
 
 def with_connected_sockets
   with_tcp_server do |server|
     # FIXME: client isn't actually a Celluloid::IO::TCPSocket yet
-    client = TCPSocket.new(example_addr, example_port)
+    client = ::TCPSocket.new(example_addr, example_port)
     peer = server.accept
 
     begin

{'commit': 'diff --git a/lib/celluloid/io/tcp_socket.rb b/lib/celluloid/io/tcp_socket.rb\nindex 231f6ff..563f1fd 100644\n--- a/lib/celluloid/io/tcp_socket.rb\n+++ b/lib/celluloid/io/tcp_socket.rb\n@@ -10,6 +10,7 @@ module Celluloid\n       def_delegators :@socket, :read_nonblock, :write_nonblock, :close, :closed?\n       def_delegators :@socket, :addr, :peeraddr\n \n+      # Convert a Ruby TCPSocket into a Celluloid::IO::TCPSocket\n       def self.from_ruby_socket(ruby_socket)\n         # Some hax here, but whatever ;)\n         socket = allocate\n@@ -17,6 +18,14 @@ module Celluloid\n         socket\n       end\n \n+      # Opens a TCP connection to remote_host on remote_port. If local_host\n+      # and local_port are specified, then those parameters are used on the\n+      # local end to establish the connection.\n+      def initialize(remote_host, remote_port, local_host = nil, local_port = nil)\n+        # FIXME: not using non-blocking connect\n+        @socket = ::TCPSocket.new(remote_host, remote_port, local_host, local_port)\n+      end\n+\n       def to_io\n         @socket\n       end\ndiff --git a/spec/celluloid/io/tcp_socket_spec.rb b/spec/celluloid/io/tcp_socket_spec.rb\nindex cc77eb6..c624ec5 100644\n--- a/spec/celluloid/io/tcp_socket_spec.rb\n+++ b/spec/celluloid/io/tcp_socket_spec.rb\n@@ -4,6 +4,20 @@ describe Celluloid::IO::TCPSocket do\n   let(:payload) { \'ohai\' }\n \n   context "inside Celluloid::IO" do\n+    it "connects to TCP servers" do\n+      server = ::TCPServer.new example_addr, example_port\n+      thread = Thread.new { server.accept }\n+      socket = within_io_actor { Celluloid::IO::TCPSocket.new example_addr, example_port }\n+      peer = thread.value\n+\n+      peer << payload\n+      within_io_actor { socket.read(payload.size) }.should eq payload\n+\n+      server.close\n+      socket.close\n+      peer.close\n+    end\n+\n     it "should be evented" do\n       with_connected_sockets do |subject|\n         within_io_actor { subject.evented? }.should be_true\n@@ -33,6 +47,20 @@ describe Celluloid::IO::TCPSocket do\n   end\n \n   context "elsewhere in Ruby" do\n+    it "connects to TCP servers" do\n+      server = ::TCPServer.new example_addr, example_port\n+      thread = Thread.new { server.accept }\n+      socket = Celluloid::IO::TCPSocket.new example_addr, example_port\n+      peer = thread.value\n+\n+      peer << payload\n+      socket.read(payload.size).should eq payload\n+\n+      server.close\n+      socket.close\n+      peer.close\n+    end\n+\n     it "should be blocking" do\n       with_connected_sockets do |subject|\n         subject.should_not be_evented\ndiff --git a/spec/spec_helper.rb b/spec/spec_helper.rb\nindex f893fb6..762dccc 100644\n--- a/spec/spec_helper.rb\n+++ b/spec/spec_helper.rb\n@@ -25,15 +25,17 @@ end\n \n def with_tcp_server\n   server = Celluloid::IO::TCPServer.new(example_addr, example_port)\n-  yield server\n-ensure\n-  server.close\n+  begin\n+    yield server\n+  ensure\n+    server.close\n+  end\n end\n \n def with_connected_sockets\n   with_tcp_server do |server|\n     # FIXME: client isn\'t actually a Celluloid::IO::TCPSocket yet\n-    client = TCPSocket.new(example_addr, example_port)\n+    client = ::TCPSocket.new(example_addr, example_port)\n     peer = server.accept\n \n     begin\n', 'commit_subject': 'Initial client support (punting on non-blocking)', 'repo_name': 'celluloid/celluloid-io', 'committer': {'name': 'Tony Arcieri', 'email': '39b76599b8180a4e18d82cce43d7507d8dff8114@gmail.com', 'time_sec': '1329712823', 'tz_offset': '-480', 'date': {'seconds': '1329712823'}}, 'commit_tree': '8c5961a864097559cb2ca0796912d055cfd79656', 'commit_message': 'Initial client support (punting on non-blocking)\n', 'language_name': 'Ruby', 'license': 'mit', 'hunks': "@@ -25,15 +25,17 @@ end\n \n def with_tcp_server\n   server = Celluloid::IO::TCPServer.new(example_addr, example_port)\n-  yield server\n-ensure\n-  server.close\n+  begin\n+    yield server\n+  ensure\n+    server.close\n+  end\n end\n \n def with_connected_sockets\n   with_tcp_server do |server|\n     # FIXME: client isn't actually a Celluloid::IO::TCPSocket yet\n-    client = TCPSocket.new(example_addr, example_port)\n+    client = ::TCPSocket.new(example_addr, example_port)\n     peer = server.accept\n \n     begin\n", 'addition_count': 6, 'deletion_count': 4, 'src_file': 'a/spec/spec_helper.rb', 'tgt_file': 'b/spec/spec_helper.rb', 'file_extension': '.rb', 'before_file': 'require "rubygems"\nrequire "bundler/setup"\n\nmodule Specs\n  ALLOW_SLOW_MAILBOXES = true # TODO: Remove hax.\nend\n\nrequire "celluloid/rspec"\nrequire "celluloid/io"\n\nDir[*Specs::INCLUDE_PATHS].map { |f| require f }\n\ndef with_tcp_server\n  server = Celluloid::IO::TCPServer.new(example_addr, example_port)\n  yield server\nensure\n  server.close\nend\n\ndef with_connected_sockets\n  with_tcp_server do |server|\n    # FIXME: client isn\'t actually a Celluloid::IO::TCPSocket yet\n    client = TCPSocket.new(example_addr, example_port)\n    peer = server.accept\n\n    begin\n', 'message': 'Initial client support (punting on non-blocking)\n', 'author_name': 'Tony Arcieri', 'lang': 'rb'}