1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
From: Hleb Valoshka <375gnu@gmail.com>
Date: Tue, 7 Jul 2015 18:38:51 +0300
Subject: Convert specs to RSpec 3.3.1 syntax with Transpec
This conversion is done by Transpec 3.1.0 with the following command:
transpec
* 58 conversions
from: obj.should
to: expect(obj).to
* 2 conversions
from: be_true
to: be_truthy
* 1 conversion
from: be_false
to: be_falsey
For more details: https://github.com/yujinakayama/transpec#supported-conversions
---
spec/websocket/handshake_spec.rb | 10 +++----
spec/websocket/message_spec.rb | 46 +++++++++++++++---------------
spec/websocket/parser_spec.rb | 60 ++++++++++++++++++++--------------------
3 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/spec/websocket/handshake_spec.rb b/spec/websocket/handshake_spec.rb
index 6a62f75..99460ce 100644
--- a/spec/websocket/handshake_spec.rb
+++ b/spec/websocket/handshake_spec.rb
@@ -16,15 +16,15 @@ describe WebSocket::ClientHandshake do
let(:client_handshake) { WebSocket::ClientHandshake.new(:get, '/', handshake_headers) }
it "can validate handshake format" do
- client_handshake.valid?.should be_true
+ expect(client_handshake.valid?).to be_truthy
end
it "can generate an accept response for the client" do
response = client_handshake.accept_response
- response.headers['Upgrade'].should eq('websocket')
- response.headers['Connection'].should eq('Upgrade')
- response.headers['Sec-WebSocket-Accept'].should eq('s3pPLMBiTxaQ9kYGzzhZRbK+xOo=')
+ expect(response.headers['Upgrade']).to eq('websocket')
+ expect(response.headers['Connection']).to eq('Upgrade')
+ expect(response.headers['Sec-WebSocket-Accept']).to eq('s3pPLMBiTxaQ9kYGzzhZRbK+xOo=')
end
it "can be seariakized to data" do
@@ -40,6 +40,6 @@ describe WebSocket::ClientHandshake do
"\r\n"
]
- client_handshake.to_data.should eq expected_lines.join("\r\n")
+ expect(client_handshake.to_data).to eq expected_lines.join("\r\n")
end
end
diff --git a/spec/websocket/message_spec.rb b/spec/websocket/message_spec.rb
index a07a37d..43fff11 100644
--- a/spec/websocket/message_spec.rb
+++ b/spec/websocket/message_spec.rb
@@ -7,14 +7,14 @@ describe WebSocket::Message do
data = message.to_data
# 2 bytes from header + 8 bytes from extended payload length + payload
- data.size.should eq(2 + 8 + text.length)
+ expect(data.size).to eq(2 + 8 + text.length)
first_byte, second_byte, ext_length, payload = data.unpack("CCQ>a#{text.length}")
- first_byte.should eq(0b10000001) # Text frame with FIN bit set
- second_byte.should eq(0b01111111) # Unmasked. Payload length 127.
- ext_length.should eq(text.length)
- payload.should eq(text)
+ expect(first_byte).to eq(0b10000001) # Text frame with FIN bit set
+ expect(second_byte).to eq(0b01111111) # Unmasked. Payload length 127.
+ expect(ext_length).to eq(text.length)
+ expect(payload).to eq(text)
end
it "knows binary representation of messages between 126 and 65,535 bytes" do
@@ -22,16 +22,16 @@ describe WebSocket::Message do
data = WebSocket::Message.new(text).to_data
# 2 bytes from header + 2 bytes from extended payload length + payload
- data.size.should eq(2 + 2 + text.length)
+ expect(data.size).to eq(2 + 2 + text.length)
# extended payload length should respect endianness
- data[2..3].should eq([0x00, 0x7F].pack('C*'))
+ expect(data[2..3]).to eq([0x00, 0x7F].pack('C*'))
first_byte, second_byte, ext_length, payload = data.unpack("CCna#{text.length}")
- first_byte.should eq(0b10000001) # Text frame with FIN bit set
- second_byte.should eq(0b01111110) # Unmasked. Payload length 126.
- ext_length.should eq(text.length)
- payload.should eq(text)
+ expect(first_byte).to eq(0b10000001) # Text frame with FIN bit set
+ expect(second_byte).to eq(0b01111110) # Unmasked. Payload length 126.
+ expect(ext_length).to eq(text.length)
+ expect(payload).to eq(text)
end
it "knows binary representation of messages with less than 126 bytes" do
@@ -39,31 +39,31 @@ describe WebSocket::Message do
data = WebSocket::Message.new(text).to_data
# 2 bytes from header + payload
- data.size.should eq(2 + text.length)
+ expect(data.size).to eq(2 + text.length)
first_byte, second_byte, payload = data.unpack("CCa#{text.length}")
- first_byte.should eq(0b10000001) # Text frame with FIN bit set
- second_byte.should eq(0b01111101) # Unmasked. Payload length 125.
- payload.should eq(text)
+ expect(first_byte).to eq(0b10000001) # Text frame with FIN bit set
+ expect(second_byte).to eq(0b01111101) # Unmasked. Payload length 125.
+ expect(payload).to eq(text)
end
it "can be masked" do
message = WebSocket::Message.new('The man with the Iron Mask')
- message.masked?.should be_false
+ expect(message.masked?).to be_falsey
message.mask!
- message.masked?.should be_true
+ expect(message.masked?).to be_truthy
end
it "allows status codes for control frames" do
msg = WebSocket::Message.close(1001, 'Bye')
- msg.status_code.should eq(1001)
- msg.payload.should eq([1001, 'Bye'].pack('S<a*'))
- msg.status.should eq(:peer_going_away)
- msg.status_message.should eq('Bye')
+ expect(msg.status_code).to eq(1001)
+ expect(msg.payload).to eq([1001, 'Bye'].pack('S<a*'))
+ expect(msg.status).to eq(:peer_going_away)
+ expect(msg.status_message).to eq('Bye')
end
it "does not allow a status message without status code" do
@@ -74,7 +74,7 @@ describe WebSocket::Message do
ping = WebSocket::Message.ping('Roman Ping Pong')
pong = WebSocket::Message.pong(ping.payload)
- pong.type.should eq(:pong)
- pong.payload.should eq('Roman Ping Pong')
+ expect(pong.type).to eq(:pong)
+ expect(pong.payload).to eq('Roman Ping Pong')
end
end
diff --git a/spec/websocket/parser_spec.rb b/spec/websocket/parser_spec.rb
index c7a31e9..cfc290d 100644
--- a/spec/websocket/parser_spec.rb
+++ b/spec/websocket/parser_spec.rb
@@ -22,7 +22,7 @@ describe WebSocket::Parser do
it "recognizes a text message" do
parser << WebSocket::Message.new('Once upon a time').to_data
- received_messages.first.should eq('Once upon a time')
+ expect(received_messages.first).to eq('Once upon a time')
end
it "returns parsed messages on parse" do
@@ -30,30 +30,30 @@ describe WebSocket::Parser do
msg2 = WebSocket::Message.new('Made glorious summer by this sun of York').to_data
messages = parser << msg1.slice!(0,5)
- messages.should be_empty # We don't have a complete message yet
+ expect(messages).to be_empty # We don't have a complete message yet
messages = parser << msg1 + msg2
- messages[0].should eq('Now is the winter of our discontent')
- messages[1].should eq('Made glorious summer by this sun of York')
+ expect(messages[0]).to eq('Now is the winter of our discontent')
+ expect(messages[1]).to eq('Made glorious summer by this sun of York')
end
it "does not return control frames" do
msg = WebSocket::Message.close(1001, 'Goodbye!').to_data
messages = parser << msg
- messages.should be_empty
+ expect(messages).to be_empty
end
it "can receive a message in parts" do
data = WebSocket::Message.new('Once upon a time').to_data
parser << data.slice!(0, 5)
- received_messages.should be_empty
+ expect(received_messages).to be_empty
parser << data
- received_messages.first.should eq('Once upon a time')
+ expect(received_messages.first).to eq('Once upon a time')
end
it "can receive succesive messages" do
@@ -63,60 +63,60 @@ describe WebSocket::Parser do
parser << msg1.to_data
parser << msg2.to_data
- received_messages[0].should eq('Now is the winter of our discontent')
- received_messages[1].should eq('Made glorious summer by this sun of York')
+ expect(received_messages[0]).to eq('Now is the winter of our discontent')
+ expect(received_messages[1]).to eq('Made glorious summer by this sun of York')
end
it "can receive medium size messages" do
# Medium size messages has a payload length between 127 and 65_535 bytes
text = 4.times.collect { 'All work and no play makes Jack a dull boy.' }.join("\n\n")
- text.length.should be > 127
- text.length.should be < 65_536
+ expect(text.length).to be > 127
+ expect(text.length).to be < 65_536
parser << WebSocket::Message.new(text).to_data
- received_messages.first.should eq(text)
+ expect(received_messages.first).to eq(text)
end
it "can receive large size messages" do
# Large size messages has a payload length greater than 65_535 bytes
text = 1500.times.collect { 'All work and no play makes Jack a dull boy.' }.join("\n\n")
- text.length.should be > 65_536
+ expect(text.length).to be > 65_536
parser << WebSocket::Message.new(text).to_data
# Check lengths first to avoid gigantic error message
- received_messages.first.length.should eq(text.length)
- received_messages.first.should eq(text)
+ expect(received_messages.first.length).to eq(text.length)
+ expect(received_messages.first).to eq(text)
end
it "recognizes a ping message" do
parser << WebSocket::Message.ping.to_data
- received_pings.size.should eq(1)
+ expect(received_pings.size).to eq(1)
end
it "recognizes a pong message" do
parser << WebSocket::Message.pong.to_data
- received_pongs.size.should eq(1)
+ expect(received_pongs.size).to eq(1)
end
it "recognizes a close message with status code and message" do
parser << WebSocket::Message.close(1001, 'Browser leaving page').to_data
status, message = received_closes.first
- status.should eq(:peer_going_away) # Status code 1001
- message.should eq('Browser leaving page')
+ expect(status).to eq(:peer_going_away) # Status code 1001
+ expect(message).to eq('Browser leaving page')
end
it "recognizes a close message without status code" do
parser << WebSocket::Message.close.to_data
status, message = received_closes.first
- status.should be_nil
- message.should be_empty
+ expect(status).to be_nil
+ expect(message).to be_empty
end
it "recognizes a masked frame" do
@@ -125,7 +125,7 @@ describe WebSocket::Parser do
parser << msg.to_data
- received_messages.first.should eq('Once upon a time')
+ expect(received_messages.first).to eq('Once upon a time')
end
context "examples from the spec" do
@@ -134,49 +134,49 @@ describe WebSocket::Parser do
it "recognizes single-frame unmasked text message" do
parser << [0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f].pack('C*')
- received_messages.first.should eq('Hello')
+ expect(received_messages.first).to eq('Hello')
end
it "recognizes single-frame masked text message" do
parser << [0x81, 0x85, 0x37, 0xfa, 0x21, 0x3d, 0x7f, 0x9f, 0x4d, 0x51, 0x58].pack('C*')
- received_messages.first.should eq('Hello')
+ expect(received_messages.first).to eq('Hello')
end
it "recognizes a fragmented unmasked text message" do
parser << [0x01, 0x03, 0x48, 0x65, 0x6c].pack('C*') # contains "Hel"
- received_messages.should be_empty
+ expect(received_messages).to be_empty
parser << [0x80, 0x02, 0x6c, 0x6f].pack('C*') # contains "lo"
- received_messages.first.should eq('Hello')
+ expect(received_messages.first).to eq('Hello')
end
it "recognizes an unnmasked ping request" do
parser << [0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f].pack('C*')
- received_pings.size.should eq(1)
+ expect(received_pings.size).to eq(1)
end
it "recognizes a masked pong response" do
parser << [0x8a, 0x85, 0x37, 0xfa, 0x21, 0x3d, 0x7f, 0x9f, 0x4d, 0x51, 0x58].pack('C*')
- received_pongs.size.should eq(1)
+ expect(received_pongs.size).to eq(1)
end
it "recognizes 256 bytes binary message in a single unmasked frame" do
data = Array.new(256) { rand(256) }.pack('c*')
parser << [0x82, 0x7E, 0x0100].pack('CCn') + data
- received_messages.first.should eq(data)
+ expect(received_messages.first).to eq(data)
end
it "recoginzes 64KiB binary message in a single unmasked frame" do
data = Array.new(65536) { rand(256) }.pack('c*')
parser << [0x82, 0x7F, 0x0000000000010000].pack('CCQ>') + data
- received_messages.first.should eq(data)
+ expect(received_messages.first).to eq(data)
end
end
end
|