spec/integration/draft75_spec.rb in em-websocket-0.5.0 vs spec/integration/draft75_spec.rb in em-websocket-0.5.1
- old
+ new
@@ -1,22 +1,15 @@
require 'helper'
-require 'integration/shared_examples'
# These integration tests are older and use a different testing style to the
# integration tests for newer drafts. They use EM::HttpRequest which happens
# to currently estabish a websocket connection using the draft75 protocol.
#
describe "WebSocket server draft75" do
include EM::SpecHelper
default_timeout 1
- def start_server
- EM::WebSocket.run(:host => "0.0.0.0", :port => 12345) { |ws|
- yield ws if block_given?
- }
- end
-
def start_client
client = Draft75WebSocketClient.new
yield client if block_given?
return client
end
@@ -27,16 +20,16 @@
it "should automatically complete WebSocket handshake" do
em {
MSG = "Hello World!"
EventMachine.add_timer(0.1) do
- http = EventMachine::HttpRequest.new('ws://127.0.0.1:12345/').get :timeout => 0
- http.errback { fail }
- http.callback { http.response_header.status.should == 101 }
+ ws = EventMachine::WebSocketClient.connect('ws://127.0.0.1:12345/')
+ ws.errback { fail }
+ ws.callback { }
- http.stream { |msg|
- msg.should == MSG
+ ws.stream { |msg|
+ msg.data.should == MSG
EventMachine.stop
}
end
start_server { |ws|
@@ -51,17 +44,16 @@
em {
messages = %w[1 2]
received = []
EventMachine.add_timer(0.1) do
- http = EventMachine::HttpRequest.new('ws://127.0.0.1:12345/').get :timeout => 0
- http.errback { fail }
- http.stream {|msg|}
- http.callback {
- http.response_header.status.should == 101
- http.send messages[0]
- http.send messages[1]
+ ws = EventMachine::WebSocketClient.connect('ws://127.0.0.1:12345/')
+ ws.errback { fail }
+ ws.stream {|msg|}
+ ws.callback {
+ ws.send_msg messages[0]
+ ws.send_msg messages[1]
}
end
start_server { |ws|
ws.onopen {}
@@ -77,17 +69,16 @@
end
it "should call onclose callback when client closes connection" do
em {
EventMachine.add_timer(0.1) do
- http = EventMachine::HttpRequest.new('ws://127.0.0.1:12345/').get :timeout => 0
- http.errback { fail }
- http.callback {
- http.response_header.status.should == 101
- http.close_connection
+ ws = EventMachine::WebSocketClient.connect('ws://127.0.0.1:12345/')
+ ws.errback { fail }
+ ws.callback {
+ ws.close_connection
}
- http.stream{|msg|}
+ ws.stream{|msg|}
end
start_server { |ws|
ws.onopen {}
ws.onclose {
@@ -99,11 +90,11 @@
end
it "should call onerror callback with raised exception and close connection on bad handshake" do
em {
EventMachine.add_timer(0.1) do
- http = EventMachine::HttpRequest.new('http://127.0.0.1:12345/').get :timeout => 0
- http.errback { http.response_header.status.should == 0 }
+ http = EM::HttpRequest.new('http://127.0.0.1:12345/').get
+ http.errback { }
http.callback { fail }
end
start_server { |ws|
ws.onopen { fail }