Sha256: 96913664777b1d96a00a69594ad0d49928bbd6542d7090a4a0699c42b395d32d

Contents?: true

Size: 932 Bytes

Versions: 4

Compression:

Stored size: 932 Bytes

Contents

require 'jellyfish/test'
require 'stringio'

describe Jellyfish do
  after do
    Muack.verify
  end

  app = Class.new do
    include Jellyfish
    controller_include Jellyfish::WebSocket
    get '/echo' do
      switch_protocol do |msg|
        ws_write(msg)
      end
      ws_write('ping')
      ws_start
    end
  end.new

  def create_env
    sock = StringIO.new
    mock(IO).select([sock]) do # or EOFError, not sure why?
      sock << WebSocket::Message.new('pong').to_data * 2
      [[sock], [], []]
    end
    [{'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/echo',
      'rack.hijack' => lambda{ sock }}, sock]
  end

  would 'ping pong' do
    env, sock = create_env
    app.call(env)
    sock.string.should.eq <<-HTTP.chomp
HTTP/1.1 101 Switching Protocols\r
Upgrade: websocket\r
Connection: Upgrade\r
Sec-WebSocket-Accept: Kfh9QIsMVZcl6xEPYxPHzW8SZ8w=\r
\r
\x81\u0004ping\x81\u0004pong\x81\u0004pong
    HTTP
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jellyfish-1.1.1 test/test_websocket.rb
jellyfish-1.1.0 test/test_websocket.rb
jellyfish-1.0.2 test/test_websocket.rb
jellyfish-1.0.1 test/test_websocket.rb