spec/reel/websocket_spec.rb in reel-0.4.0.pre vs spec/reel/websocket_spec.rb in reel-0.4.0.pre2

- old
+ new

@@ -8,17 +8,30 @@ it "performs websocket handshakes" do with_socket_pair do |client, connection| client << handshake.to_data - websocket = connection.request + request = connection.request + request.should be_websocket + + websocket = request.websocket websocket.should be_a Reel::WebSocket handshake.errors.should be_empty end end + it "raises an error if trying to close a connection upgraded to socket" do + with_socket_pair do |client, connection| + client << handshake.to_data + + websocket = connection.request.websocket + websocket.should be_a Reel::WebSocket + expect { connection.close }.to raise_error(Reel::Connection::StateError) + end + end + it "knows its URL" do with_websocket_pair do |_, websocket| websocket.url.should == example_path end end @@ -60,13 +73,32 @@ websocket.close websocket.should be_closed end end + it "raises a RequestError when connection used after it was upgraded" do + with_socket_pair do |client, connection| + client << handshake.to_data + + remote_host = connection.remote_host + + request = connection.request + request.should be_websocket + websocket = request.websocket + websocket.should be_a Reel::WebSocket + + expect { connection.remote_host }.to raise_error(Reel::Connection::StateError) + websocket.remote_host.should == remote_host + end + end + def with_websocket_pair with_socket_pair do |client, connection| client << handshake.to_data - websocket = connection.request + request = connection.request + + request.should be_websocket + websocket = request.websocket websocket.should be_a Reel::WebSocket # Discard handshake client.readpartial(4096)