mirror of
https://github.com/faye/websocket-driver-ruby.git
synced 2025-11-01 13:59:38 +00:00
If driver.close is called before driver.start, the driver should close.
This commit is contained in:
@@ -181,17 +181,16 @@ module WebSocket
|
||||
reason ||= ''
|
||||
code ||= ERRORS[:normal_closure]
|
||||
|
||||
case @ready_state
|
||||
when 0 then
|
||||
@ready_state = 3
|
||||
emit(:close, CloseEvent.new(code, reason))
|
||||
true
|
||||
when 1 then
|
||||
frame(reason, :close, code)
|
||||
@ready_state = 2
|
||||
true
|
||||
else
|
||||
false
|
||||
if @ready_state <= 0
|
||||
@ready_state = 3
|
||||
emit(:close, CloseEvent.new(code, reason))
|
||||
true
|
||||
elsif @ready_state == 1
|
||||
frame(reason, :close, code)
|
||||
@ready_state = 2
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -54,6 +54,14 @@ describe WebSocket::Driver::Client do
|
||||
expect(driver.state).to eq nil
|
||||
end
|
||||
|
||||
describe :close do
|
||||
it "changes the state to closed" do
|
||||
driver.close
|
||||
expect(driver.state).to eq :closed
|
||||
expect(@close).to eq [1000, ""]
|
||||
end
|
||||
end
|
||||
|
||||
describe :start do
|
||||
it "writes the handshake request to the socket" do
|
||||
expect(socket).to receive(:write).with(
|
||||
|
||||
Reference in New Issue
Block a user