spec/integration/draft13_spec.rb in em-websocket-0.4.0 vs spec/integration/draft13_spec.rb in em-websocket-0.5.0
- old
+ new
@@ -1,5 +1,7 @@
+# encoding: BINARY
+
require 'helper'
require 'integration/shared_examples'
describe "draft13" do
include EM::SpecHelper
@@ -29,33 +31,32 @@
"Sec-WebSocket-Accept" => "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",
}
}
end
- it_behaves_like "a websocket server" do
- let(:version) { 13 }
+ def start_server
+ EM::WebSocket.run(:host => "0.0.0.0", :port => 12345) { |ws|
+ yield ws if block_given?
+ }
+ end
- def start_server
- EM::WebSocket.start(:host => "0.0.0.0", :port => 12345) { |ws|
- yield ws
- }
- end
+ def start_client
+ client = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient)
+ client.send_data(format_request(@request))
+ yield client if block_given?
+ return client
+ end
- def start_client
- client = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient)
- client.send_data(format_request(@request))
- yield client if block_given?
- end
+ it_behaves_like "a websocket server" do
+ let(:version) { 13 }
end
it "should send back the correct handshake response" do
em {
- EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 12345) { }
+ start_server
- # Create a fake client which sends draft 13 handshake
- connection = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient)
- connection.send_data(format_request(@request))
+ connection = start_client
connection.onopen {
connection.handshake_response.lines.sort.
should == format_response(@response).lines.sort
done
@@ -64,11 +65,11 @@
end
# TODO: This test would be much nicer with a real websocket client...
it "should support sending pings and binding to onpong" do
em {
- EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 12345) { |ws|
+ start_server { |ws|
ws.onopen {
ws.should be_pingable
EM.next_tick {
ws.ping('hello').should == true
}
@@ -78,19 +79,29 @@
data.should == 'hello'
done
}
}
- # Create a fake client which sends draft 13 handshake
- connection = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient)
- connection.send_data(format_request(@request))
+ connection = start_client
# Confusing, fake onmessage means any data after the handshake
connection.onmessage { |data|
# This is what a ping looks like
data.should == "\x89\x05hello"
# This is what a pong looks like
connection.send_data("\x8a\x05hello")
}
+ }
+ end
+
+ it "should report that close codes are supported" do
+ em {
+ start_server { |ws|
+ ws.onopen {
+ ws.supports_close_codes?.should == true
+ done
+ }
+ }
+ start_client
}
end
end