Sha256: 2be14f505af22f5b7717153c84a0dfa8eec60267c3de739cbe10db0ad6cbee3e

Contents?: true

Size: 1.3 KB

Versions: 20

Compression:

Stored size: 1.3 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}
      end
    end

    s, h, b = req
    s.should == 200
    h.should == {'Content-Type'=>'text/html'}
    b.to_a.should == %w'a b 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.should == 200
    h.should == {'Content-Type'=>'text/html'}
    b.callback{a << 'd'}
    proc{b.each{|v| a << v}}.should raise_error(Roda::RodaError)
    a.should == %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.should == 200
    h.should == {'Content-Type'=>'text/html'}
    b.callback{a << 'd'}
    proc{b.each{|v| a << v}}.should raise_error(Roda::RodaError)
    a.should == %w'a b e d'
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
roda-2.2.0 spec/plugin/streaming_spec.rb
roda-2.1.0 spec/plugin/streaming_spec.rb
roda-2.0.0 spec/plugin/streaming_spec.rb
roda-1.3.0 spec/plugin/streaming_spec.rb
roda-1.2.0 spec/plugin/streaming_spec.rb
roda-1.1.0 spec/plugin/streaming_spec.rb
roda-cj-1.0.5 spec/plugin/streaming_spec.rb
roda-cj-1.0.4 spec/plugin/streaming_spec.rb
roda-cj-1.0.3 spec/plugin/streaming_spec.rb
roda-cj-1.0.2 spec/plugin/streaming_spec.rb
roda-cj-1.0.1 spec/plugin/streaming_spec.rb
roda-cj-1.0.0 spec/plugin/streaming_spec.rb
roda-1.0.0 spec/plugin/streaming_spec.rb
roda-cj-0.9.6 spec/plugin/streaming_spec.rb
roda-cj-0.9.5 spec/plugin/streaming_spec.rb
roda-cj-0.9.4 spec/plugin/streaming_spec.rb
roda-cj-0.9.3 spec/plugin/streaming_spec.rb
roda-cj-0.9.2 spec/plugin/streaming_spec.rb
roda-cj-0.9.1 spec/plugin/streaming_spec.rb
roda-0.9.0 spec/plugin/streaming_spec.rb