If driver.close is called before driver.start, the driver should close.

This commit is contained in:
James Coglan
2014-10-03 00:36:50 +01:00
parent 72972be911
commit 58c19e7659
2 changed files with 18 additions and 11 deletions
+10 -11
View File
@@ -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
+8
View File
@@ -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(