Sha256: facfaf00201782e01696f9bf47e948c297a1be0c5bc1358a756970b148df74b8

Contents?: true

Size: 1.52 KB

Versions: 11

Compression:

Stored size: 1.52 KB

Contents

# encoding=utf-8

require "spec_helper"

shared_examples_for "draft-75 parser" do
  it "parses text frames" do
    @web_socket.should_receive(:receive).with("Hello")
    parse [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
  end
  
  it "parses multiple frames from the same packet" do
    @web_socket.should_receive(:receive).with("Hello").exactly(2)
    parse [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
  end
  
  it "parses text frames beginning 0x00-0x7F" do
    @web_socket.should_receive(:receive).with("Hello")
    parse [0x66, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
  end
  
  it "ignores frames with a length header" do
    @web_socket.should_not_receive(:receive)
    parse [0x80, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
  end
  
  it "parses text following an ignored block" do
    @web_socket.should_receive(:receive).with("Hello")
    parse [0x80, 0x02, 0x48, 0x65, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
  end
  
  it "parses multibyte text frames" do
    @web_socket.should_receive(:receive).with(encode "Apple = ")
    parse [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
  end
  
  it "parses frames received in several packets" do
    @web_socket.should_receive(:receive).with(encode "Apple = ")
    parse [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65]
    parse [0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
  end
  
  it "parses fragmented frames" do
    @web_socket.should_receive(:receive).with("Hello")
    parse [0x00, 0x48, 0x65, 0x6c]
    parse [0x6c, 0x6f, 0xff]
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
faye-websocket-0.4.6-java spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.6 spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.5-java spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.5 spec/faye/websocket/draft75_parser_examples.rb
_bushido-faye-websocket-0.4.4 spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.4-java spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.4 spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.3 spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.2 spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.1 spec/faye/websocket/draft75_parser_examples.rb
faye-websocket-0.4.0 spec/faye/websocket/draft75_parser_examples.rb