Sha256: 3257d7b824c94b9070be0bf99a12c809f7d791312d53f778c7cdf503e32ec994

Contents?: true

Size: 1.31 KB

Versions: 11

Compression:

Stored size: 1.31 KB

Contents

require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

describe "streaming plugin" do 
  it "adds stream method for streaming responses" do
    app(:streaming) do |r|
      stream do |out|
        %w'a b c'.each{|v| out << v; out.write(v) }
      end
    end

    s, h, b = req
    s.must_equal 200
    h.must_equal('Content-Type'=>'text/html')
    b.to_a.must_equal %w'a a b b c c'
  end

  it "should handle errors when streaming, and run callbacks" do
    a = []
    app(:streaming) do |r|
      stream(:callback=>proc{a << 'e'}) do |out|
        %w'a b'.each{|v| out << v}
        raise Roda::RodaError, 'foo'
        out << 'c'
      end
    end

    s, h, b = req
    s.must_equal 200
    h.must_equal('Content-Type'=>'text/html')
    b.callback{a << 'd'}
    proc{b.each{|v| a << v}}.must_raise(Roda::RodaError)
    a.must_equal %w'a b e d'
  end

  it "should handle :loop option to loop" do
    a = []
    app(:streaming) do |r|
      b = %w'a b c'
      stream(:loop=>true, :callback=>proc{a << 'e'}) do |out|
        out << b.shift
        raise Roda::RodaError, 'foo' if b.length == 1
      end
    end

    s, h, b = req
    s.must_equal 200
    h.must_equal('Content-Type'=>'text/html')
    b.callback{a << 'd'}
    proc{b.each{|v| a << v}}.must_raise(Roda::RodaError)
    a.must_equal %w'a b e d'
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
roda-2.20.0 spec/plugin/streaming_spec.rb
roda-2.19.0 spec/plugin/streaming_spec.rb
roda-2.18.0 spec/plugin/streaming_spec.rb
roda-2.17.0 spec/plugin/streaming_spec.rb
roda-2.16.0 spec/plugin/streaming_spec.rb
roda-2.15.0 spec/plugin/streaming_spec.rb
roda-2.14.0 spec/plugin/streaming_spec.rb
roda-2.13.0 spec/plugin/streaming_spec.rb
roda-2.12.0 spec/plugin/streaming_spec.rb
roda-2.11.0 spec/plugin/streaming_spec.rb
roda-2.10.0 spec/plugin/streaming_spec.rb