spec/spec_helper.rb in reel-0.2.0 vs spec/spec_helper.rb in reel-0.3.0.pre

- old
+ new

@@ -16,18 +16,19 @@ server.terminate end def with_socket_pair host = '127.0.0.1' - port = 10103 + port = 10101 server = TCPServer.new(host, port) client = TCPSocket.new(host, port) peer = server.accept begin - yield client, Reel::Connection.new(peer) + connection = Reel::Connection.new(peer) + yield client, connection ensure server.close rescue nil client.close rescue nil peer.close rescue nil end @@ -63,5 +64,28 @@ "#{@method} #{@path} HTTP/#{@version}\r\n" << @headers.map { |k, v| "#{k}: #{v}" }.join("\r\n") << "\r\n\r\n" << (@body ? @body : '') end end + +module WebSocketHelpers + def self.included(spec) + spec.instance_eval do + let(:example_host) { "www.example.com" } + let(:example_path) { "/example"} + let(:example_url) { "ws://#{example_host}#{example_path}" } + let :handshake_headers do + { + "Host" => example_host, + "Upgrade" => "websocket", + "Connection" => "Upgrade", + "Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==", + "Origin" => "http://example.com", + "Sec-WebSocket-Protocol" => "chat, superchat", + "Sec-WebSocket-Version" => "13" + } + end + + let(:handshake) { WebSocket::ClientHandshake.new(:get, example_url, handshake_headers) } + end + end +end \ No newline at end of file