Sha256: 26d5289d7c987e19c440f8d764ca2b4581861d71130481a6ed4a440d5774b2bb

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'
require 'net/http/server/stream'

require 'stringio'

describe Net::HTTP::Server::Stream do
  describe "#read" do
    let(:data) { "foo\0bar" }

    it "should read data from a socket" do
      stream = described_class.new(StringIO.new(data))
      stream.read.should == data
    end

    it "should read an amount of data from a socket, directly into a buffer" do
      length = 3
      buffer = ''

      stream = described_class.new(StringIO.new(data))
      stream.read(length,buffer)
      
      buffer.should == data[0,length]
    end
  end

  describe "#each" do
    it "should stop yielding data on 'nil'" do
      results = []

      stream = described_class.new(StringIO.new())
      stream.each { |chunk| results << chunk }

      results.should be_empty
    end

    it "should yield each chunk in the stream" do
      chunks = ['A' * 4096, 'B' * 4096]
      data = chunks.join('')
      results = []

      stream = described_class.new(StringIO.new(data))
      stream.each { |chunk| results << chunk }

      results.should == chunks
    end
  end

  describe "#body" do
    it "should append each chunk to a buffer" do
      chunks = ['A' * 4096, 'B' * 4096]
      data = chunks.join('')

      stream = described_class.new(StringIO.new(data))
      stream.body.should == data
    end
  end

  describe "#write" do
    it "should write to the socket and flush" do
      data = "foo\n\rbar"

      stream = described_class.new(StringIO.new)
      stream.write(data).should == data.length
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
net-http-server-0.2.2 spec/net/http/server/stream_spec.rb
net-http-server-0.2.1 spec/net/http/server/stream_spec.rb
net-http-server-0.2.0 spec/net/http/server/stream_spec.rb