Sha256: 4a75fb6c8d5d32efe430c9293336287e8b854622e7ba0aba8c5f3e786caf9aa5

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 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))
      expect(stream.read).to eq(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)
      
      expect(buffer).to eq(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 }

      expect(results).to 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 }

      expect(results).to eq(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))
      expect(stream.body).to eq(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)
      expect(stream.write(data)).to eq(data.length)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-http-server-0.2.3 spec/net/http/server/stream_spec.rb