Sha256: da2fa2ef87a71693d885aaae9e99342776f1c3855846bf752c38cba5b25434b4

Contents?: true

Size: 1.82 KB

Versions: 26

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

describe Riak::Util::Multipart::StreamParser do
  let(:klass) { Riak::Util::Multipart::StreamParser }
  let(:block) { mock }
  it "should detect the initial boundary" do
    text = "--boundary1\r\nContent-Type: text/plain\r\n\r\nfoo\r\n--boundary1--\r\n"
    parser = klass.new do |result|
      result[:headers]['content-type'].should include("text/plain")
      result[:body].should == "foo"
    end
    parser.accept text
  end

  it "should detect inner multipart bodies" do
    block.should_receive(:ping).once.and_return(true)
    parser = klass.new do |result|
      block.ping
      result.should have(1).item
      result.first[:headers]['content-type'].should include("text/plain")
      result.first[:body].should == "SCP sloooow...."
    end
    File.open("spec/fixtures/multipart-with-body.txt", "r") do |f|
      while chunk = f.read(16)
        parser.accept chunk
      end
    end
  end

  it "should yield successive complete chunks to the block" do
    block.should_receive(:ping).twice.and_return(true)
    parser = klass.new do |result|
      block.ping
      result[:headers]['content-type'].should include("application/json")
      lambda { Riak::JSON.parse(result[:body]) }.should_not raise_error
    end
    File.open("spec/fixtures/multipart-mapreduce.txt", "r") do |f|
      while chunk = f.read(16)
        parser.accept chunk
      end
    end
  end

  it "should yield successive complete bodies to the block, even when multiple bodies are accepted in a single chunk" do
    block.should_receive(:ping).twice.and_return(true)
    parser = klass.new do |result|
      block.ping
      result[:headers]['content-type'].should include("application/json")
      lambda { Riak::JSON.parse(result[:body]) }.should_not raise_error
    end
    parser.accept File.read("spec/fixtures/multipart-mapreduce.txt")
  end
end

Version data entries

26 entries across 16 versions & 2 rubygems

Version Path
riak-client-1.4.5 spec/riak/stream_parser_spec.rb
riak-client-1.4.4.1 spec/riak/stream_parser_spec.rb
riak-client-1.4.4 spec/riak/stream_parser_spec.rb
riak-client-1.4.3 spec/riak/stream_parser_spec.rb
riak-client-1.4.2 spec/riak/stream_parser_spec.rb
riak-client-1.4.1 spec/riak/stream_parser_spec.rb
riak-client-1.4.0 spec/riak/stream_parser_spec.rb
riak-client-1.2.0 spec/riak/stream_parser_spec.rb
riak-client-1.1.1 spec/riak/stream_parser_spec.rb
riak-client-1.1.0 spec/riak/stream_parser_spec.rb
riak-client-1.0.5 spec/riak/stream_parser_spec.rb
riak-client-1.0.3 pkg/riak-client-1.0.2/pkg/riak-client-1.0.1/spec/riak/stream_parser_spec.rb
riak-client-1.0.3 pkg/riak-client-1.0.2/spec/riak/stream_parser_spec.rb
riak-client-1.0.3 spec/riak/stream_parser_spec.rb
riak-client-1.0.3 pkg/riak-client-1.0.1/pkg/riak-client-1.0.0/spec/riak/stream_parser_spec.rb
riak-client-1.0.3 pkg/riak-client-1.0.0/spec/riak/stream_parser_spec.rb
riak-client-1.0.3 pkg/riak-client-1.0.1/spec/riak/stream_parser_spec.rb
riak-client-1.0.3 pkg/riak-client-1.0.2/pkg/riak-client-1.0.0/spec/riak/stream_parser_spec.rb
riak-client-1.0.3 pkg/riak-client-1.0.2/pkg/riak-client-1.0.1/pkg/riak-client-1.0.0/spec/riak/stream_parser_spec.rb
riak-client-1.0.2 pkg/riak-client-1.0.0/spec/riak/stream_parser_spec.rb