[DRE-commits] [ruby-websocket-parser] 02/03: Convert specs to RSpec 3.3.1 syntax with Transpec

Hleb Valoshka tsfgnu-guest at moszumanska.debian.org
Tue Jul 7 16:00:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

tsfgnu-guest pushed a commit to branch patch-queue/master
in repository ruby-websocket-parser.

commit d02bbc498e636cd18882363cb53b792840c7cdc0
Author: Hleb Valoshka <375gnu at gmail.com>
Date:   Tue Jul 7 18:38:51 2015 +0300

    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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-websocket-parser.git



More information about the Pkg-ruby-extras-commits mailing list