Sha256: 8504d6d11d9a4559751829356fa01dccfd92c5ef6fd4653186c60f580608601d

Contents?: true

Size: 1000 Bytes

Versions: 5

Compression:

Stored size: 1000 Bytes

Contents

require 'minitest_helper'

describe 'Straming' do

  let(:request) { Rack::Request.new Hash.new }
  let(:response) { Rack::Response.new }
  let(:render) { Rasti::Web::Render.new request, response }
  
  it 'Server sent events' do
    render.server_sent_events :test_channel

    response.status.must_equal 200
    response['Content-Type'].must_equal 'text/event-stream'
    response['Cache-Control'].must_equal 'no-cache'
    response['Connection'].must_equal 'keep-alive'
    response.body.must_be_instance_of Rasti::Web::Stream

    events = []
    thread = Thread.new do
      response.body.each { |e| events << e }
    end

    3.times do |i|
      data = {text: "Tick #{i}"}
      event = Rasti::Web::ServerSentEvent.new data, id: i, event: 'tick'
      Rasti::Web::Channel[:test_channel].publish event
    end

    while events.count < 3; sleep 0.0001 end
    response.body.close 

    events.must_equal 3.times.map { |i| "id: #{i}\nevent: tick\ndata: {\"text\":\"Tick #{i}\"}\n\n" }
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rasti-web-0.1.1 spec/streaming_spec.rb
rasti-web-0.1.0 spec/streaming_spec.rb
rasti-web-0.0.7 spec/streaming_spec.rb
rasti-web-0.0.6 spec/streaming_spec.rb
rasti-web-0.0.5 spec/streaming_spec.rb