diff --git a/spec/reel/connection_spec.rb b/spec/reel/connection_spec.rb index da24627..3a54559 100644 --- a/spec/reel/connection_spec.rb +++ b/spec/reel/connection_spec.rb @@ -338,6 +338,40 @@ def test_chunked_response(request, client) end end + it "detaches a connection properly" do + with_socket_pair do |client, peer| + connection = Reel::Connection.new(peer) + client << ExampleRequest.new.to_s + + expect(connection.detach).to be_a Reel::Connection + expect(connection.attached?).to eq(false) + end + end + + it "returns friendlier inspect output" do + with_socket_pair do |client, peer| + connection = Reel::Connection.new(peer) + example_request = ExampleRequest.new + client << example_request.to_s + request = connection.request + + expect(request.inspect).to eq example_request.inspect_method + end + end + + it "raises an exception if not in chunked body mode" do + with_socket_pair do |client, peer| + connection = Reel::Connection.new(peer) + client << ExampleRequest.new.tap{ |r| + r['Connection'] = 'keep-alive' + }.to_s + request = connection.request + request.respond :ok, :transfer_encoding => '' + + expect {request << "Hello"}.to raise_error(Reel::StateError) + end + end + context "#readpartial" do it "streams request bodies" do with_socket_pair do |client, peer| diff --git a/spec/reel/websocket_spec.rb b/spec/reel/websocket_spec.rb index e62c6f3..64cc504 100644 --- a/spec/reel/websocket_spec.rb +++ b/spec/reel/websocket_spec.rb @@ -122,6 +122,23 @@ def initialize(websocket) end end + it "writes array messages" do + with_websocket_pair do |client, websocket| + websocket.write Array.new(2) { |e| e = e * 2} + + parser = WebSocket::Parser.new + + parser.append client.readpartial(4096) until first_message = parser.next_message + expect(first_message).to eq("\x00\x02") + end + end + + it "it raises exception when trying to write besides string or array messages" do + with_websocket_pair do |client, websocket| + expect { websocket.write 1 }.to raise_exception('Can only send byte array or string over driver.') + end + end + it "closes" do with_websocket_pair do |_, websocket| expect(websocket).not_to be_closed diff --git a/spec/support/example_request.rb b/spec/support/example_request.rb index 4a8d50d..09582ed 100644 --- a/spec/support/example_request.rb +++ b/spec/support/example_request.rb @@ -31,4 +31,8 @@ def to_s @headers.map { |k, v| "#{k}: #{v}" }.join("\r\n") << "\r\n\r\n" << (@body ? @body : '') end + + def inspect_method + "#" + end end